How can I automatically elevate a COM interface used for automation?
Posted
by Jim Flood
on Stack Overflow
See other posts from Stack Overflow
or by Jim Flood
Published on 2010-03-13T19:44:34Z
Indexed on
2010/03/13
19:55 UTC
Read the original article
Hit count: 293
I have a Windows service built with ATL to expose a LocalServer32 COM interface for a set of admin commands used for configuring the service, and these can be used from VBScript for example:
Set myObj = WScript.CreateObject("MySvc.Administrator")
myObj.DoSomething()
I want DoSomething to run elevated, and I would like the UAC prompt to come up automatically when this is called by the VBScript. Is this possible?
I know I can run the script in an elevated command shell, and that I can use
objShell.ShellExecute WScript.FullName, Chr(34) & WScript.ScriptFullName & Chr(34), vbNullString, "runas"
for example, to run the VBScript itself elevated, and either of those work fine -- the COM method finds itself elevated.
However, AFAIK getting an elevated Explorer window on the desktop is convoluted (it's not as simple as right-clicking Start/Accessories/Windows Explorer/Run as Administrator, which doesn't actually elevate.) I want a user in the local admin group to be able to drag-and-drop files and folders onto the script, and then have the script call the admin COM interface with those pathnames as arguments. (And I am hoping for something simpler than monkeying around with the args and using ShellExecute "runas".)
I've tried setting UAC Execution Level to requireAdministrator in the service EXE's manifest, and setting Elevated/Enabled = 1 and LocalizedString in the registry for the MySvc.Administrator class, and these don't do the trick.
© Stack Overflow or respective owner