• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
wjshan0808

Learn from yesterday, Live for today, For a better tomorrow.
 ————wjshan0808

博客园    首页    新随笔    联系   管理    订阅  订阅

cmd

            Process p = new Process();//创建进程对象
            string drivename = cboDrive.Text;//盘符
            string shareName = txtShareName.Text;//共享名
            string sharePath = txtShareDisk.Text;//共享路径
            p.StartInfo.FileName = "cmd";//启动进程名称
            //磁盘格式转换
            //p.StartInfo.Arguments = "/c convert " + drivename + "/fs:ntfs";//执行的命令
            //设置共享
            p.StartInfo.Arguments = " /c net share " + shareName + "=" + sharePath;//执行的命令
            p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;//窗口状态为隐藏
            p.StartInfo.CreateNoWindow = true;//启动进程不创建窗口
            p.StartInfo.UseShellExecute = false;//从可执行文件创建进程
            p.StartInfo.RedirectStandardOutput = true;//将输出写入流中                
            p.Start();//启动进程
            p.WaitForExit(); 
 Process p = new Process();//创建进程对象
            p.StartInfo.FileName = "cmd.exe";//启动进程名称
            ///System.Environment.UserName    当前登录用户
            p.StartInfo.Arguments = "/c net localgroup administrators |find \"%username%\"";//执行的命令
            p.StartInfo.UseShellExecute = false;//从可执行文件创建进程
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;//窗口状态为隐藏
            p.Start();//启动进程
            return p.StandardOutput.ReadToEnd();
 ProcessStartInfo ps = new ProcessStartInfo();//实例化
            ps.FileName = "shutdown.exe";//执行的命令名
            ps.Arguments = "-r -t 1";// 重启计算机
 ps.Arguments = "-s -t 1";//关闭计算机
            ps.CreateNoWindow = true;
            ps.RedirectStandardError = true;
            ps.RedirectStandardInput = true;
            ps.RedirectStandardOutput = true;
            Process.Start(ps);//启动进程

 


posted @ 2015-01-19 14:17  wjshan0808  阅读(171)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3