本文整理汇总了C#中STARTUPINFO类的典型用法代码示例。如果您正苦于以下问题:C# STARTUPINFO类的具体用法?C# STARTUPINFO怎么用?C# STARTUPINFO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
STARTUPINFO类属于命名空间,在下文中一共展示了STARTUPINFO类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateProcess
/// <summary>
/// Creates the process.
/// </summary>
/// <param name="ProcessName">Name of the process.</param>
/// <param name="CommandLine">The command line.</param>
/// <exception cref="System.Exception">Failure</exception>
public static void CreateProcess(string ProcessName, string CommandLine)
{
Log.WriteLine("CreateProcess(" + ProcessName + ", " + CommandLine + ")");
STARTUPINFO SInfo = new STARTUPINFO();
PROCESS_INFORMATION PInfo = new PROCESS_INFORMATION();
Log.WriteLine("Try Connect to DBG");
DbgUiConnectToDbg();
Log.WriteLine("Try CreateProcess");
if (!CreateProcess(null, new StringBuilder(ProcessName).Append(" ").Append(CommandLine), null, null, false, 0x1 | 0x2, null, null, ref SInfo, ref PInfo))
{
// May be must be run under Administrator.
if (Global.IsAdministrator())
{
Log.WriteLine("Creating process failed.");
}
else
{
RestartWithAdministrator();
}
}
Log.WriteLine("Try Stop Debugging");
DbgUiStopDebugging(PInfo.hProcess);
CloseHandle(PInfo.hProcess);
CloseHandle(PInfo.hThread);
Log.WriteLine("Created Process.");
}
开发者ID:qcjxberin,项目名称:IFEOManage,代码行数:33,代码来源:Launcher.cs
示例2: Run
/// <summary>
/// Runs the
/// </summary>
public static void Run()
{
const uint NORMAL_PRIORITY_CLASS = 0x0020;
string Path = Environment.CurrentDirectory + @"\" + (Program.projectName.ToString() == "Ultimatium" ? "BlackOpsMP.exe" : "iw5mp.exe");
string Arguments = Program.Arguments;
PROCESS_INFORMATION pInfo = new PROCESS_INFORMATION();
STARTUPINFO sInfo = new STARTUPINFO();
SECURITY_ATTRIBUTES pSec = new SECURITY_ATTRIBUTES();
SECURITY_ATTRIBUTES tSec = new SECURITY_ATTRIBUTES();
pSec.nLength = Marshal.SizeOf(pSec);
tSec.nLength = Marshal.SizeOf(tSec);
bool Initialized = CreateProcess(Path, Arguments,
ref pSec, ref tSec, false, NORMAL_PRIORITY_CLASS,
IntPtr.Zero, null, ref sInfo, out pInfo);
if (Initialized)
{
Log.Write("Launching " + Program.projectName + "...");
Log.Write("Successful launch. PID: " + pInfo.dwProcessId);
Log.Write("Happy gaming!");
Environment.Exit(0x0);
}
else
{
Log.Write("ERROR: Could not launch " + Program.projectName + ". Press any key to exit.");
Console.ReadKey();
Environment.Exit(0x3);
}
}
开发者ID:GammaForce,项目名称:Updater,代码行数:31,代码来源:Launcher.cs
示例3: CreateProcess
public static extern bool CreateProcess(string lpApplicationName,
string lpCommandLine, IntPtr lpProcessAttributes,
IntPtr lpThreadAttributes,
bool bInheritHandles, ProcessCreationFlags dwCreationFlags,
IntPtr lpEnvironment, string lpCurrentDirectory,
ref STARTUPINFO lpStartupInfo,
out PROCESS_INFORMATION lpProcessInformation);
开发者ID:vans163,项目名称:linLauncher,代码行数:7,代码来源:proclauncher.cs
示例4: CreateProcess
public static PROCESS_INFORMATION CreateProcess(
string lpApplicationName,
string lpCommandLine,
IntPtr lpProcessAttributes,
IntPtr lpThreadAttributes,
bool bInheritHandles,
uint dwCreationFlags,
IntPtr lpEnvironment,
string lpCurrentDirectory)
{
var startupInfo = new STARTUPINFO();
startupInfo.cb = Marshal.SizeOf(typeof(STARTUPINFO));
PROCESS_INFORMATION pi;
if (!_CreateProcess(
lpApplicationName,
lpCommandLine,
lpProcessAttributes,
lpThreadAttributes,
bInheritHandles,
dwCreationFlags,
lpEnvironment,
lpCurrentDirectory,
ref startupInfo,
out pi))
{
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
}
return pi;
}
开发者ID:DeCarabas,项目名称:sudo,代码行数:30,代码来源:NativeMethods.cs
示例5: LaunchPathAsUser
public static bool LaunchPathAsUser(string path)
{
unsafe
{
IntPtr token;
string dir = new FileInfo(path).Directory.FullName;
STARTUPINFO startup = new STARTUPINFO
{
cb = 0, // Probably incredibly dangerous and unsafe, but you can't use sizeof(STARTUPINFO).
lpReserved = null,
lpDesktop = "winsta0\\default",
lpTitle = null,
dwFlags = 0,
cbReserved2 = 0,
lpReserved2 = IntPtr.Zero
};
PROCESS_INFORMATION procinfo;
WTSQueryUserToken(WTSGetActiveConsoleSessionId(), out token);
return CreateProcessAsUser(
token,
path,
null,
null,
null,
false,
0,
IntPtr.Zero,
dir,
ref startup,
out procinfo
);
}
}
开发者ID:hach-que,项目名称:Pivot.Update,代码行数:33,代码来源:WindowsNative.cs
示例6: Launch
public static Debuggee Launch(string executable,
string argumentString = null, string workingDirectory = null)
{
var si = new STARTUPINFO {
cb = Marshal.SizeOf(typeof(STARTUPINFO)),
};
var pi = new PROCESS_INFORMATION();
if (argumentString == string.Empty)
argumentString = null;
if (workingDirectory == string.Empty)
workingDirectory = null;
if (!API.CreateProcess(executable, argumentString, IntPtr.Zero, IntPtr.Zero, true,
ProcessCreationFlags.CreateNewConsole | // Create extra console for the process
ProcessCreationFlags.DebugOnlyThisProcess // Grant debugger access to the process
,IntPtr.Zero, workingDirectory, ref si, out pi))
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
var dbg = new Debuggee(executable,
pi.hProcess, pi.dwProcessId,
pi.hThread, pi.dwThreadId,
ExecutableMetaInfo.ExtractFrom(executable));
return dbg;
}
开发者ID:aBothe,项目名称:DDebugger,代码行数:28,代码来源:DDebugger.cs
示例7: StartProcessAsCurrentUser
public static bool StartProcessAsCurrentUser(string appPath, string cmdLine = null, string workDir = null, bool visible = true)
{
var hUserToken = IntPtr.Zero;
var startInfo = new STARTUPINFO();
var procInfo = new PROCESS_INFORMATION();
var pEnv = IntPtr.Zero;
int iResultOfCreateProcessAsUser;
startInfo.cb = Marshal.SizeOf(typeof(STARTUPINFO));
try
{
if (!GetSessionUserToken(ref hUserToken))
{
throw new Exception("StartProcessAsCurrentUser: GetSessionUserToken failed.");
}
uint dwCreationFlags = CREATE_UNICODE_ENVIRONMENT | (uint)(visible ? CREATE_NEW_CONSOLE : CREATE_NO_WINDOW);
startInfo.wShowWindow = (short)(visible ? SW.SW_SHOW : SW.SW_HIDE);
startInfo.lpDesktop = "winsta0\\default";
if (!CreateEnvironmentBlock(ref pEnv, hUserToken, false))
{
throw new Exception("StartProcessAsCurrentUser: CreateEnvironmentBlock failed.");
}
if (!CreateProcessAsUser(hUserToken,
appPath, // Application Name
cmdLine, // Command Line
IntPtr.Zero,
IntPtr.Zero,
false,
dwCreationFlags,
pEnv,
workDir, // Working directory
ref startInfo,
out procInfo))
{
throw new Exception("StartProcessAsCurrentUser: CreateProcessAsUser failed.\n");
}
iResultOfCreateProcessAsUser = Marshal.GetLastWin32Error();
}
finally
{
CloseHandle(hUserToken);
if (pEnv != IntPtr.Zero)
{
DestroyEnvironmentBlock(pEnv);
}
CloseHandle(procInfo.hThread);
CloseHandle(procInfo.hProcess);
}
return true;
}
开发者ID:supergonzales,项目名称:CreateProcessAsUser,代码行数:56,代码来源:ProcessExtensions.cs
示例8: CreateProcess
public static extern bool CreateProcess(StringBuilder lpApplicationName, StringBuilder lpCommandLine,
SECURITY_ATTRIBUTES lpProcessAttributes,
SECURITY_ATTRIBUTES lpThreadAttributes,
bool bInheritHandles,
int dwCreationFlags,
StringBuilder lpEnvironment,
StringBuilder lpCurrentDirectory,
ref STARTUPINFO lpStartupInfo,
ref PROCESS_INFORMATION lpProcessInformation
);
开发者ID:icaca,项目名称:launcher,代码行数:10,代码来源:frmLauncher.cs
示例9: CreateProcess
public static extern bool CreateProcess(String imageName,
String cmdLine,
IntPtr lpProcessAttributes,
IntPtr lpThreadAttributes,
bool boolInheritHandles,
uint dwCreationFlags,
IntPtr lpEnvironment,
String lpszCurrentDir,
ref STARTUPINFO si,
out PROCESS_INFORMATION pi);
开发者ID:alexisjojo,项目名称:tibiaezbot,代码行数:10,代码来源:WinApi.cs
示例10: CreateProcess
internal static extern bool CreateProcess(
[MarshalAs(UnmanagedType.LPTStr)] string lpApplicationName,
StringBuilder lpCommandLine,
ref SECURITY_ATTRIBUTES procSecAttrs,
ref SECURITY_ATTRIBUTES threadSecAttrs,
bool bInheritHandles,
int dwCreationFlags,
IntPtr lpEnvironment,
[MarshalAs(UnmanagedType.LPTStr)] string lpCurrentDirectory,
STARTUPINFO lpStartupInfo,
PROCESS_INFORMATION lpProcessInformation
);
开发者ID:noahfalk,项目名称:corefx,代码行数:12,代码来源:Interop.CreateProcess.cs
示例11: RunProcess
private string RunProcess(string id, string command)
{
try {
IntPtr dupedToken = new IntPtr(0);
SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();
sa.bInheritHandle = false;
sa.Length = Marshal.SizeOf(sa);
sa.lpSecurityDescriptor = (IntPtr)0;
var token = WindowsIdentity.GetCurrent().Token;
const uint GENERIC_ALL = 0x10000000;
const int SecurityImpersonation = 2;
const int TokenType = 1;
var ret = DuplicateTokenEx(token, GENERIC_ALL, ref sa, SecurityImpersonation, TokenType, ref dupedToken);
if (ret == false)
throw new Exception("DuplicateTokenEx failed (" + Marshal.GetLastWin32Error() + ")");
STARTUPINFO si = new STARTUPINFO();
si.cb = Marshal.SizeOf(si);
si.lpDesktop = "";
PROCESS_INFORMATION pi = new PROCESS_INFORMATION();
uint exitCode;
try {
ret = CreateProcessAsUser(dupedToken, null, @"c:\windows\system32\shutdown.exe " + command + " /m " + id, ref sa, ref sa, false, 0, (IntPtr)0, "c:\\", ref si, out pi);
if (ret == false)
throw new Exception("CreateProcessAsUser failed (" + Marshal.GetLastWin32Error() + ")");
WaitForSingleObject(pi.hProcess, 10000);
GetExitCodeProcess(pi.hProcess, out exitCode);
}
catch (Exception ex) {
throw ex;
}
finally {
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
CloseHandle(dupedToken);
}
if (exitCode == 0)
return "";
return "Exit code: " + exitCode;
}
catch (Exception ex) {
return ex.Message;
}
}
开发者ID:saxx,项目名称:WolWeb,代码行数:53,代码来源:ShutdownController.cs
示例12: CreateProcessAsUser
public static extern bool CreateProcessAsUser(
IntPtr hToken,
string lpApplicationName,
string lpCommandLine,
ref SECURITY_ATTRIBUTES lpProcessAttributes,
ref SECURITY_ATTRIBUTES lpThreadAttributes,
bool bInheritHandles,
uint dwCreationFlags,
IntPtr lpEnvironment,
string lpCurrentDirectory,
ref STARTUPINFO lpStartupInfo,
out PROCESS_INFORMATION lpProcessInformation);
开发者ID:terryfan1109,项目名称:win32-test,代码行数:12,代码来源:Win32.Process.cs
示例13: CreateProcessWithLogonW
internal static extern bool CreateProcessWithLogonW(
string userName,
string domain,
string passwordInClearText,
LogonFlags logonFlags,
[MarshalAs(UnmanagedType.LPTStr)] string appName,
StringBuilder cmdLine,
int creationFlags,
IntPtr environmentBlock,
[MarshalAs(UnmanagedType.LPTStr)] string lpCurrentDirectory,
STARTUPINFO lpStartupInfo,
PROCESS_INFORMATION lpProcessInformation);
开发者ID:Czapek83,项目名称:corefx,代码行数:12,代码来源:Interop.CreateProcessWithLogon.cs
示例14: CreateProcessAsUser
public static extern Boolean CreateProcessAsUser(
IntPtr hToken,
String lpApplicationName,
String lpCommandLine,
IntPtr lpProcessAttributes,
IntPtr lpThreadAttributes,
Boolean bInheritHandles,
Int32 dwCreationFlags,
IntPtr lpEnvironment,
String lpCurrentDirectory,
ref STARTUPINFO lpStartupInfo,
out PROCESS_INFORMATION lpProcessInformation
);
开发者ID:CNU-Developers,项目名称:CNUServiceAndUpdator,代码行数:13,代码来源:Win32ProcessCall.cs
示例15: CreateProcessWithLogonW
public static extern Boolean CreateProcessWithLogonW(
String lpszUsername,
String lpszDomain,
String lpszPassword,
Int32 dwLogonFlags,
String applicationName,
String commandLine,
Int32 creationFlags,
IntPtr environment,
String currentDirectory,
ref STARTUPINFO sui,
out PROCESS_INFORMATION processInfo
);
开发者ID:CNU-Developers,项目名称:CNUServiceAndUpdator,代码行数:13,代码来源:Win32ProcessCall.cs
示例16: Main
static int Main(string[] args)
{
var exe = Assembly.GetExecutingAssembly().Location;
var dir = Path.GetDirectoryName(exe);
var name = Path.GetFileNameWithoutExtension(exe);
var configPath = Path.Combine(dir, name + ".shim");
if(!File.Exists(configPath)) {
Console.Error.WriteLine("Couldn't find " + Path.GetFileName(configPath) + " in " + dir);
return 1;
}
var config = Config(configPath);
var path = Get(config, "path");
var add_args = Get(config, "args");
var si = new STARTUPINFO();
var pi = new PROCESS_INFORMATION();
// create command line
var cmd_args = add_args ?? "";
var pass_args = Serialize(args);
if(!string.IsNullOrEmpty(pass_args)) {
if(!string.IsNullOrEmpty(cmd_args)) cmd_args += " ";
cmd_args += pass_args;
}
if(!string.IsNullOrEmpty(cmd_args)) cmd_args = " " + cmd_args;
var cmd = "\"" + path + "\"" + cmd_args;
if(!CreateProcess(null, cmd, IntPtr.Zero, IntPtr.Zero,
bInheritHandles: true,
dwCreationFlags: 0,
lpEnvironment: IntPtr.Zero, // inherit parent
lpCurrentDirectory: null, // inherit parent
lpStartupInfo: ref si,
lpProcessInformation: out pi)) {
return Marshal.GetLastWin32Error();
}
WaitForSingleObject(pi.hProcess, INFINITE);
uint exit_code = 0;
GetExitCodeProcess(pi.hProcess, out exit_code);
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return (int)exit_code;
}
开发者ID:nikolasd,项目名称:scoop,代码行数:51,代码来源:shim.cs
示例17: CreateProcess
private static extern bool CreateProcess(
[MarshalAs(UnmanagedType.LPTStr)]
string lpApplicationName,
string lpCommandLine,
IntPtr lpProcessAttributes,
IntPtr lpThreadAttributes,
bool bInheritHandles,
int dwCreationFlags,
IntPtr lpEnvironment,
[MarshalAs(UnmanagedType.LPTStr)]
string lpCurrentDirectory,
STARTUPINFO lpStartupInfo,
ref PROCESS_INFORMATION lpProcessInformation
);
开发者ID:Ricordanza,项目名称:poderosa,代码行数:14,代码来源:PipeCreator.cs
示例18: Execute
public override object Execute()
{
object result = null;
if (!this.HasRun)
{
Process process = null;
STARTUPINFO startupInfo = new STARTUPINFO();
PROCESS_INFORMATION processInfo = new PROCESS_INFORMATION();
Context.AnalysisOut.PersistVariables();
switch (option)
{
case CommandNames.DISPLAY:
bool created = CreateProcess(
null,
commandlineString,
IntPtr.Zero,
IntPtr.Zero,
false,
0,
IntPtr.Zero,
null,
ref startupInfo,
out processInfo);
if (created)
{
process = Process.GetProcessById((int)processInfo.dwProcessId);
}
else
{
throw new GeneralException("Could not execute the command: '" + commandlineString + "'");
}
break;
case CommandNames.TO:
break;
case "PRINT":
break;
}
this.HasRun = true;
}
return result;
}
开发者ID:NALSS,项目名称:epiinfo-82474,代码行数:48,代码来源:Rule_Report.cs
示例19: inject
public DLLInformation inject(string exePath, string dllPath)
{
DLLInformation d = new DLLInformation();
STARTUPINFO lpStartupInfo = new STARTUPINFO();
PROCESS_INFORMATION lpProcessInfo = new PROCESS_INFORMATION();
SECURITY_ATTRIBUTES lpSecurityAttributes1 = new SECURITY_ATTRIBUTES();
SECURITY_ATTRIBUTES lpSecurityAttributes2 = new SECURITY_ATTRIBUTES();
lpSecurityAttributes1.nLength = Marshal.SizeOf(lpSecurityAttributes1);
lpSecurityAttributes2.nLength = Marshal.SizeOf(lpSecurityAttributes2);
IntPtr hProcess;
CreateProcess(exePath, "", ref lpSecurityAttributes1, ref lpSecurityAttributes2, false, 0x0020, IntPtr.Zero, null, ref lpStartupInfo, out lpProcessInfo);
hProcess = OpenProcess((int)(0x000F0000L | 0x00100000L | 0xFFF), false, lpProcessInfo.dwProcessId);
d.ProcID = lpProcessInfo.dwProcessId;
d.ErrorCode = commonInject(hProcess, dllPath, ref d);
return d;
}
开发者ID:aevv,项目名称:aevvinject,代码行数:16,代码来源:Injector.cs
示例20: LaunchBatchFile
/// Launch a batch file.
/// This function calls CreateProcess directly, and ensures that
/// bInheritHandles=false, which prevents handle leakage into
/// child processes.
public static QRProcess LaunchBatchFile(
string batchFilePath,
string workingDir,
bool unicode,
string extraCmdCommandLine)
{
string systemPath = Environment.GetFolderPath(Environment.SpecialFolder.System);
string cmdPath = Path.Combine(systemPath, "cmd.exe");
StringBuilder commandline = new StringBuilder();
if (unicode) {
commandline.Append("/U ");
}
commandline.Append("/C "); // terminate after executing
commandline.AppendFormat("\"{0} {1}\" ",
batchFilePath,
String.IsNullOrEmpty(extraCmdCommandLine) ? "" : extraCmdCommandLine);
uint dwCreationFlags = CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS;
STARTUPINFO startupInfo = new STARTUPINFO();
startupInfo.cb = Marshal.SizeOf(startupInfo);
startupInfo.dwFlags = STARTF_USESHOWWINDOW;
startupInfo.wShowWindow = SW_HIDE;
PROCESS_INFORMATION processInfo;
bool success = CreateProcess(
cmdPath,
commandline,
null,
null,
/* bInheritHandles */ false,
dwCreationFlags,
IntPtr.Zero,
workingDir,
ref startupInfo,
out processInfo);
if (!success) {
int gle = Marshal.GetLastWin32Error();
return null;
}
QRProcess process = new QRProcess(processInfo);
return process;
}
开发者ID:fifoforlifo,项目名称:QRBuild,代码行数:50,代码来源:QRProcess.cs
注:本文中的STARTUPINFO类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论