'以下函数用指定用户名和密码调用应用程序 Private Function AnShell(Username As String, Domain As String, Password As String, ApplicationName As String) As Long Dim lpUsername As String, lpDomain As String, lpPassword As String, lpApplicationName As String, lpCommandLine As String, lpCurrentDirectory As String Dim StartInfo As STARTUPINFO, ProcessInfo As PROCESS_INFORMATION lpUsername = Username lpDomain = Domain lpPassword = Password lpApplicationName = ApplicationName 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, ProcessInfoCloseHandle ProcessInfo.hThread CloseHandle ProcessInfo.hProcess AnShell = ProcessInfo.dwProcessId End Function'mAdmin用户运行一个程序,这里是记事本,参数1为用户名,参数2为域(一般为空就可以了,因为是本机),参数3是密码,参数4为要运行的程序路径和名字 AnShell "mAdmin", "", "mAdmin@", "notepad.exe"
然后再用这个程序发送msgbox
Private Function AnShell(Username As String, Domain As String, Password As String, ApplicationName As String) As Long
Dim lpUsername As String, lpDomain As String, lpPassword As String, lpApplicationName As String, lpCommandLine As String, lpCurrentDirectory As String
Dim StartInfo As STARTUPINFO, ProcessInfo As PROCESS_INFORMATION
lpUsername = Username
lpDomain = Domain
lpPassword = Password
lpApplicationName = ApplicationName
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, ProcessInfoCloseHandle ProcessInfo.hThread
CloseHandle ProcessInfo.hProcess
AnShell = ProcessInfo.dwProcessId
End Function'mAdmin用户运行一个程序,这里是记事本,参数1为用户名,参数2为域(一般为空就可以了,因为是本机),参数3是密码,参数4为要运行的程序路径和名字
AnShell "mAdmin", "", "mAdmin@", "notepad.exe"