执行CMD代码

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
/// <summary>
/// 发送CMD命令(执行命令行)
/// </summary>
public static void SendCMD(string pwd)
{
string route = ConfigurationManager.AppSettings["Rout"];
try
{
var _p = new Process();
//Process类有一个StartInfo属性,这是ProcessStartInfo类,包括了一些属性和方法
_p.StartInfo.FileName = "cmd.exe"; //执行的命令及参数 //_p.StartInfo.Arguments = "/c " + " net user zwsc " + pwd; _p.StartInfo.Arguments = "/c " + " net user " + ConfigurationManager.AppSettings["userName"] + " " + pwd; _p.StartInfo.UseShellExecute = false; //关闭Shell的使用 _p.StartInfo.RedirectStandardInput = true; _p.StartInfo.RedirectStandardOutput = true; _p.StartInfo.RedirectStandardError = true;
_p.StartInfo.CreateNoWindow = true;//设置不显示窗口 _p.Start(); //启动进程 string _standardOutput = _p.StandardOutput.ReadToEnd();
string _errorOutput = _p.StandardError.ReadToEnd();
string[] _message = { _standardOutput, _errorOutput };
_p.WaitForExit();
}
catch (Exception ex)
{
string file = route + DateTime.Now.ToString("yyyyMMddhhmmss") + ".txt";
string content = ex.Message;
if (File.Exists(file))
{
//MessageBox.Show("存在此文件!");
FileStream myFs = new FileStream(file, FileMode.Open);
StreamWriter mySw = new StreamWriter(myFs);
mySw.Write(content);
mySw.Close();
myFs.Close();
}
else
{
FileStream myFs = new FileStream(file, FileMode.Create);
StreamWriter mySw = new StreamWriter(myFs);
mySw.Write(content);
mySw.Close();
myFs.Close();
//MessageBox.Show("写入成功");
}
}
}
阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

“执行CMD代码” 的相关文章

thinkphp实现分页功能的方法是什么 - 编程语言

这篇文章主要介绍“thinkphp实现分页功能的方法是什么”,在日常操作中,相信很多人在thinkphp实现分页功能的方法是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”thinkphp实现分页功能的方法是什么”的疑惑有所帮助!接下...

怎么使用Python制作一个极简四则运算解释器 - 开发技术

本篇内容主要讲解“怎么使用Python制作一个极简四则运算解释器”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么使用Python制作一个极简四则运算解释器”吧!计算功能演示这里先展示了程序的帮助信息,然后是几个简单的四则...

controller函数中参数列表怎么使用多个@RequestBody - 开发技术

这篇文章主要介绍“controller函数中参数列表怎么使用多个@RequestBody”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“controller函数中参数列表怎么使用多个@RequestBody”文章能帮助大家解决问...

枚举转char

#define NAME(value) #value...

重要概念之函数式编程

什么是函数式编程?函数式编程(Functional Programming, FP)就是利用纯函数实现细粒度的函数,然后再通过函数的组合把细粒度的函数组合成功能更强大的函数。函数式编程中的 "函数" 不是程序中的函数(方法),而是数学中的函数(映射关系),例如 y=sin(x) 中 x 和 y 的关...

php如何实现IP地址和整数的转换 - 编程语言

今天小编给大家分享一下php如何实现IP地址和整数的转换的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。 IP地址是计算机互联...