Solved

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

Posted on 2007-11-15
5
638 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
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…

920 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