本文整理汇总了C#中System.Diagnostics.Process类的典型用法代码示例。如果您正苦于以下问题:C# Process类的具体用法?C# Process怎么用?C# Process使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Process类属于System.Diagnostics命名空间,在下文中一共展示了Process类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: cmd
public String cmd(String cnd)
{
cnd = cnd.Trim();
String output = " ";
Console.WriteLine(cnd);
if ((cnd.Substring(0, 3).ToLower() == "cd_") && (cnd.Length > 2))
{
if (System.IO.Directory.Exists(cnd.Substring(2).Trim()))
cpath = cnd.Substring(2).Trim();
}
else
{
cnd = cnd.Insert(0, "/B /c ");
Process p = new Process();
p.StartInfo.WorkingDirectory = cpath;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = cnd;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
output = p.StandardOutput.ReadToEnd(); // output of cmd
output = (output.Length == 0) ? " " : output;
p.WaitForExit();
}
return output;
} // end cmd
开发者ID:TheBugMaker,项目名称:Payload-Client,代码行数:32,代码来源:Tools.cs
示例2: Runcmd
public string Runcmd()
{
Process myProcess = new Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.RedirectStandardOutput = true;
try
{
myProcess.Start();
}
catch (Exception)
{
throw;
}
try
{
foreach (var item in Cmds)
{
myProcess.StandardInput.WriteLine(item);
}
}
catch (Exception)
{
throw;
}
myProcess.StandardInput.WriteLine("exit");
return myProcess.StandardOutput.ReadToEnd();
}
开发者ID:SaintLoong,项目名称:RemoteControl,代码行数:34,代码来源:Dos.cs
示例3: generateKeypair
/// <summary>
/// Generate a keypair
/// </summary>
public static void generateKeypair()
{
// We need both, the Public and Private Key
// Public Key to send to Gitlab
// Private Key to connect to Gitlab later
if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\.ssh\id_rsa.pub") &&
File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\.ssh\id_rsa"))
{
return;
}
try {
Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\.ssh");
} catch (Exception) {}
Process p = new Process();
p.StartInfo.FileName = "ssh-keygen";
p.StartInfo.Arguments = "-t rsa -f \"" + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\.ssh\\id_rsa\" -N \"\"";
p.Start();
Console.WriteLine();
Console.WriteLine("Waiting for SSH Key to be generated ...");
p.WaitForExit();
while (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\.ssh\id_rsa.pub") &&
!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\.ssh\id_rsa"))
{
Thread.Sleep(1000);
}
Console.WriteLine("SSH Key generated successfully!");
}
开发者ID:Xarlot,项目名称:gitlab-ci-runner-win,代码行数:31,代码来源:SSHKey.cs
示例4: Snes
public Snes()
{
mProcess = SearchProcess("snes9x.exe");
mProcessPtr = OpenProcess(ProcessAccessFlags.PROCESS_VM_READ, false, mProcess.Id);
updateMemory();
}
开发者ID:nicklegr,项目名称:ShirenHUD,代码行数:7,代码来源:Snes.cs
示例5: B_start_Click
private void B_start_Click(object sender, EventArgs e)
{
AccountCacher = new Process();
AccountCacher.StartInfo.FileName = "AccountCacher.exe";
AccountCacher.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
AccountCacher.Start();
Thread.Sleep(500);
LauncherServer = new Process();
LauncherServer.StartInfo.FileName = "LauncherServer.exe";
LauncherServer.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
LauncherServer.Start();
Thread.Sleep(500);
LobbyServer = new Process();
LobbyServer.StartInfo.FileName = "LobbyServer.exe";
LobbyServer.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
LobbyServer.Start();
Thread.Sleep(500);
WorldServer = new Process();
WorldServer.StartInfo.FileName = "WorldServer.exe";
WorldServer.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
WorldServer.Start();
}
开发者ID:Necrosummon,项目名称:WarEmu,代码行数:28,代码来源:Form1.cs
示例6: GetThumbnailFromProcess
private MemoryStream GetThumbnailFromProcess(Process p, ref int width, ref int height)
{
Debug("Starting ffmpeg");
using (var thumb = new MemoryStream()) {
var pump = new StreamPump(p.StandardOutput.BaseStream, thumb, null, 4096);
if (!p.WaitForExit(20000)) {
p.Kill();
throw new ArgumentException("ffmpeg timed out");
}
if (p.ExitCode != 0) {
throw new ArgumentException("ffmpeg does not understand the stream");
}
Debug("Done ffmpeg");
if (!pump.Wait(2000)) {
throw new ArgumentException("stream reading timed out");
}
if (thumb.Length == 0) {
throw new ArgumentException("ffmpeg did not produce a result");
}
using (var img = Image.FromStream(thumb)) {
using (var scaled = ThumbnailMaker.ResizeImage(img, ref width, ref height)) {
var rv = new MemoryStream();
try {
scaled.Save(rv, ImageFormat.Jpeg);
return rv;
}
catch (Exception) {
rv.Dispose();
throw;
}
}
}
}
}
开发者ID:renanxr3,项目名称:simpleDLNA,代码行数:35,代码来源:VideoThumbnails.cs
示例7: ProcessInfo
private Dictionary<int, ThreadInfo> processThreads; //has relating thread id to its threadInfo object
#endregion Fields
#region Constructors
/// <summary>
/// Constructor for ProcessInfo
/// </summary>
/// <param name="procID">The id of the process</param>
/// <param name="debugger">The debugger</param>
public ProcessInfo(Process process, CorDebugger debug)
{
if (debug == null)
{
throw new ArgumentException("Null Debugger Exception");
}
processThreads = new Dictionary<int, ThreadInfo>();
processCorThreads = new List<CorThread>();
generalThreadInfos = new Dictionary<int, ProcessThread>();
attachedCompletedProcessEvent = new ManualResetEvent(false);
debugger = debug;
processId = process.Id;
generalProcessInfo = Process.GetProcessById(processId);
//CorPublish cp = new CorPublish();
//cpp = cp.GetProcess(processId);
processFullName = process.MainModule.FileName;
processShortName = System.IO.Path.GetFileName(process.MainModule.FileName);
FileVersionInfo fileInfo = FileVersionInfo.GetVersionInfo(processFullName);
description = fileInfo.FileDescription;
company = fileInfo.CompanyName;
//debuggerProcessInfo will be set when the updateInfo function is called
//the reason for this is that the process must be stopped for this to take place
//this happen only when we want it to
}
开发者ID:artisticcheese,项目名称:MSE,代码行数:39,代码来源:ProcessInfo.cs
示例8: AbortedShutdown
internal void AbortedShutdown()
{
if(_ShutdownProcess != null && !_ShutdownProcess.HasExited)
_ShutdownProcess.Kill();
_ShutdownProcess = null;
_Main.StopTimer();
}
开发者ID:CapCalamity,项目名称:ShutdownManager,代码行数:7,代码来源:Controller.cs
示例9: AddSimpleRectoSvn
public static void AddSimpleRectoSvn(string inputDir)
{
try {
Process p = new Process();
p.StartInfo.FileName = "svn";
p.StartInfo.Arguments = "add -N " + inputDir + @"\*";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = false;
p.Start();
string output = p.StartInfo.Arguments + "\r\n";
output = output + p.StandardOutput.ReadToEnd();
p.WaitForExit();
p = new Process();
p.StartInfo.FileName = "svn";
p.StartInfo.Arguments = "commit " + inputDir + "\\* -m\"addedFiles\"";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.WaitForExit();
} catch (Exception ex) {
MessageBox.Show(ex.Message, "SVN checkout issue");
}
}
开发者ID:mzkabbani,项目名称:cSharpProjects,代码行数:27,代码来源:CommonUtils.cs
示例10: StartSteamAccount
public bool StartSteamAccount(SteamAccount a)
{
bool finished = false;
if(IsSteamRunning())
{
KillSteam();
}
while (finished == false)
{
if (IsSteamRunning() == false)
{
Process p = new Process();
if (File.Exists(installDir))
{
p.StartInfo = new ProcessStartInfo(installDir, a.getStartParameters());
p.Start();
finished = true;
return true;
}
}
}
return false;
}
开发者ID:Trontor,项目名称:SteamAccountSwitcher,代码行数:25,代码来源:Steam.cs
示例11: BuildPSAttack
public static int BuildPSAttack(Attack attack, GeneratedStrings generatedStrings)
{
//DateTime now = DateTime.Now;
//string buildDate = String.Format("{0:MMMM dd yyyy} at {0:hh:mm:ss tt}", now);
//using (StreamWriter buildDateFile = new StreamWriter(Path.Combine(attack.resources_dir, "attackDate.txt")))
//{
// buildDateFile.Write(buildDate);
//}
string dotNetDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
string msbuildPath = Path.Combine(dotNetDir, "msbuild.exe");
if (File.Exists(msbuildPath))
{
Process msbuild = new Process();
msbuild.StartInfo.FileName = msbuildPath;
msbuild.StartInfo.Arguments = attack.build_args(Path.Combine(Strings.obfuscatedSourceDir, generatedStrings.Store["psaReplacement"] + ".sln"));
msbuild.StartInfo.UseShellExecute = false;
msbuild.StartInfo.RedirectStandardOutput = true;
msbuild.StartInfo.RedirectStandardError = true;
Console.WriteLine("Running build with this command: {0} {1}", msbuild.StartInfo.FileName, msbuild.StartInfo.Arguments);
msbuild.Start();
string output = msbuild.StandardOutput.ReadToEnd();
Console.WriteLine(output);
string err = msbuild.StandardError.ReadToEnd();
Console.WriteLine(err);
msbuild.WaitForExit();
int exitCode = msbuild.ExitCode;
msbuild.Close();
return exitCode;
}
return 999;
}
开发者ID:jaredhaight,项目名称:PSAttackBuildTool,代码行数:33,代码来源:PSABTUtils.cs
示例12: ayudaToolStripMenuItem_Click
private void ayudaToolStripMenuItem_Click(object sender, EventArgs e)
{
Process pr = new Process();
pr.StartInfo.WorkingDirectory = @"C:\Users\Wilfredo\Desktop\admin\admin\admin";
pr.StartInfo.FileName = "SofTool Systems help.htm";
pr.Start();
}
开发者ID:walter016,项目名称:dise2015,代码行数:7,代码来源:frmmenuPrincipal.cs
示例13: aa
public void aa()
{
//实例化一个进程类
cmd = new Process();
//获得系统信息,使用的是 systeminfo.exe 这个控制台程序
cmd.StartInfo.FileName = "cmd.exe";
//将cmd的标准输入和输出全部重定向到.NET的程序里
cmd.StartInfo.UseShellExecute = false; //此处必须为false否则引发异常
cmd.StartInfo.RedirectStandardInput = true; //标准输入
cmd.StartInfo.RedirectStandardOutput = true; //标准输出
cmd.StartInfo.RedirectStandardError = true;
//不显示命令行窗口界面
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmd.Start(); //启动进程
cmd.StandardInput.WriteLine("jdf b");
//cmd.StandardInput.WriteLine("exit");
//获取输出
//需要说明的:此处是指明开始获取,要获取的内容,
//<span style="color: #FF0000;">只有等进程退出后才能真正拿到</span>
//cmd.WaitForExit();//等待控制台程序执行完成
//cmd.Close();//关闭该进程
Thread oThread1 = new Thread(new ThreadStart(bb));
oThread1.Start();
}
开发者ID:xuzhe0211,项目名称:jdf,代码行数:34,代码来源:Form2.cs
示例14: _load
private void _load(Process proc) {
File = new FileInfo(ProcessExecutablePath(proc));
Name = proc.ProcessName;
Id = proc.Id;
Thread = new Thread(Monitor);
Thread.Start(this);
}
开发者ID:Nucs,项目名称:nlib,代码行数:7,代码来源:ProcessRestartMonitor.cs
示例15: tcpRouteStart
void tcpRouteStart()
{
tcpRoute = new Process();
tcpRoute.StartInfo.FileName = "TcpRoute2.exe";
tcpRoute.StartInfo.WorkingDirectory = ".";
tcpRoute.StartInfo.Arguments = "";
tcpRoute.StartInfo.CreateNoWindow = true;
// tcpRoute.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
tcpRoute.StartInfo.UseShellExecute = false;
tcpRoute.StartInfo.RedirectStandardOutput = true;
tcpRoute.StartInfo.StandardOutputEncoding = Encoding.UTF8;
tcpRoute.StartInfo.StandardErrorEncoding = Encoding.UTF8;
tcpRoute.StartInfo.RedirectStandardError = true;
// 注册关闭事件
tcpRoute.EnableRaisingEvents = true;
tcpRoute.SynchronizingObject = this;
tcpRoute.Exited += new EventHandler(TcpRouteExit);
tcpRoute.OutputDataReceived += new DataReceivedEventHandler(process1_ErrorDataReceived);
tcpRoute.ErrorDataReceived += new DataReceivedEventHandler(process1_ErrorDataReceived);
tcpRoute.Start();
tcpRoute.BeginOutputReadLine();
tcpRoute.BeginErrorReadLine();
// tcpRoute.WaitForExit();
}
开发者ID:wxhzk,项目名称:TcpRoute2,代码行数:30,代码来源:Form1.cs
示例16: ExecuteSync
public void ExecuteSync(string fileName, string arguments, string workingDirectory)
{
if (string.IsNullOrWhiteSpace(fileName))
throw new ArgumentException("fileName");
var process = new Process {
StartInfo = {
FileName = fileName,
Arguments = arguments,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
WorkingDirectory = workingDirectory
},
};
process.OutputDataReceived += Process_OutputDataReceived;
process.ErrorDataReceived += Process_ErrorDataReceived;
process.Exited += Process_Exited;
try {
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
} catch (Win32Exception) {
throw new ExecuteFileNotFoundException(fileName);
}
}
开发者ID:samukce,项目名称:migrate-from-svn-to-git,代码行数:32,代码来源:ProcessCaller.cs
示例17: RunProcess
private string RunProcess(string commandName, string arguments, bool useShell)
{
System.Windows.Forms.Cursor oldCursor = System.Windows.Forms.Cursor.Current;
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
Process p = new Process();
p.StartInfo.CreateNoWindow = !useShell;
p.StartInfo.UseShellExecute = useShell;
p.StartInfo.Arguments = arguments;
p.StartInfo.RedirectStandardOutput = !useShell;
p.StartInfo.RedirectStandardError = !useShell;
p.StartInfo.FileName = commandName;
p.Start();
if(!useShell)
{
string output = p.StandardOutput.ReadToEnd();
string error = p.StandardError.ReadToEnd();
p.WaitForExit();
WriteToConsole(error);
WriteToConsole(output);
System.Windows.Forms.Cursor.Current = oldCursor;
return output;
}
return "";
}
开发者ID:sillsdev,项目名称:WorldPad,代码行数:25,代码来源:PerforceUtils.cs
示例18: Main
static void Main(string[] args)
{
List<string> start_for = new List<string>();
start_for.Add(@"C:\\xampp\\mysql\\bin\\mysqld.exe");//mysql路徑
start_for.Add(@"C:\\xampp\\apache\\bin\\httpd.exe");//apache路徑
start_for.Add("netsh wlan stop hostednetwork");//wifi stop
start_for.Add("netsh wlan set hostednetwork mode=allow ssid=Apple-steven-wifi key=0000000000123");//wifi set
start_for.Add("netsh wlan start hostednetwork");//cmd 指令
//Process p = new Process();
//p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
int i = 0;
foreach (string C_val in start_for)
{
Process SomeProgram = new Process();
SomeProgram.StartInfo.FileName = (i == 2 || i == 3 || i == 4) ? "cmd.exe" : C_val;
SomeProgram.StartInfo.Arguments = @"/c " + C_val;
//p.StartInfo.Arguments = "/c " + command;
SomeProgram.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;//不要有視窗
SomeProgram.Start();
i++;
}
}
开发者ID:seven2966,项目名称:data,代码行数:26,代码来源:Program.cs
示例19: ExecuteUtilityAsync
void ExecuteUtilityAsync(string args, Action<string> parseOutput, Action onComplete)
{
Process p = new Process();
p.StartInfo.FileName = Utility;
p.StartInfo.Arguments = args;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
var t = new Thread( _ =>
{
using (var reader = p.StandardOutput)
{
// This is wrong, chrisf knows why
while (!p.HasExited)
{
string s = reader.ReadLine();
if (string.IsNullOrEmpty(s)) continue;
parseOutput(s);
}
}
onComplete();
}) { IsBackground = true };
t.Start();
}
开发者ID:djohe,项目名称:OpenRA,代码行数:26,代码来源:Utilities.cs
示例20: Button1Click
void Button1Click(object sender, EventArgs e)
{
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(@"C:\Users\IJMAIL\AppData\Roaming\Nox\bin\nox_adb.exe" );
myProcessStartInfo.Arguments = "devices";
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true; // 데이터 받기
myProcessStartInfo.RedirectStandardError = true; // 오류내용 받기
myProcessStartInfo.CreateNoWindow = true; // 원도우창 띄우기(true 띄우지 않기, false 띄우기)
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
myProcess.WaitForExit();
//string output = myProcess.StandardOutput.ReadToEnd();
string output = myProcess.StandardOutput.ReadToEnd();
string error = myProcess.StandardError.ReadToEnd();
string[] aa = output.Split('\n');
for(int i=1; i<aa.Length; i++) {
listBox1.Items.Add(aa[i]);
}
//listBox1.Items.Add(aa.Length);
//listBox1.Items.Add(aa[1]);
//listBox1.Text = output;
// 프로그램이 종료되면
//System.Console.WriteLine( "ExitCode is " + myProcess.ExitCode );
myProcess.WaitForExit();
myProcess.Close();
}
开发者ID:eunsebi,项目名称:Cshap,代码行数:34,代码来源:MainForm.cs
注:本文中的System.Diagnostics.Process类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论