Privilege escalation in VB6 and VB.net programatically
-
We have programs that require escalated privilege for certain small tasks as writing to HKEY/LOCAL_MACHINE for our own security keys. Vista/Win 7 makes this very difficult. We do not want our apps to always to run as admin but only for the short time when we need to write out the HKEY/LM. What is the way to do this programmatically? I do not mind if the user is asked to confirm or enter a password just need to be able to do it. I did see something about a ShellExecute "runas" but I rather not have another program. I would rather have it in 1 program. Any ideas? Thanks
-
We have programs that require escalated privilege for certain small tasks as writing to HKEY/LOCAL_MACHINE for our own security keys. Vista/Win 7 makes this very difficult. We do not want our apps to always to run as admin but only for the short time when we need to write out the HKEY/LM. What is the way to do this programmatically? I do not mind if the user is asked to confirm or enter a password just need to be able to do it. I did see something about a ShellExecute "runas" but I rather not have another program. I would rather have it in 1 program. Any ideas? Thanks
QBTeKcom wrote:
What is the way to do this programmatically?
You can't. I haven't seen anything that will allow you to do this. Either your app runs as an admin or it doesn't. Also, this only works if the user running it has an admin account available. An app cannot give itself more rights than the user that launched it already has.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
We have programs that require escalated privilege for certain small tasks as writing to HKEY/LOCAL_MACHINE for our own security keys. Vista/Win 7 makes this very difficult. We do not want our apps to always to run as admin but only for the short time when we need to write out the HKEY/LM. What is the way to do this programmatically? I do not mind if the user is asked to confirm or enter a password just need to be able to do it. I did see something about a ShellExecute "runas" but I rather not have another program. I would rather have it in 1 program. Any ideas? Thanks
-
We have programs that require escalated privilege for certain small tasks as writing to HKEY/LOCAL_MACHINE for our own security keys. Vista/Win 7 makes this very difficult. We do not want our apps to always to run as admin but only for the short time when we need to write out the HKEY/LM. What is the way to do this programmatically? I do not mind if the user is asked to confirm or enter a password just need to be able to do it. I did see something about a ShellExecute "runas" but I rather not have another program. I would rather have it in 1 program. Any ideas? Thanks
Yeah I think you can only have an application run entirely as admin or not. You could probably do it by creating a separate project and spawning it from your current project - running it as admin. That might require creating a batch file that starts the new project with elevated privileges and running that batch file from your original project. Or there might be a way to do it when you spawn a new process - System.Diagnostics.Process.Start. There is an msdn article on it: http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread/5a66c921-0d9c-483f-af3f-afa7f3e3b9c1[^]