Using CreateProcessAsUser

waughp

Member
Joined
Feb 18, 2005
Messages
15
Programming Experience
Beginner
Hello,

I need an example on how to use CreateProcessAsUser. I would like to hardcode a user/password into a vb.net program 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:

Private Sub cmdSystem_Click(ByVal sender As Object, 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")

End If

End Sub


I found this code, however, I'm not sure how to make it work with a button's 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
 
Last edited:
Top Bottom