zoukankan      html  css  js  c++  java
  • C# Process类在程序中实现以管理员方式运行外部进程运行

      因为项目中需要使用BCP命令导出数据库中数据,然后将导出结果的统计信息输出到文本中,但是bcp命令对文件夹的操作权限不足,所以就用到了Process类以管理员的身份运行BCP控制台程序,直接上代码:

      Process p = new Process();

      try
      {
        p.StartInfo.FileName = "bcp.exe";
        p.StartInfo.RedirectStandardInput = true;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.RedirectStandardError = true;
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.Verb = "RunAs";
        p.StartInfo.UseShellExecute = false;
        //@必须加上,不然特殊字符会被自动过滤掉
        p.StartInfo.Arguments = sql;
        p.Start();
        p.WaitForExit();
        p.Close();
      }
      catch (Exception e)
      {
        log.writeLog_DB("失败020", sql + "||||||" + e.Message.ToString());
        return false;
      }

      

  • 相关阅读:
    JVM原理---------------1.开篇
    mysql开启事务的方式,命令学习
    mysql中的锁
    mysql索引底层原理
    mysql的常见存储引擎与常见日志类型,以及4种线程的作用
    Mutex
    委托和匿名委托
    线程通信
    同步锁
    [ValidateInput(false)]
  • 原文地址:https://www.cnblogs.com/IclearByte/p/5941101.html
Copyright © 2011-2022 走看看