private static uint CreateHoneytokenProcess(string appPath, string domain, string user, string password, LogonFlags lf, CreationFlags cf) { StartupInfo si = new StartupInfo(); si.cb = Marshal.SizeOf(typeof(StartupInfo)); ProcessInfo pi = new ProcessInfo(); pi.dwProcessId = 0; if (CreateProcessWithLogonW(user, domain, password, lf, appPath, null, cf, IntPtr.Zero, null, ref si, out pi)) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } else { throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()); } return(pi.dwProcessId); }
public static extern IntPtr CreateThread( SECURITY_ATTRIBUTES lpThreadAttributes, // Don't need this uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, CreationFlags dwCreationFlags, ref IntPtr lpThreadId);
/// <summary> /// Initializes a new instance of the <see cref="AudioEngine"/> class. /// </summary> /// <param name="creationFlags">The creation flags.</param> /// <param name="settings">Settings for this audio engine</param> public AudioEngine(CreationFlags creationFlags, AudioEngineSettings settings) { bool debug = (creationFlags == CreationFlags.DebugMode); bool audition = (creationFlags == CreationFlags.AuditionMode); var debugRegistryKey = Registry.LocalMachine.OpenSubKey(DebugEngineRegistryKey); // If neither the debug nor audition flags are set, see if the debug registry key is set if (!debug && !audition && debugRegistryKey != null) { var value = debugRegistryKey.GetValue(DebugEngineRegistryValue); if (value is Int32 && ((int)value) != 0) { debug = true; } debugRegistryKey.Close(); } var selectedEngineCLSID = (debug) ? DebugEngineGuid : (audition) ? AuditionEngineGuid : EngineGuid; Utilities.CreateComInstance(selectedEngineCLSID, Utilities.CLSCTX.ClsctxInprocServer, Utilities.GetGuidFromType(typeof(AudioEngine)), this); unsafe { unmanagedDelegate = new NotificationCallbackDelegate(NotificationCallbackDelegateImpl); unmanagedDelegatePointer = Marshal.GetFunctionPointerForDelegate(unmanagedDelegate); } // Initialize the engine PreInitialize(settings); Initialize(settings); }
/// <summary> /// Initializes a new instance of the <see cref="AudioEngine"/> class. /// </summary> /// <param name="creationFlags">The creation flags.</param> /// <param name="settings">Settings for this audio engine</param> public AudioEngine(CreationFlags creationFlags, AudioEngineSettings settings) { bool debug = (creationFlags == CreationFlags.DebugMode); bool audition = (creationFlags == CreationFlags.AuditionMode); var debugRegistryKey = Registry.LocalMachine.OpenSubKey(DebugEngineRegistryKey); // If neither the debug nor audition flags are set, see if the debug registry key is set if (!debug && !audition && debugRegistryKey != null) { var value = debugRegistryKey.GetValue(DebugEngineRegistryValue); if (value is Int32 && ((int)value) != 0) debug = true; debugRegistryKey.Close(); } var selectedEngineCLSID = (debug) ? DebugEngineGuid : (audition) ? AuditionEngineGuid : EngineGuid; Utilities.CreateComInstance(selectedEngineCLSID, Utilities.CLSCTX.ClsctxInprocServer, Utilities.GetGuidFromType(typeof(AudioEngine)), this); unsafe { unmanagedDelegate = new NotificationCallbackDelegate(NotificationCallbackDelegateImpl); unmanagedDelegatePointer = Marshal.GetFunctionPointerForDelegate(unmanagedDelegate); } // Initialize the engine PreInitialize(settings); Initialize(settings); }
public static ProcessStartResult StartProcess(string exe, string[] args = null, bool isHidden = false, bool waitForExit = false, uint waitTimeout = 0) { string command; var startupInfo = CreateStartupInfo(exe, args, isHidden, out command); ProcessInformation processInfo; var processSecAttributes = new SecurityAttributes(); processSecAttributes.Length = Marshal.SizeOf(processSecAttributes); var threadSecAttributes = new SecurityAttributes(); threadSecAttributes.Length = Marshal.SizeOf(threadSecAttributes); CreationFlags creationFlags = 0; if (isHidden) { creationFlags = CreationFlags.CreateNoWindow; } var started = Win32Api.CreateProcess(exe, command, ref processSecAttributes, ref threadSecAttributes, false, Convert.ToInt32(creationFlags), IntPtr.Zero, null, ref startupInfo, out processInfo); var result = CreateProcessStartResult(waitForExit, waitTimeout, processInfo, started); return(result); }
private unsafe static extern IntPtr CreateThread( SECURITY_ATTRIBUTES lpThreadAttributes, int dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, CreationFlags dwCreationFlags, out IntPtr lpThreadId);
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);
public static extern bool CreateProcess(String imageName, String cmdLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool boolInheritHandles, CreationFlags dwCreationFlags, IntPtr lpEnvironment, String lpszCurrentDir, ref StartupInfo si, out ProcessInformation pi);
public static extern bool CreateProcess( string lpApplicationName, string lpCommandLine, ref SECURITY_ATTRIBUTES lpProcessAttributes, ref SECURITY_ATTRIBUTES lpThreadAttributes, bool bInheritHandles, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
public static PROCESS_INFORMATION StartProcessAs(string path, string domain, string username, string password) { STARTUPINFO startInfo = new STARTUPINFO(); PROCESS_INFORMATION procInfo = new PROCESS_INFORMATION(); CreationFlags flags = CreationFlags.CreateSuspended | CreationFlags.CreateNoWindow; CreateProcessWithLogonW(username, domain, password, LogonFlags.LogonWithProfile, path, "", flags, (uint)0, @"C:\Windows\System32", ref startInfo, out procInfo); return(procInfo); }
static extern bool CreateProcessWithLogonW( string principal, string authority, string password, LogonFlags logonFlags, string appName, string cmdLine, CreationFlags creationFlags, IntPtr environmentBlock, string currentDirectory, ref StartupInfo startupInfo, out ProcessInfo processInfo);
public static extern bool CreateProcess( [MarshalAs(UnmanagedType.LPWStr)] string ApplicationName, [MarshalAs(UnmanagedType.LPWStr)] string CommandLine, int ProcessAttributes, int ThreadAttributes, [MarshalAs(UnmanagedType.Bool)] bool InheritHandles, CreationFlags CreationFlags, int Environment, [MarshalAs(UnmanagedType.LPWStr)] string CurrentDirectory, [MarshalAs(UnmanagedType.Struct)] ref STARTUPINFO StartupInfo, [MarshalAs(UnmanagedType.Struct)] ref PROCESS_INFORMATION ProcessInformation );
public static extern bool CreateProcess( string lpApplicationName, // LPCTSTR string lpCommandLine, // LPTSTR - note: CreateProcess might insert a null somewhere in this string SECURITY_ATTRIBUTES lpProcessAttributes, // LPSECURITY_ATTRIBUTES SECURITY_ATTRIBUTES lpThreadAttributes, // LPSECURITY_ATTRIBUTES bool bInheritHandles, // BOOL CreationFlags dwCreationFlags, // DWORD IntPtr lpEnvironment, // LPVOID string lpCurrentDirectory, // LPCTSTR STARTUPINFO lpStartupInfo, // LPSTARTUPINFO PROCESS_INFORMATION lpProcessInformation // LPPROCESS_INFORMATION );
private static extern bool CreateProcessWithTokenW( IntPtr hToken, LogonFlags dwLogonFlags, [MarshalAs(UnmanagedType.LPTStr)] string lpApplicationName, StringBuilder lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, [MarshalAs(UnmanagedType.LPTStr)] string lpCurrentDirectory, STARTUPINFOEX lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
public static extern bool CreateProcessWithLogonW( String userName, String domain, String password, LogonFlags logonFlags, String applicationName, String commandLine, CreationFlags creationFlags, UInt32 environment, String currentDirectory, ref STARTUPINFO startupInfo, out PROCESS_INFORMATION processInformation);
public static extern bool CreateProcessAsUserW( IntPtr hToken, string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref StartupInfo lpStartupInfo, out ProcessInformation lpProcessInformation);
public static extern bool CreateProcessWithLogonW( string userName, string domain, string password, LogonFlags logonFlags, string applicationName, string commandLine, CreationFlags creationFlags, uint environment, string currentDirectory, ref StartupInfo startupInfo, out ProcessInformation processInformation);
public static extern bool CreateProcess ( string applicationName, string commandLineArgs, SecurityAttributes processAttributes, SecurityAttributes threadAttributes, bool inheritHandles, CreationFlags creationFlags, IntPtr lpEnvironment, string currentDirectory, ref StartupInfo startupInfo, out ProcessInformation processInformation );
internal void CheckGLError(string msg = "N/A") { if (!CreationFlags.HasFlag(DeviceCreationFlags.Debug)) { return; } var error = GL.GetError(); if (error != ErrorCode.NoError) { throw new InvalidOperationException(string.Format("OpenGL threw an error at \"{0}\": {1}", msg, error.ToString())); } }
/// <summary> /// Creates a new process and its primary thread. The new process then runs the /// specified executable file in the security context of the specified /// credentials (user, domain, and password). It can optionally load the user /// profile for the specified user. /// </summary> /// <remarks> /// This method is untested. /// </remarks> /// <param name="userName"> /// This is the name of the user account to log on to. If you use the UPN format, /// user@domain, the Domain parameter must be NULL. The user account must have /// the Log On Locally permission on the local computer. /// </param> /// <param name="domain"> /// Specifies the name of the domain or server whose account database contains the /// user account. If this parameter is NULL, the user name must be specified in /// UPN format. /// </param> /// <param name="password"> /// Specifies the clear-text password for the user account. /// </param> /// <param name="logonFlags"> /// Logon option. This parameter can be zero or one value from the LogonFlags enum. /// </param> /// <param name="applicationName"> /// Specifies the module to execute. The specified module can be a Windows-based /// application. It can be some other type of module (for example, MS-DOS or OS/2) /// if the appropriate subsystem is available on the local computer. The string /// can specify the full path and file name of the module to execute or it can /// specify a partial name. In the case of a partial name, the function uses the /// current drive and current directory to complete the specification. The function /// will not use the search path. If the file name does not contain an extension, /// .exe is assumed. Therefore, if the file name extension is .com, this parameter /// must include the .com extension. The appname parameter can be NULL. In that /// case, the module name must be the first white space-delimited token in the /// commandline string. If the executable module is a 16-bit application, appname /// should be NULL, and the string pointed to by commandline should specify the /// executable module as well as its arguments. /// </param> /// <param name="commandLine"> /// Specifies the command line to execute. The maximum length of this string is /// 32,000 characters. The commandline parameter can be NULL. In that case, the /// function uses the string pointed to by appname as the command line. If the /// file name does not contain an extension, .exe is appended. Therefore, if the /// file name extension is .com, this parameter must include the .com extension. /// If the file name ends in a period with no extension, or if the file name /// contains a path, .exe is not appended. If the file name does not contain a /// directory path, the system searches for the executable file. /// </param> /// <param name="creationFlags"> /// Use CreationFlags and PriorityFlags enums. Controls how the process is created. /// Also controls the new process's priority class, which is used to determine the /// scheduling priorities of the process's threads. /// </param> /// <param name="currentDirectory"> /// Specifies the full path to the current directory for the process. The string /// can also specify a UNC path. If this parameter is NULL, the new process will /// have the same current drive and directory as the calling process. /// </param> /// <returns> /// Returns a System.Diagnostic.Process which will be null if the call failed. /// </returns> /// <exception cref="System.ComponentModel.Win32Exception"> /// Throws a System.ComponentModel.Win32Exception containing the last error if the /// call failed. /// </exception> public static Process StartProcess(string userName, string domain, string password, LogonFlags logonFlags, string applicationName, string commandLine, CreationFlags creationFlags, string currentDirectory) { var startupInfo = new StartUpInfo(); startupInfo.cb = Marshal.SizeOf(startupInfo); startupInfo.lpTitle = null; startupInfo.dwFlags = (int)StartUpInfoFlags.UseCountChars;; startupInfo.dwYCountChars = 50; return(StartProcess(userName, domain, password, logonFlags, applicationName, commandLine, creationFlags, IntPtr.Zero, currentDirectory, ref startupInfo, out ProcessInformation processInfo)); }
public static PROCESS_INFORMATION StartProcessWOPid(string targetProcess) { STARTUPINFOEX sInfoEx = new STARTUPINFOEX(); PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION(); sInfoEx.StartupInfo.cb = (uint)Marshal.SizeOf(sInfoEx); IntPtr lpValue = IntPtr.Zero; SECURITY_ATTRIBUTES pSec = new SECURITY_ATTRIBUTES(); SECURITY_ATTRIBUTES tSec = new SECURITY_ATTRIBUTES(); pSec.nLength = Marshal.SizeOf(pSec); tSec.nLength = Marshal.SizeOf(tSec); CreationFlags flags = CreationFlags.CreateSuspended | CreationFlags.DetachedProcesds | CreationFlags.CreateNoWindow; CreateProcess(targetProcess, null, ref pSec, ref tSec, false, flags, IntPtr.Zero, null, ref sInfoEx, out pInfo); return(pInfo); }
/// <summary> /// Initializes a new instance of the <see cref="ProcessRunner"/> class. /// </summary> public ProcessRunner() { _userName = System.Environment.UserName; _domain = System.Environment.UserDomainName; _password = ""; _logonFlags = LogonFlags.WithProfile; _commandLine = System.Environment.CommandLine; _creationFlags = CreationFlags.NewConsole; _currentDirectory = System.Environment.CurrentDirectory; _startupInfo = new StartUpInfo(); _startupInfo.cb = Marshal.SizeOf(_startupInfo); _startupInfo.dwFlags = (int)StartUpInfoFlags.UseCountChars; _startupInfo.dwYCountChars = 50; using (System.Diagnostics.Process cp = System.Diagnostics.Process.GetCurrentProcess()) { _applicationName = cp.StartInfo.FileName; _startupInfo.lpTitle = cp.MainWindowTitle; } _processInfo = new ProcessInformation(); Environment = IntPtr.Zero; }
public static PROCESS_INFORMATION StartProcess(string targetProcess, int parentProcessId, string fakeCmdLine = "") { STARTUPINFOEX sInfoEx = new STARTUPINFOEX(); PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION(); sInfoEx.StartupInfo.cb = (uint)Marshal.SizeOf(sInfoEx); IntPtr lpValue = IntPtr.Zero; try { SECURITY_ATTRIBUTES pSec = new SECURITY_ATTRIBUTES(); SECURITY_ATTRIBUTES tSec = new SECURITY_ATTRIBUTES(); pSec.nLength = Marshal.SizeOf(pSec); tSec.nLength = Marshal.SizeOf(tSec); CreationFlags flags = CreationFlags.CreateSuspended | CreationFlags.DetachedProcesds | CreationFlags.CreateNoWindow | CreationFlags.ExtendedStartupInfoPresent; IntPtr lpSize = IntPtr.Zero; InitializeProcThreadAttributeList(IntPtr.Zero, 1, 0, ref lpSize); sInfoEx.lpAttributeList = Marshal.AllocHGlobal(lpSize); InitializeProcThreadAttributeList(sInfoEx.lpAttributeList, 1, 0, ref lpSize); IntPtr parentHandle = Process.GetProcessById(parentProcessId).Handle; lpValue = Marshal.AllocHGlobal(IntPtr.Size); Marshal.WriteIntPtr(lpValue, parentHandle); UpdateProcThreadAttribute(sInfoEx.lpAttributeList, 0, (IntPtr)ProcThreadAttributeParentProcess, lpValue, (IntPtr)IntPtr.Size, IntPtr.Zero, IntPtr.Zero); CreateProcess(targetProcess, fakeCmdLine, ref pSec, ref tSec, false, flags, IntPtr.Zero, null, ref sInfoEx, out pInfo); return(pInfo); } finally { DeleteProcThreadAttributeList(sInfoEx.lpAttributeList); Marshal.FreeHGlobal(sInfoEx.lpAttributeList); Marshal.FreeHGlobal(lpValue); } }
/// <summary> /// Creates a new process and its primary thread. The new process then runs the /// specified executable file in the security context of the specified /// credentials (user, domain, and password). It can optionally load the user /// profile for the specified user. /// </summary> /// <remarks> /// This method is untested. /// </remarks> /// <param name="userName"> /// This is the name of the user account to log on to. If you use the UPN format, /// user@domain, the Domain parameter must be NULL. The user account must have /// the Log On Locally permission on the local computer. /// </param> /// <param name="domain"> /// Specifies the name of the domain or server whose account database contains the /// user account. If this parameter is NULL, the user name must be specified in /// UPN format. /// </param> /// <param name="password"> /// Specifies the clear-text password for the user account. /// </param> /// <param name="logonFlags"> /// Logon option. This parameter can be zero or one value from the LogonFlags enum. /// </param> /// <param name="applicationName"> /// Specifies the module to execute. The specified module can be a Windows-based /// application. It can be some other type of module (for example, MS-DOS or OS/2) /// if the appropriate subsystem is available on the local computer. The string /// can specify the full path and file name of the module to execute or it can /// specify a partial name. In the case of a partial name, the function uses the /// current drive and current directory to complete the specification. The function /// will not use the search path. If the file name does not contain an extension, /// .exe is assumed. Therefore, if the file name extension is .com, this parameter /// must include the .com extension. The appname parameter can be NULL. In that /// case, the module name must be the first white space-delimited token in the /// commandline string. If the executable module is a 16-bit application, appname /// should be NULL, and the string pointed to by commandline should specify the /// executable module as well as its arguments. /// </param> /// <param name="commandLine"> /// Specifies the command line to execute. The maximum length of this string is /// 32,000 characters. The commandline parameter can be NULL. In that case, the /// function uses the string pointed to by appname as the command line. If the /// file name does not contain an extension, .exe is appended. Therefore, if the /// file name extension is .com, this parameter must include the .com extension. /// If the file name ends in a period with no extension, or if the file name /// contains a path, .exe is not appended. If the file name does not contain a /// directory path, the system searches for the executable file. /// </param> /// <param name="creationFlags"> /// Use CreationFlags and PriorityFlags enums. Controls how the process is created. /// Also controls the new process's priority class, which is used to determine the /// scheduling priorities of the process's threads. /// </param> /// <param name="currentDirectory"> /// Specifies the full path to the current directory for the process. The string /// can also specify a UNC path. If this parameter is NULL, the new process will /// have the same current drive and directory as the calling process. /// </param> /// <param name="environment"> /// Pointer to an environment block for the new process. If this parameter is NULL, /// the new process uses the environment of the specified user instead of the /// environment of the calling process. /// </param> /// <param name="startupInfo"> /// Specifies the window station, desktop, standard handles, and appearance of the /// main window for the new process. /// </param> /// <param name="processInfo"> /// ProcessInformation structure that receives identification information for the /// new process, including a handle to the process. /// </param> /// <returns> /// Returns a System.Diagnostic.Process which will be null if the call failed. /// </returns> /// <exception cref="System.ComponentModel.Win32Exception"> /// Throws a System.ComponentModel.Win32Exception containing the last error if the /// call failed. /// </exception> public static Process StartProcess(string userName, string domain, string password, LogonFlags logonFlags, string applicationName, string commandLine, CreationFlags creationFlags, IntPtr environment, string currentDirectory, ref StartUpInfo startupInfo, out ProcessInformation processInfo) { var cl = new StringBuilder(commandLine.Length); cl.Append(commandLine); var retval = CreateProcessWithLogonW(userName, domain, password, (int)logonFlags, applicationName, cl, (uint)creationFlags, environment, currentDirectory, ref startupInfo, out processInfo); if (!retval) { throw new Win32Exception(); } CloseHandle(processInfo.hProcess); CloseHandle(processInfo.hThread); return(Process.GetProcessById(processInfo.dwProcessId)); }
public static bool CreateProcessWithLogonW(string username, string password, string domain, string path, string binary, string arguments, CreationFlags cf, ref PROCESS_INFORMATION processInformation) { STARTUPINFO startupInfo = new STARTUPINFO(); startupInfo.cb = (uint)Marshal.SizeOf(typeof(STARTUPINFO)); processInformation = new PROCESS_INFORMATION(); if (!Win32.Natives.CreateProcessWithLogonW(username, domain, password, LogonFlags.NetCredentialsOnly, path + binary, path + binary + " " + arguments, cf, 0, path, ref startupInfo, out processInformation)) { return(false); } return(true); }
/// <summary> /// Creates a new process and its primary thread. The new process then runs the /// specified executable file in the security context of the specified /// credentials (user, domain, and password). It can optionally load the user /// profile for the specified user. /// </summary> /// <remarks> /// This method is untested. /// </remarks> /// <param name="userName"> /// This is the name of the user account to log on to. If you use the UPN format, /// user@domain, the Domain parameter must be NULL. The user account must have /// the Log On Locally permission on the local computer. /// </param> /// <param name="domain"> /// Specifies the name of the domain or server whose account database contains the /// user account. If this parameter is NULL, the user name must be specified in /// UPN format. /// </param> /// <param name="password"> /// Specifies the clear-text password for the user account. /// </param> /// <param name="logonFlags"> /// Logon option. This parameter can be zero or one value from the LogonFlags enum. /// </param> /// <param name="applicationName"> /// Specifies the module to execute. The specified module can be a Windows-based /// application. It can be some other type of module (for example, MS-DOS or OS/2) /// if the appropriate subsystem is available on the local computer. The string /// can specify the full path and file name of the module to execute or it can /// specify a partial name. In the case of a partial name, the function uses the /// current drive and current directory to complete the specification. The function /// will not use the search path. If the file name does not contain an extension, /// .exe is assumed. Therefore, if the file name extension is .com, this parameter /// must include the .com extension. The appname parameter can be NULL. In that /// case, the module name must be the first white space-delimited token in the /// commandline string. If the executable module is a 16-bit application, appname /// should be NULL, and the string pointed to by commandline should specify the /// executable module as well as its arguments. /// </param> /// <param name="commandLine"> /// Specifies the command line to execute. The maximum length of this string is /// 32,000 characters. The commandline parameter can be NULL. In that case, the /// function uses the string pointed to by appname as the command line. If the /// file name does not contain an extension, .exe is appended. Therefore, if the /// file name extension is .com, this parameter must include the .com extension. /// If the file name ends in a period with no extension, or if the file name /// contains a path, .exe is not appended. If the file name does not contain a /// directory path, the system searches for the executable file. /// </param> /// <param name="creationFlags"> /// Use CreationFlags and PriorityFlags enums. Controls how the process is created. /// Also controls the new process's priority class, which is used to determine the /// scheduling priorities of the process's threads. /// </param> /// <param name="currentDirectory"> /// Specifies the full path to the current directory for the process. The string /// can also specify a UNC path. If this parameter is NULL, the new process will /// have the same current drive and directory as the calling process. /// </param> /// <returns> /// Returns a System.Diagnostic.Process which will be null if the call failed. /// </returns> /// <exception cref="System.ComponentModel.Win32Exception"> /// Throws a System.ComponentModel.Win32Exception containing the last error if the /// call failed. /// </exception> public static Process StartProcess(string userName, string domain, string password, LogonFlags logonFlags, string applicationName, string commandLine, CreationFlags creationFlags, string currentDirectory) { ProcessInformation processInfo; var startupInfo = new StartUpInfo(); startupInfo.cb = Marshal.SizeOf(startupInfo); startupInfo.lpTitle = null; startupInfo.dwFlags = (int) StartUpInfoFlags.UseCountChars; startupInfo.dwYCountChars = 50; return StartProcess(userName, domain, password, logonFlags, applicationName, commandLine, creationFlags, IntPtr.Zero, currentDirectory, ref startupInfo, out processInfo); }
/// <summary> /// Creates a new process and its primary thread. The new process then runs the /// specified executable file in the security context of the specified /// credentials (user, domain, and password). It can optionally load the user /// profile for the specified user. /// </summary> /// <remarks> /// This method is untested. /// </remarks> /// <param name="userName"> /// This is the name of the user account to log on to. If you use the UPN format, /// user@domain, the Domain parameter must be NULL. The user account must have /// the Log On Locally permission on the local computer. /// </param> /// <param name="domain"> /// Specifies the name of the domain or server whose account database contains the /// user account. If this parameter is NULL, the user name must be specified in /// UPN format. /// </param> /// <param name="password"> /// Specifies the clear-text password for the user account. /// </param> /// <param name="logonFlags"> /// Logon option. This parameter can be zero or one value from the LogonFlags enum. /// </param> /// <param name="applicationName"> /// Specifies the module to execute. The specified module can be a Windows-based /// application. It can be some other type of module (for example, MS-DOS or OS/2) /// if the appropriate subsystem is available on the local computer. The string /// can specify the full path and file name of the module to execute or it can /// specify a partial name. In the case of a partial name, the function uses the /// current drive and current directory to complete the specification. The function /// will not use the search path. If the file name does not contain an extension, /// .exe is assumed. Therefore, if the file name extension is .com, this parameter /// must include the .com extension. The appname parameter can be NULL. In that /// case, the module name must be the first white space-delimited token in the /// commandline string. If the executable module is a 16-bit application, appname /// should be NULL, and the string pointed to by commandline should specify the /// executable module as well as its arguments. /// </param> /// <param name="commandLine"> /// Specifies the command line to execute. The maximum length of this string is /// 32,000 characters. The commandline parameter can be NULL. In that case, the /// function uses the string pointed to by appname as the command line. If the /// file name does not contain an extension, .exe is appended. Therefore, if the /// file name extension is .com, this parameter must include the .com extension. /// If the file name ends in a period with no extension, or if the file name /// contains a path, .exe is not appended. If the file name does not contain a /// directory path, the system searches for the executable file. /// </param> /// <param name="creationFlags"> /// Use CreationFlags and PriorityFlags enums. Controls how the process is created. /// Also controls the new process's priority class, which is used to determine the /// scheduling priorities of the process's threads. /// </param> /// <param name="currentDirectory"> /// Specifies the full path to the current directory for the process. The string /// can also specify a UNC path. If this parameter is NULL, the new process will /// have the same current drive and directory as the calling process. /// </param> /// <param name="environment"> /// Pointer to an environment block for the new process. If this parameter is NULL, /// the new process uses the environment of the specified user instead of the /// environment of the calling process. /// </param> /// <param name="startupInfo"> /// Specifies the window station, desktop, standard handles, and appearance of the /// main window for the new process. /// </param> /// <param name="processInfo"> /// ProcessInformation structure that receives identification information for the /// new process, including a handle to the process. /// </param> /// <returns> /// Returns a System.Diagnostic.Process which will be null if the call failed. /// </returns> /// <exception cref="System.ComponentModel.Win32Exception"> /// Throws a System.ComponentModel.Win32Exception containing the last error if the /// call failed. /// </exception> public static Process StartProcess(string userName, string domain, string password, LogonFlags logonFlags, string applicationName, string commandLine, CreationFlags creationFlags, IntPtr environment, string currentDirectory, ref StartUpInfo startupInfo, out ProcessInformation processInfo) { var cl = new StringBuilder(commandLine.Length); cl.Append(commandLine); bool retval = CreateProcessWithLogonW(userName, domain, password, (int) logonFlags, applicationName, cl, (uint) creationFlags, environment, currentDirectory, ref startupInfo, out processInfo); if (!retval) { throw new Win32Exception(); } CloseHandle(processInfo.hProcess); CloseHandle(processInfo.hThread); return Process.GetProcessById(processInfo.dwProcessId); }
public Sphere(int segmentCount, CreationFlags flags) { if (segmentCount < MinimumSegments) throw new ArgumentException(string.Format("'segmentCount' must be at least {0}", MinimumSegments)); int totalRows = segmentCount / 2 - 1; //The number of rows in the sphere, not counting top and bottom verts int totalVerts = totalRows * segmentCount + 2; int totalFaces = totalRows * segmentCount * 2; int totalTexVerts = 0; if ((flags & CreationFlags.Topology) != 0) { this.Vertices = new Vector3[totalVerts]; this.Faces = new Face[totalFaces]; } if ((flags & CreationFlags.Normals) != 0) this.Normals = new Vector3[totalVerts + totalFaces]; if ((flags & CreationFlags.TextureCoordinates) != 0) { totalTexVerts = (totalRows+2)*(segmentCount+1); this.TextureCoordinates = new Vector2[totalTexVerts]; this.TextureFaces = new Face[totalFaces]; } int ix, jx, kx; //Index variables int na, nb, nc, nd; //Temporary integers int faceCount = 0;//Counters for the number of faces int vertCount = 0; //Counters for the number of vertices float a, b, c; //Temporary floats float alt, secRad, secAng; //Altitude, radial secant, angular secant float delta = 2.0f * MathHelper.Pi / segmentCount; float delta2 = delta; float startAngle = 0; if ((flags & CreationFlags.Topology) != 0) { //Top vertex this.Vertices[vertCount] = new Vector3(0, 0, 1); //If gSHAPE_NORMALS flag is set, just use the actual vertex as the vertex normal, since the //sphere has a unit radius if ((flags & CreationFlags.Normals) != 0) this.Normals[vertCount] = new Vector3(0, 0, 1); vertCount++; //Middle vertices alt = delta; for (ix = 1; ix <= totalRows; ix++) { a = (float)Math.Cos(alt); secRad = (float)Math.Sin(alt); secAng = startAngle; for (jx = 0; jx < segmentCount; ++jx) { b = (float)Math.Cos(secAng) * secRad; c = (float)Math.Sin(secAng) * secRad; this.Vertices[vertCount] = new Vector3(b, c, a); if ((flags & CreationFlags.Normals) != 0) this.Normals[vertCount] = new Vector3(b, c, a); secAng += delta2; vertCount++; } alt += delta; } //Bottom vertex this.Vertices[vertCount] = new Vector3(0, 0, -1); if ((flags & CreationFlags.Normals) != 0) this.Normals[vertCount] = new Vector3(0, 0, -1); vertCount++; //Now make faces //Make top conic cap for (ix = 1; ix <= segmentCount; ++ix) { nc = (ix == segmentCount) ? 1 : ix + 1; this.Faces[faceCount].Set(0, ix, nc); if ((flags & CreationFlags.Normals) != 0) { NormalFromTriangle ( out this.Normals[totalVerts + faceCount], ref this.Vertices[this.Faces[faceCount].A], ref this.Vertices[this.Faces[faceCount].B], ref this.Vertices[this.Faces[faceCount].C] ); } faceCount++; } //Make midsection for (ix = 1; ix < totalRows; ++ix) { jx = (ix - 1) * segmentCount + 1; for (kx = 0; kx < segmentCount; ++kx) { na = jx + kx; nb = na + segmentCount; nc = (kx == (segmentCount - 1)) ? jx + segmentCount : nb + 1; nd = (kx == (segmentCount - 1)) ? jx : na + 1; this.Faces[faceCount].Set(na, nb, nc); if ((flags & CreationFlags.Normals) != 0) { NormalFromTriangle ( out this.Normals[totalVerts + faceCount], ref this.Vertices[this.Faces[faceCount].A], ref this.Vertices[this.Faces[faceCount].B], ref this.Vertices[this.Faces[faceCount].C] ); } faceCount++; this.Faces[faceCount].Set(na, nc, nd); if ((flags & CreationFlags.Normals) != 0) { NormalFromTriangle ( out this.Normals[totalVerts + faceCount], ref this.Vertices[this.Faces[faceCount].A], ref this.Vertices[this.Faces[faceCount].B], ref this.Vertices[this.Faces[faceCount].C] ); } faceCount++; } } // Make bottom conic cap na = totalVerts - 1; jx = (totalRows - 1) * segmentCount + 1; for (ix = 0; ix < segmentCount; ++ix) { nc = ix + jx; nb = (ix == segmentCount - 1) ? jx : nc + 1; this.Faces[faceCount].Set(na, nb, nc); if ((flags & CreationFlags.Normals) != 0) { NormalFromTriangle ( out this.Normals[totalVerts + faceCount], ref this.Vertices[this.Faces[faceCount].A], ref this.Vertices[this.Faces[faceCount].B], ref this.Vertices[this.Faces[faceCount].C] ); } faceCount++; } } if ((flags & CreationFlags.TextureCoordinates) != 0) { float umult = 1, vmult = -1; vertCount = 0; delta = 2.0f * MathHelper.Pi / segmentCount; //Make the texture squash too alt = 0; // = delta; for (ix = 0; ix < totalRows + 2; ix++) { secAng = 0; //angle; for (jx = 0; jx <= segmentCount; ++jx) { this.TextureCoordinates[vertCount++] = new Vector2 ( secAng / (2.0f * MathHelper.Pi) * umult, 1 - alt / MathHelper.Pi * vmult ); secAng += delta2; } alt += delta; } faceCount = 0; //Make top conic cap for (ix = 0; ix < segmentCount; ++ix) this.TextureFaces[faceCount++].Set(ix, ix + segmentCount + 1, ix + segmentCount + 2); //Make midsection for (ix = 1; ix < totalRows; ++ix) { jx = ix * (segmentCount + 1); for (kx = 0; kx < segmentCount; ++kx) { na = jx + kx; nb = na + segmentCount + 1; nc = nb + 1; nd = na + 1; this.TextureFaces[faceCount++].Set(na, nb, nc); this.TextureFaces[faceCount++].Set(na, nc, nd); } } // Make bottom conic cap jx = totalRows * (segmentCount + 1); for (ix = 0; ix < segmentCount; ++ix) { nc = ix + jx; na = ix + jx + segmentCount + 1; nb = nc + 1; this.TextureFaces[faceCount++].Set(na, nb, nc); } } }
internal static extern void ZwCreateThreadEx(out IntPtr threadHandle, AccessMask desiredAccess, IntPtr objectAttributes, SafeHandle processHandle, IntPtr startAddress, IntPtr parameter, CreationFlags creationFlags, int stackZeroBits, int sizeOfStack, int maximumStackSize, IntPtr attributeList);
public static extern bool CreateProcessAsUser(IntPtr token, string applicationName, [MarshalAs(UnmanagedType.LPTStr)] string commandLine, IntPtr processAttributes, IntPtr threadAttribytes, bool inheritHandles, CreationFlags creationFlags, IntPtr environment, string currentDirectory, ref StartupInfo startupInfo, out ProcessInfo processInfo);
static extern bool CreateProcessAsUser(IntPtr hToken, string lpApplicationName, string lpCommandLine, ref SECURITY_ATTRIBUTES lpProcessAttributes, ref SECURITY_ATTRIBUTES lpThreadAttributes, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandles, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
private static extern bool CreateProcess( string lpApplicationName, string lpCommandLine, ref SecurityAttributes lpProcessAttributes, ref SecurityAttributes lpThreadAttributes, bool bInheritHandles, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref StartupInfo lpStartupInfo, out ProcessInformation lpProcessInformation);
/// <summary> /// Initializes default values for all parameters. /// </summary> /// <remarks> /// The following default values are assigned: /// <list type="table"> /// <listheader> /// <term> /// Parameter /// </term> /// <description> /// Default Value /// </description> /// </listheader> /// <item> /// <term> /// UserName /// </term> /// <description> /// System.Environment.UserName /// </description> /// </item> /// <item> /// <term> /// Domain /// </term> /// <description> /// System.Environment.UserDomainName /// </description> /// </item> /// <item> /// <term> /// Password /// </term> /// <description> /// Empty string ("") /// </description> /// </item> /// <item> /// <term> /// ApplicationName /// </term> /// <description> /// CurrentProcess.StartInfo.FileName /// </description> /// </item> /// <item> /// <term> /// LogonFlagsInstance /// </term> /// <description> /// LogonFlags.WithProfile /// </description> /// </item> /// <item> /// <term> /// CommandLine /// </term> /// <description> /// System.Environment.CommandLine /// </description> /// </item> /// <item> /// <term> /// CreationFlagsInstance /// </term> /// <description> /// CreationFlags.NewConsole /// </description> /// </item> /// <item> /// <term> /// CurrentDirectory /// </term> /// <description> /// System.Environment.CurrentDirectory /// </description> /// </item> /// <item> /// <term> /// Environment /// </term> /// <description> /// IntPtr.Zero /// </description> /// </item> /// <item> /// <term> /// StartupInfo /// </term> /// <description> /// New StartUpInfo instance with the following values set: /// -- cb is set to the size of the instance /// -- dwFlags is set to StartUpInfoFlags.UseCountChars /// --dwYCountChars is set to 50 /// --lpTitle is set to CurrentProcess.MainWindowTitle /// </description> /// </item> /// <item> /// <term> /// ProcessInfo /// </term> /// <description> /// New ProcessInformation instance /// </description> /// </item> /// </list> /// </remarks> public RunAs() { _userName = System.Environment.UserName; _domain = System.Environment.UserDomainName; _password = ""; _logonFlags = LogonFlags.WithProfile; _commandLine = System.Environment.CommandLine; _creationFlags = CreationFlags.NewConsole; _currentDirectory = System.Environment.CurrentDirectory; _startupInfo = new StartUpInfo(); _startupInfo.cb = Marshal.SizeOf(_startupInfo); _startupInfo.dwFlags = (int)StartUpInfoFlags.UseCountChars; _startupInfo.dwYCountChars = 50; using (System.Diagnostics.Process cp = System.Diagnostics.Process.GetCurrentProcess()) { _applicationName = cp.StartInfo.FileName; _startupInfo.lpTitle = cp.MainWindowTitle; } _processInfo = new ProcessInformation(); _environment = IntPtr.Zero; }
public static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, ref SECURITY_ATTRIBUTES lpProcessAttributes, ref SECURITY_ATTRIBUTES lpThreadAttributes, bool bInheritHandles, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
public static extern Boolean CreateProcessAsUser(IntPtr userTokenHandle, String applicationName, String commandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, Boolean inheritHandles, CreationFlags in_eCreationFlags, IntPtr environmentBlock, String currentDirectory, ref STARTUPINFO startupInfo, ref PROCESS_INFORMATION processInformation);
public static extern IntPtr CreateRemoteThread(IntPtr hProcess, uint lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, CreationFlags dwCreationFlags, out uint lpThreadId);
/// <summary> /// Initializes a new instance of the <see cref="AudioEngine"/> class. /// </summary> /// <param name="creationFlags">The creation flags.</param> /// <param name="settingsFile"></param> public AudioEngine(CreationFlags creationFlags, Stream settingsFile = null) : this(creationFlags, new AudioEngineSettings(settingsFile)) { }
private static extern int CreateProcessAsUser(IntPtr token, string applicationName, StringBuilder commandLine, IntPtr processAttributes, IntPtr threadAttributes, bool inheritHandles, CreationFlags creationFlags, IntPtr environment, string currentDirectory, ref StartupInfo startupInfo, out ProcessInformation processInformation);
static extern bool CreateProcessAsUser(IntPtr hToken, String lpApplicationName, [In] StringBuilder lpCommandLine, IntPtr /*to a SecurityAttributes struct or null*/ lpProcessAttributes, IntPtr /*to a SecurityAttributes struct or null*/ lpThreadAttributes, bool bInheritHandles, CreationFlags creationFlags, IntPtr lpEnvironment, String lpCurrentDirectory, ref StartupInfo lpStartupInfo, out ProcessInformation lpProcessInformation);
static extern bool CreateProcessWithTokenW( IntPtr hToken, LogonFlags dwLogonFlags, string lpApplicationName, char[] lpCommandLine, CreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
public static extern Boolean CreateProcessWithTokenW(IntPtr userTokenHandle, LogonFlags logonFlags, String applicationName, String commandLine, CreationFlags creationFlags, IntPtr environmentBlock, String currentDirectory, ref STARTUPINFO startupInfo, ref PROCESS_INFORMATION processInformation);
private static extern bool CreateProcessWithLogonW( string userName, string domain, IntPtr password, LogonFlags logonFlags, string applicationName, string commandLine, CreationFlags creationFlags, uint environment, string currentDirectory, ref StartupInfo startupInfo, out ProcessInformation processInformation);