广州凡科互联网科技有限公司

营业时间
MON-SAT 9:00-18:00

全国服务热线
18720358503

公司门店地址
广州市海珠区工业大道北67号凤凰创意园

Cmd跳转,跳转有哪些用

日期:2021-02-19 浏览:
Cmd跳转,跳转有哪些用
关注度1 评价 45  网民共享于:  :50 访问数44079次

Cmd跳转,跳转有哪些用

1、实行一条cmd指令

public static string mand)
 Process p = new Process();
 p.StartInfo.FileName = "cmd.exe";
 p.StartInfo.UseShellExecute = false; //是不是应用实际操作系统软件shell起动
 p.StartInfo.RedirectStandardInput = true;//接纳来源于启用程序的键入信息内容
 p.StartInfo.RedirectStandardOutput = true;//由启用程序获得輸出信息内容
 p.StartInfo.RedirectStandardError = true;//跳转规范不正确輸出
 p.StartInfo.CreateNoWindow = true;//无法显示程序对话框
 //p.StartInfo.Arguments = "/c " + command;///c意味着实行指令后关掉cmd.exe /k主要参数则不关掉
 p.Start();//起动程序
 //清除三行起动信息内容
 p.StandardOutput.ReadLine();
 p.StandardOutput.ReadLine();
 p.StandardOutput.ReadLine();
 //向cmd对话框推送键入信息内容
 p.mand);
 p.StandardInput.WriteLine("exit");
 string result = p.StandardOutput.ReadToEnd().Replace(Environment.CurrentDirectory, "");
 string error = p.StandardError.ReadToEnd();
 if (!string.IsNullOrWhiteSpace(error))
 result = result + "\r\n Error Message :\r\n" + error;
 p.WaitForExit();
 p.Close();
 return result;
}

2、一次实行好几条cmd指令

public static string ExecuteCmd(string[] commands)
 Process p = new Process();
 p.StartInfo.FileName = "cmd.exe";
 p.StartInfo.UseShellExecute = false; //是不是应用实际操作系统软件shell起动
 p.StartInfo.RedirectStandardInput = true;//接纳来源于启用程序的键入信息内容
 p.StartInfo.RedirectStandardOutput = true;//由启用程序获得輸出信息内容
 p.StartInfo.RedirectStandardError = true;//跳转规范不正确輸出
 p.StartInfo.CreateNoWindow = true;//无法显示程序对话框
 //p.StandardInput.AutoFlush = true;//每一次载入指令后更新,报未StandardInput未跳转
 //p.StartInfo.Arguments = "/c " + command;///c意味着实行指令后关掉cmd.exe /k主要参数则不关掉
 p.Start();//起动程序
 //清除三行起动信息内容
 p.StandardOutput.ReadLine();
 p.StandardOutput.ReadLine();
 p.StandardOutput.ReadLine();
 //向cmd对话框推送键入信息内容
 foreach (string mands)
 p.StandardInput.WriteLine(cmd);
 p.StandardInput.Flush();
 p.StandardInput.WriteLine("exit");
 string result = p.StandardOutput.ReadToEnd().Replace(Environment.CurrentDirectory, "");
 string error = p.StandardError.ReadToEnd();
 if (!string.IsNullOrWhiteSpace(error))
 result = result + "\r\n Error Message :\r\n" + error;
 p.WaitForExit();
 p.Close();
 return result;
}

3、运用cmd跳转申请注册DLL、建立服务、载入资格证书

public static string RegsvrFile(string filePath, bool reg = true, bool fileBit64 = false)
 string result;
 string[] commands = { "", "" };
 if (!fileBit64 Environment.Is64BitOperatingSystem)
 commands[0] = "cd /d %WinDir%\\SysWOW64";
 if (reg)
 commands[1] = "regsvr32 /s \"" + filePath + "\"";
 else
 commands[1] = "regsvr32 /u /s \"" + filePath + "\"";
 if (mands[0]))
 result = mands[1]);
 else
 result = mands);
 return result;
public static string ScCreate(string filePath, string serviceName, string displayName, string description, string start="auto", string depend=null)
 string result;
 string[] commands = { "", "" };
 if (string.IsNullOrWhiteSpace(depend))
 commands[0] = string.Format("sc create {0} binPath= \"{1}\" type= share start= {2} error= ignore DisplayName= \"{3}\"",
 serviceName, filePath, start, displayName);
 else
 commands[0] = string.Format("sc create {0} binPath= \"{1}\" type= share start= {2} error= ignore DisplayName= \"{3}\" depend= {4}",
 serviceName, filePath, start, displayName, depend);
 if (!string.IsNullOrWhiteSpace(description))
 commands[1] = string.Format("sc description {0} \"{1}\"", serviceName, description);
 if (mands[1]))
 result = mands[0]);
 else
 result = mands);
 return result;
public static string ScStart(string serviceName)
 mand = "net start " + serviceName;
 return mand);
public static string ScStop(string serviceName)
 mand = "net stop " + serviceName;
 return mand);
public static string ScDelete(string serviceName)
 string[] commands = { "net stop " + serviceName, "sc delete " + serviceName };
 return mands);
public static string CertFile(string filePath, bool install=true)
 string result;
 string[] commands = { "", "" };
 if (Environment.Is64BitOperatingSystem)
 commands[0] = "cd /d %WinDir%\\SysWOW64";
 if (install)
 commands[1] = "certutil -addstore root \"" + filePath + "\"";
 else
 commands[1] = "certutil -delstore root \"" + filePath + "\"";
 if (mands[0]))
 result = mands[1]);
 else
 result = mands);
 return result;
}

dengb.TechArticleCmd跳转,跳转有哪些用 1、实行一条cmd指令 public static string ExecuteCmd( mand){ Process p = new Process(); p.StartInfo.FileName = " cmd.exe " ; p.S...



网站知识

联系方式丨CONTACT

  • 全国热线:18720358503
  • 传真热线:18720358503
  • Q Q咨询:2639601583
  • 企业邮箱:2639601583@qq.com

首页
电话
短信
联系