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

      

  • 相关阅读:
    python之打开python源文件方法
    python学习网站
    python知识点
    计算机概念--鸭子类型
    装饰器、函数调用 语句分析法
    python相关软件安装
    python之字典的作用
    [转载]理解HTML语义化
    Java 入门 代码2浮点数据类型
    Java入门1dayCode
  • 原文地址:https://www.cnblogs.com/IclearByte/p/5941101.html
Copyright © 2011-2022 走看看