views:

156

answers:

2

Hello,

I am trying to find out how I can programmatically create a logon account in Windows Vista with UAC enabled?

I have an OCX that creates a user account and it has worked for years on NT and XP, but now our application fails with Access Denied when creating the account on Vista. If our customers turn off UAC then setup that app it works fine. However, it is not acceptable to have our users turn off UAC AND REBOOT before finsihing configuring our app.

If anone has any knowledge of how we can create the accounts in Vista it would be a great help!!!

Thanks in advance.

+1  A: 

If you run your application with administrator privileges in Vista, then does it work?

You can also create a COM object with elevated privileges using this code:

HRESULT __stdcall CreateElevatedComObject(HWND hwnd, REFCLSID rclsid, REFIID riid, __out IUnknown ** ppv)
{
    OSVERSIONINFO ver={sizeof(ver)};
    if (GetVersionEx(&ver) && ver.dwMajorVersion > 5)
    {
     BIND_OPTS3 bo;
     WCHAR wszCLSID[50];
     WCHAR wszMonikerName[300];

     if (StringFromGUID2(rclsid, wszCLSID, ELEMENTS(wszCLSID)))
     {
      HRESULT hr = StringCchPrintf(wszMonikerName,
       ELEMENTS(wszMonikerName),
       L"Elevation:Administrator!new:%s",
       wszCLSID);
      if (FAILED(hr))
       return hr;
      memset(&bo, 0, sizeof(bo));
      bo.cbStruct = sizeof(bo);
      bo.hwnd = hwnd;
      bo.dwClassContext  = CLSCTX_LOCAL_SERVER;
      return CoGetObject(wszMonikerName, &bo, riid, (void **)ppv);
     }
     return E_FAIL;
    }
    else
     return ::CoCreateInstance(rclsid,NULL,CLSCTX_ALL,riid,(void**)ppv);
}

Running under UAC, it will present an elevation dialog. The object will run out of process in dllhost (I think) but with full admin privileges.

Also look at the step by step guide for UAC in Vista.

1800 INFORMATION
Thank for the reply. No it does not work with admin privileges. I could put this code in my current OCX, right? Will this cause a diaog to come up. Keep in mind this is an OCX running from a web page.Thanks for the help.
Tony
No, you need to run this in place of the usual code you are using to create the COM object. If you are running inside IE, then this provides additional security boundaries because it will intentionally drop privileges when it runs.
1800 INFORMATION
If you right click IE and choose "Run as administrator" this will cause IE to run as a full unfiltered administrator - if you just run it normally, then Vista will cause IE (or any process really) to run without actual admin privileges, even if they are an admin on the machine
1800 INFORMATION
+1  A: 

Here's another article about dealing with UAC when deploying. Having been through some vista deployment issues already, all I can say to you is good luck. :)

JP Alioto