|
Postup:
Private Const LOGON_WITH_PROFILE
= &H1&
Private Const LOGON_NETCREDENTIALS_ONLY = &H2&
Private Const CREATE_DEFAULT_ERROR_MODE = &H4000000
Private Const CREATE_NEW_CONSOLE = &H10&
Private Const CREATE_NEW_PROCESS_GROUP = &H200&
Private Const CREATE_SEPARATE_WOW_VDM = &H800&
Private Const CREATE_SUSPENDED = &H4&
Private Const CREATE_UNICODE_ENVIRONMENT = &H400&
Private Const ABOVE_NORMAL_PRIORITY_CLASS = &H8000&
Private Const BELOW_NORMAL_PRIORITY_CLASS = &H4000&
Private Const HIGH_PRIORITY_CLASS = &H80&
Private Const IDLE_PRIORITY_CLASS = &H40&
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const REALTIME_PRIORITY_CLASS = &H100&
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Declare Function CreateProcessWithLogon Lib "Advapi32" _
Alias "CreateProcessWithLogonW" _
(ByVal lpUsername As Long, _
ByVal lpDomain As Long, _
ByVal lpPassword As Long, _
ByVal dwLogonFlags As Long, _
ByVal lpApplicationName As Long, _
ByVal lpCommandLine As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, _
lpProcessInfo As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Sub Form_Load()
Dim lpUsername As String, lpDomain As String
Dim lpPassword As String, lpApplicationName As
String
Dim lpCommandLine As String, lpCurrentDirectory As String
Dim StartInfo As STARTUPINFO, ProcessInfo As PROCESS_INFORMATION
lpUsername = "JINE_UZIVATELSKE_JMENO"
lpDomain = ""
lpPassword = "JINE_UZIVATELSKE_HESLO"
lpApplicationName = "C:\WINNT\NOTEPAD.EXE"
lpCommandLine = vbNullString
lpCurrentDirectory = vbNullString
StartInfo.cb = LenB(StartInfo)
StartInfo.dwFlags = 0&
CreateProcessWithLogon StrPtr(lpUsername), StrPtr(lpDomain),_
StrPtr(lpPassword),
LOGON_WITH_PROFILE, _
StrPtr(lpApplicationName), StrPtr(lpCommandLine),_
CREATE_DEFAULT_ERROR_MODE Or CREATE_NEW_CONSOLE
_
Or CREATE_NEW_PROCESS_GROUP, _
ByVal 0&, StrPtr(lpCurrentDirectory),
StartInfo, _
ProcessInfo
'Zavřeme ukazatel na hlavní thread, protože už ho nepotřebujeme
CloseHandle ProcessInfo.hThread
'Zavřeme ukazatel na proces, protože už ho nepotřebujeme
CloseHandle ProcessInfo.hProcess
'POZN: Zavřením ukazatelů na hlavní thread a proces ovšem
spuštěný proces nekončí
Unload Me
End Sub |