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;
      }

      

  • 相关阅读:
    WordCount结对项目
    第一周作业:一些感想
    第一次作业
    Spring Cloud 微服务实战笔记
    解决jest处理es模块
    领域驱动设计(DDD:Domain-Driven Design)
    测试
    whistle
    日记(2018-11-07)
    ubuntu中使用机密数据Secrets
  • 原文地址:https://www.cnblogs.com/IclearByte/p/5941101.html
Copyright © 2011-2022 走看看