CreateProcessWithTokenW - Usage Example in C #

I am trying to use the win32 API function CreateProcessWithTokenW() to start a new process using a token. The problem is that I am completely new to the win32 API, and I have no idea how to use this function correctly, but which structures, etc. Can someone provide me an example of how to use a function in C # correctly?

+7
source share
1 answer

This is unmanaged code, so you need to use P / Invoke (Platform Invoke), here is the function signature for CreateProcessWithTokenW() :

 [DllImport("advapi32", SetLastError = true, CharSet = CharSet.Unicode)] public static extern bool CreateProcessWithTokenW( IntPtr hToken, LogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation); 

You can use an enumeration like this to pass the LogonFlags parameter (to keep the .net feeling :)):

 public enum LogonFlags { WithProfile = 1, NetCredentialsOnly } 

Here is the listing for CreationFlags after the documentation available here :

 public enum CreationFlags { DefaultErrorMode = 0x04000000, NewConsole = 0x00000010, NewProcessGroup = 0x00000200, SeparateWOWVDM = 0x00000800, Suspended = 0x00000004, UnicodeEnvironment = 0x00000400, ExtendedStartupInfoPresent = 0x00080000 } 
+4
source

All Articles