Hello,
I need an example on how to use CreateProcessasuser or CreateProcesswithLogonW. I would like to hardcode a user/password into a vb.net program (trusted and secure environment) so that I can have trusted people run cpl files (control Panels) as the local administrator, without knowing the password.
For Example, I would like my program to execute the system control panel as the local administrator automatically. Here is the code I have to start the system control panel so far:
PrivateSub cmdSystem_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles cmdSystem.Click
Winpath = System.Environment. _
GetEnvironmentVariable("SystemRoot")
Fname = Winpath & "\system32\sysdm.cpl"
If System.IO.File.Exists(Fname) Then
System.Diagnostics.Process.Start(Fname)
Else
MsgBox("Control Panel not found!", 16, "Error")
EndIf
EndSub
I found this code, however, Im not sure how to make it work with a buttons click event.
Declare Function CreateProcessAsUser Lib "advapi32.dll" Alias "CreateProcessAsUserA" (ByVal hToken As Integer, ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByVal lpProcessAttributes As SECURITY_ATTRIBUTES, ByVal lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Integer, ByVal dwCreationFlags As Integer, ByVal lpEnvironment As String, ByVal lpCurrentDirectory As String, ByVal lpStartupInfo As STARTUPINFO, ByVal lpProcessInformation As PROCESS_INFORMATION) As Integer
Structure PROCESS_INFORMATION
Dim hProcess As Integer
Dim hThread As Integer
Dim dwProcessId As Integer
Dim dwThreadId As Integer
End Structure
Structure STARTUPINFO
Dim cb As Integer
Dim lpReserved As String
Dim lpDesktop As String
Dim lpTitle As String
Dim dwX As Integer
Dim dwY As Integer
Dim dwXSize As Integer
Dim dwYSize As Integer
Dim dwXCountChars As Integer
Dim dwYCountChars As Integer
Dim dwFillAttribute As Integer
Dim dwFlags As Integer
Dim wShowWindow As Short
Dim cbReserved2 As Short
Dim lpReserved2 As Integer
Dim hStdInput As Integer
Dim hStdOutput As Integer
Dim hStdError As Integer
End Structure
Structure SECURITY_ATTRIBUTES
Dim nLength As Integer
Dim lpSecurityDescriptor As Integer
Dim bInheritHandle As Integer
End Structure
Any help is much appreciated! Thanks a lot!
Pat
P.S.
Im relatively new to vb.net so be gentle
I need an example on how to use CreateProcessasuser or CreateProcesswithLogonW. I would like to hardcode a user/password into a vb.net program (trusted and secure environment) so that I can have trusted people run cpl files (control Panels) as the local administrator, without knowing the password.
For Example, I would like my program to execute the system control panel as the local administrator automatically. Here is the code I have to start the system control panel so far:
PrivateSub cmdSystem_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles cmdSystem.Click
Winpath = System.Environment. _
GetEnvironmentVariable("SystemRoot")
Fname = Winpath & "\system32\sysdm.cpl"
If System.IO.File.Exists(Fname) Then
System.Diagnostics.Process.Start(Fname)
Else
MsgBox("Control Panel not found!", 16, "Error")
EndIf
EndSub
I found this code, however, Im not sure how to make it work with a buttons click event.
Declare Function CreateProcessAsUser Lib "advapi32.dll" Alias "CreateProcessAsUserA" (ByVal hToken As Integer, ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByVal lpProcessAttributes As SECURITY_ATTRIBUTES, ByVal lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Integer, ByVal dwCreationFlags As Integer, ByVal lpEnvironment As String, ByVal lpCurrentDirectory As String, ByVal lpStartupInfo As STARTUPINFO, ByVal lpProcessInformation As PROCESS_INFORMATION) As Integer
Structure PROCESS_INFORMATION
Dim hProcess As Integer
Dim hThread As Integer
Dim dwProcessId As Integer
Dim dwThreadId As Integer
End Structure
Structure STARTUPINFO
Dim cb As Integer
Dim lpReserved As String
Dim lpDesktop As String
Dim lpTitle As String
Dim dwX As Integer
Dim dwY As Integer
Dim dwXSize As Integer
Dim dwYSize As Integer
Dim dwXCountChars As Integer
Dim dwYCountChars As Integer
Dim dwFillAttribute As Integer
Dim dwFlags As Integer
Dim wShowWindow As Short
Dim cbReserved2 As Short
Dim lpReserved2 As Integer
Dim hStdInput As Integer
Dim hStdOutput As Integer
Dim hStdError As Integer
End Structure
Structure SECURITY_ATTRIBUTES
Dim nLength As Integer
Dim lpSecurityDescriptor As Integer
Dim bInheritHandle As Integer
End Structure
Any help is much appreciated! Thanks a lot!
Pat
P.S.
Im relatively new to vb.net so be gentle