ikantspelwurdz
Well-known member
- Joined
- Dec 8, 2009
- Messages
- 49
- Programming Experience
- 1-3
What I want is to create an app that will run, 99% of the time, without elevated privileges. However, a few functions do require admin privileges. I want the user to be prompted to grant admin privileges when and only when these functions are invoked.
My design has been to create two executables. The first is normal. It looks like this:
The second is called "protectedFunctions.exe." It has requestedExecutionLevel level="requireAdministrator" embedded in the manifest, and it contains the functions that need admin-level privileges. It looks like this:
This works, but I was wondering if there was a better way to do it. Can this be done without making a separate executable?
My design has been to create two executables. The first is normal. It looks like this:
VB.NET:
Sub Main()
Console.WriteLine("Would you like to 1) hear a joke or 2) write to the registry?")
Dim i As Integer = Console.ReadLine()
Select Case i
Case 1
Console.WriteLine("Two bytes walk into a bar. The first byte turns to the second and says " & ControlChars.Quote & "I think I may have a parity error." & ControlChars.Quote & _
"The second byte turns to the first and says " & ControlChars.Quote & "yeah, you look a bit off." & ControlChars.Quote)
Case 2
Dim cmd As String = "protectedFunctions.exe"
Dim cmdArgs As String = "REG HKLM SOFTWARE\FOO BAR ."
Dim pPriveleged As System.Diagnostics.Process
pPriveleged = System.Diagnostics.Process.Start(cmd, cmdArgs)
pPriveleged.WaitForExit()
End Select
End Sub
The second is called "protectedFunctions.exe." It has requestedExecutionLevel level="requireAdministrator" embedded in the manifest, and it contains the functions that need admin-level privileges. It looks like this:
VB.NET:
Sub Main()
Select Case My.Application.CommandLineArgs(0).ToUpper
Case "REG"
REG(My.Application.CommandLineArgs(1), My.Application.CommandLineArgs(2))
End Select
End Sub
Public Sub REG(ByVal regHive As String, ByVal regKey As String)
Select Case regHive.ToUpper
Case "HKLM"
My.Computer.Registry.LocalMachine.CreateSubKey(regKey)
End Select
End Sub
This works, but I was wondering if there was a better way to do it. Can this be done without making a separate executable?