|
-
Mar 25th, 2007, 01:23 PM
#1
Thread Starter
New Member
[RESOLVED] Elevate Code in Vista using VB6
I was unable to find any code on how to elevate to run as an administrator portions of my VB6 code under Vista. So, I tried it on my own, and I am getting really close, but not quite there.
Note: I could simply run a separate EXE using ShellExecute with the "Runas" verb, but I would like to avoid the extra warning and therefore, I am trying to use the COM route.
To summarize, this is what I have done so far:
- Created a new VB6 ActiveX EXE project.
- Added a couple of methods
- Compiled.
- Added the needed keys to the registry, namely:
- Localized String
- Elevation\Enabled = 1 - Created a new VB6 Project as a normal EXE
- Declared the object, and
- Used the CreateObject Function so that I can use the Moniker:
Code:
Dim MyObj As My_Vista.My_Vista_Cmds
Set MyObj = CreateObject("Elevation:Administrator!new:My_Vista.My_Vista_Cmds")
MyObj.Test_Elevate "This Elevation"
Set MyObj = Nothing
Running the program, this is what I get:
Running as an Administrator- I get the request to elevate
- Click "Allow"
- Object is created
- Methods are available and can be called.
Running as a Standard Vista User
- I get the request to elevate
- Enter the password of the Administrator account
- The COM object appears as a process in the Task Manager running under the Admin's account
- The "Initialize" code of the COM runs correctly
- In the calling program, "CreateObject" fails (70 - Permission denied)
Since the changes I need to make are minor (I am changing the name of a printer), I can run what I need under the "Initialize" sub and then simply quit: it works in that the code is indeed running under the Administrator account, but I would rather use the proper methods/properties to return the results to the user (ie it passed or failed).
Any ideas? Thx!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|