Solved

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

Posted on 2007-11-15
5
637 Views
Last Modified: 2010-04-21
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.
0
Comment
Question by:rmcmanamy
  • 3
  • 2
5 Comments
 
LVL 34

Expert Comment

by:sramesh2k
ID: 20306957
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
0
 

Author Comment

by:rmcmanamy
ID: 20307502
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.
0
 
LVL 34

Expert Comment

by:sramesh2k
ID: 20308072
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.
0
 
LVL 34

Accepted Solution

by:
sramesh2k earned 500 total points
ID: 20308074
0
 

Author Closing Comment

by:rmcmanamy
ID: 31427351
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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now