Link to home
Start Free TrialLog in
Avatar of rmcmanamy
rmcmanamy

asked on

Is it possible to elevate a program once it is already running in VB6?

Because of a 3rd party software we incorporate we need to write the Registration Code to unlock it to the HKEY_LOCAL_MACHINE portion of the registry so it's available for all users.  And this needs to be done when the user is running after they purchase it as opposed to during installation.

Is there any way to elevate a program once it is running or to write to the HKEY_LOCAL_MACHINE in VB6 on Vista?  I don't care if the user gets the UAC prompt to allow it but I really don't want to have to have a completely separate registration program that runs in elevated mode to do it.  It's so much cleaner if it's kept inside of our main program.
Avatar of sramesh2k
sramesh2k
Flag of India image

Calling the ShellExecute function passing "runas" (instead of "open") will do the trick. Also, to add a "shield" icon to the command button, see this post:

http://groups.google.com/group/microsoft.public.de.vb/msg/1fc55a994d516405
Avatar of rmcmanamy
rmcmanamy

ASKER

Thanks but I was hoping there was some way to elevate it nce it was running already.  Basially we ae trying to store our registration information and I didn't want to have to shell out to another program to do it.  I would have thought Microsoft wouldhave been smart enough to think of this situation and give a way to ask for the securiy credintials or something when you are trying to write to the HKEY_LOCAL_Machine and have it prompt the user.
Here is a sample written for VB.NET but it should give you an idea on how to accomplish this. When the application first starts, let it check the registry to know if there is a registration code already present. If it's missing (probably a first run of the app), then restart the app elevated, using Shellexecute.
ASKER CERTIFIED SOLUTION
Avatar of sramesh2k
sramesh2k
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks that should work I guess.  It still seams strange that Microsoft didn't think far enough ahead to let one just elevate the RegOpenKeyEx but I suppose there were security concerns with it.