/// <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("写入成功");
}
}
}

执行CMD代码的更多相关文章

  1. Windows使用Java执行cmd代码

    话不多说,直入正题 今天给大家分享下,怎么在Windows上使用Java执行Cmd代码! 首先默认大家都熟悉cmd代码,以及cmd的命令行操作. 直接在main方法中写这一行(需要抛出异常),可以直接 ...

  2. java调用执行cmd指令启动weblogic

    这里的例子是启动weblogic import java.io.BufferedReader; import java.io.IOException; import java.io.InputStre ...

  3. AJPFX编写cmd界面下一键编译、执行java代码的bat脚本

    此脚本适合刚接触java的同学,在cmd界面下用jc取代 复杂的  javac *.java + java main使用说明:把脚本内容复制到txt文本中,修改后缀名为.bat,运行一次即可完成配置, ...

  4. [转]Delphi执行CMD命令

    今天看到有人在问用代码执行CMD命令的问题,就总结一下用法,也算做个备忘. Delphi中,执行命令或者运行一个程序有2个函数,一个是winexec,一个是shellexecute.这两个大家应该都见 ...

  5. C#隐式执行CMD命令

    本文实现C#隐式执行CMD功能命令.下图是示例程序的主界面. 在命令文本框输入DOS命令,点击"Run"button.在以下的文本框中输出执行结果. 以下是程序的完整代码. 本程序 ...

  6. 005dayPython学习:编写并执行Pythong代码和流程梳理

    一.创建 python 文件 PS:文件路径和文件名尽量不要包含中文! 二.编写python代码 1.头部的特殊两行 #!/usr/bin/env python # -*- coding:utf-8 ...

  7. 在 Linux/windows下 命令行中使用和执行 PHP 代码[交互式php]

    [注释]在ubuntu下,升级php到7.1版本,虽然提示的是Interactive mode enabled, 但实际上可以直接书写命令,和interactive shell效果一样. 一:wind ...

  8. 如何使用Java执行cmd命令

    用JAVA代码实现执行CMD命令的方法! Runtime rt = Runtime.getRuntime(); Process p = rt.exec(String[] cmdarray);     ...

  9. C#执行CMD命令并接收返回结果的实现方法

    using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using ...

随机推荐

  1. poj 3287 The Trip, 2007_贪心

    题意:把一个包放入另一个包内,使得总共要带的件数最少,就是说大包可以装小包,且一个大包只能装一个小包,但是这个小包可以继续装更小的包. 思路:因为相同大小的包不能互相装,所以最小数量就是有相同尺寸的包 ...

  2. magento url rewrite

    Magento 设置 Rewrite Url 方法. 1.apache 要加载 Rewrite 扩展模块.2.网站根目录要有 .htaccess 文件.3.Magento 后台要设置启用 Rewrit ...

  3. IOS开发之——获取屏幕的尺寸及各模拟器代表的型号

    获取屏幕尺寸 [[[UIScreen mainScreen] currentMode].size.width]; [[[UIScreen mainScreen] currentMode].size.h ...

  4. The 5th tip of DB Query Analyzer

    The 5th tip of DB Query Analyzer             Ma Genfeng   (Guangdong UnitollServices incorporated, G ...

  5. 手机端页面自适应:rem布局

    rem布局非常简单,首页你只需在页面引入这段原生js代码就可以了 (function (doc, win) { var docEl = doc.documentElement, resizeEvt = ...

  6. 【奇偶剪枝】【HDU1010】Tempter of the Bone

    题意:输入一个n*m的迷宫,和一个T:可以在迷宫中生存的最大时间.S为起点,D为终点.并且,每个格子只能踩一次,且只能维持一秒,然后该块地板就会塌陷.所以你必须每秒走一步,且到D点时,所用时间为T. ...

  7. C# MySQL数据库的备份 还原 初始化

    // 执行创建数据库操作 this.GetExecute(G_Con, "create database if not exists NEWDB"); this.sqlAddres ...

  8. EXT.NET常用属性

    Ext_数字输入框_Ext.form.NumberField:   <mce:script type="text/javascript"><!-- /* Ext. ...

  9. WampServer2.5的XDebug调试不成功的原因

    WampServer2.5的php.ini文件位置很奇妙,除了在“wamp\bin\php\php5.5.12”目录下有一个外,“wamp\bin\apache\apache2.4.9\bin”目录下 ...

  10. golang Aes

    package models import ( "bytes" "crypto/aes" "crypto/cipher" "err ...