Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than advapi32, prefix the name with the module name and a period.
CreateProcessWithLogonW (advapi32)
.
' This Code Does not work in VB.Net
C# Signature:
[DllImport("advapi32.dll")]
static extern TODO CreateProcessWithLogonW(TODO);
VB Signature:
"Try this for VB"
Public Shared Function CreateProcessWithLogonW( _
"""<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)>""" ByVal lpUsername As String, _
"""<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)>""" ByVal lpDomain As String, _
"""<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)>""" ByVal lpPassword As String, _
ByVal dwLogonFlags As Integer, _
"""ByVal lpApplicationName As Integer""", _
"""<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)>""" ByVal lpCommandLine As String, _
ByVal dwCreationFlags As Integer, _
"""ByVal lpEnvironment As Integer""", _
"""<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)>""" ByVal lpCurrentDirectory As String, _
ByRef lpStartupInfo As STARTUPINFO, _
ByRef lpProcessInformation As PROCESS_INFORMATION _
) As Integer
End Function
Public Shared Function CreateProcessWithLogonW( _
ByVal lpUsername As String, _
ByVal lpDomain As String, _
ByVal lpPassword As String, _
ByVal dwLogonFlags As Integer, _
ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
ByVal dwCreationFlags As Integer, _
ByVal lpEnvironment As IntPtr, _
ByVal lpCurrentDirectory As String, _
ByRef lpStartupInfo As STARTUPINFO, _
ByRef lpProcessInformation As PROCESS_INFORMATION _
) As Integer
End Function
""" Before using this, you will need to change the STARTUPINFO and PROCESS_ INFORMATION STRUCTURE
Private Declare Function CloseHandle Lib "kernel32.dll" _
(ByVal hObject As Long) As Long
"""Change to Private/Public Shared Function OpenAppAsUser( _
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByValUserName As String, _
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByVal Password As String, _
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByValDomainName As String, _
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByValApplicationName As String, <System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByValCommandLine As String, _
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)> ByValCurrentDirectory As String) As Long
Dim si As STARTUPINFO
Dim pi As PROCESS_INFORMATION
Dim Result As Long
si.cb = Len(si)
Result = CreateProcessWithLogonW(UserName, DomainName, Password, LOGON_WITH_PROFILE, 0%, CommandLine, CREATE_DEFAULT_ERROR_MODE, 0%, CurrentDirectory, si, pi)
' CreateProcessWithLogonW() does not
If Result <> 0 Then
CloseHandle(pi.hThread)
CloseHandle(pi.hProcess)
W2KRunAsUser = 0
Else
W2KRunAsUser = Err.LastDllError
MsgBox("CreateProcessWithLogonW() failed with error " & Err.LastDllError, vbExclamation)
End If
End Function
Public Shared Function OpenAppAsUser(ByVal username As String, ByVal domainname As String, ByVal password As String) As Boolean
'The Windows NT user token.
"Dim LAppname as Integer"
Dim lpAppName As String
Dim appExe As SR.[Assembly]
Dim pi As PROCESS_INFORMATION
Dim si As STARTUPINFO
Dim fResult As Boolean
Dim dwCreationFlags As Integer = Nothing
Dim lpCommandLine As String = Nothing
Dim lpEnvironment As IntPtr
Dim lpCurrentDirectory As String = Nothing
Dim ret As Integer
' call the Win32 API to open the application under the userID passed in
' Implicit Integer to Boolean conversion. CreateProcessWithLogonW returns 0 (False) when it fails.
fResult = CreateProcessWithLogonW(username, domainname, password, LOGON_WITH_PROFILE, lpAppName, lpCommandLine, dwCreationFlags, lpEnvironment, lpCurrentDirectory, si, pi)
' if the logon fails then we need to generate an error
If Not fResult Then
' get the last error from Windows
ret = Marshal.GetLastWin32Error
' if the userid, password, or domain is bad we can display a friendly message
If ret = 1326 Then
MessageBox.Show("Invalid UserID or Password entered. Please try again.", "Logon Error")
Return False
Else
' the error code is unexpected so throw an exception to be logged.
Dim retMsg = GetErrorMessage(ret)
Throw New MAE.BaseApplicationException("Error occurred: " + ret.ToString() + " - " + retMsg)
Return False
End If
End If
3/16/2007 7:31:57 AM - anfortas.geo@yahoo.com-216.204.61.86
The SetLastError API
1/26/2016 3:27:33 AM - -124.148.167.58
Click to read this page
4/6/2008 7:23:14 AM - anonymous
Passed in place of STARTUPINFO to extend CreateProcess
7/8/2019 11:50:55 AM - dahall-72.24.140.51
The '''PROCESS_INFORMATION''' structure is filled in by either the CreateProcess, CreateProcessAsUser, CreateProcessWithLogonW, or CreateProcessWithTokenW function with information about the newly created process and its primary thread.
8/9/2010 12:13:12 PM - -97.79.160.250
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).