Sure
Imports System.Runtime. InteropServices
Public Class ProcInfo
#Region "Structs"
<StructLayout(L ayoutKind.Seque ntial)> _
Public Structure PROCESS_INFORMA TION
Dim hProcess As System.IntPtr
Dim hThread As System.IntPtr
Dim dwProcessId As Integer
Dim dwThreadId As Integer
End Structure
<StructLayout(L ayoutKind.Seque ntial)> _
Public Structure STARTUPINFO
Dim cb As Integer
Dim lpReserved As System.IntPtr
Dim lpDesktop As System.IntPtr
Dim lpTitle As System.IntPtr
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
' you had this as a byte, but it is LPBYTE or byte*
' so should be an IntPtr
Dim lpReserved2 As System.IntPtr
Dim hStdInput As System.IntPtr
Dim hStdOutput As System.IntPtr
Dim hStdError As System.IntPtr
End Structure
#End Region
#Region "APIINFO"
Private Const LOGON_NETCREDEN TIALS_ONLY As Integer = &H2
Private Const NORMAL_PRIORITY _CLASS As Integer = &H20
Private Const CREATE_DEFAULT_ ERROR_MODE As Integer = &H4000000
Private Const CREATE_NEW_CONS OLE As Integer = &H10
Private Const CREATE_NEW_PROC ESS_GROUP As Integer = &H200
Private Const LOGON_WITH_PROF ILE As Integer = &H1
Private Declare Unicode Function CreateProcessWi thLogon Lib "Advapi32"
Alias "CreateProcessW ithLogonW" _
(ByVal lpUsername As String, _
ByVal lpDomain As String, _
ByVal lpPassword As String, _
ByVal dwLogonFlags As Integer, _
ByVal lpApplicationNa me As String, _
ByVal lpCommandLine As String, _
ByVal dwCreationFlags As Integer, _
ByVal lpEnvironment As System.IntPtr, _
ByVal lpCurrentDirect ory As System.IntPtr, _
ByRef lpStartupInfo As STARTUPINFO, _
ByRef lpProcessInfo As PROCESS_INFORMA TION) As Integer
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As
System.IntPtr) As Integer
#End Region
Public Function StartProcess(By Val filename As String, ByVal parameter
As String, ByVal username As String, ByVal password As String, ByVal domain
As String) As Boolean
Dim szApp As String = filename
Dim szCmdLine As String = parameter
Dim szUser As String = username
Dim szPass As String = password
Dim szDomain As String = domain
Dim siStartup As STARTUPINFO
Dim piProcess As PROCESS_INFORMA TION
siStartup.cb = Marshal.SizeOf( siStartup)
siStartup.dwFla gs = 0
Dim ret As Integer = CreateProcessWi thLogon(szUser, szDomain,
szPass, LOGON_WITH_PROF ILE, szApp, szCmdLine, _
NORMAL_PRIORITY _CLASS Or CREATE_DEFAULT_ ERROR_MODE Or
CREATE_NEW_CONS OLE Or CREATE_NEW_PROC ESS_GROUP, _
IntPtr.Zero, IntPtr.Zero, siStartup, piProcess)
If ret = 0 Then
MessageBox.Show (New
System.Componen tModel.Win32Exc eption(Marshal. GetLastWin32Err or()).Message)
End If
CloseHandle(piP rocess.hProcess )
CloseHandle(piP rocess.hThread)
End Function
End Class
"Tamas Nyilanszky" <sn************ ****@gmail.com> wrote in message
news:OL******** ******@TK2MSFTN GP12.phx.gbl...
would you mind sharing that code?
Fredrik Melin wrote: Found some code on the net to do this.
"Fredrik Melin" <me*@n.o.spam.d acsa.net.remove .as.needed> wrote in
message news:u0******** *****@TK2MSFTNG P10.phx.gbl... How can I start a process as another user?
I want my starter app to install framework 2.0 if its not installed,
admin rights is needed for it.
So can I start it as the domain/administrator somehow?
Regards
Fredrik