1

如何有问题地运行 aspnet_regiis 命令

我希望此代码以编程方式在 C# 代码中运行

aspnet_regiis.exe -pdf "连接字符串" "C:\Users\99xccba\Desktop\连接字符串\DNN"

4

2 回答 2

1

非常简单的任务

主要方法

        /// <summary>
    /// Method to run windows process
    /// </summary>
    /// <param name="processName">Process Name</param>
    /// <param name="arguments">Arguments </param>
    private void RunProcess(string processName, string arguments)
    {
        var newProcess = new ProcessStartInfo(processName);
        Log("User: " + GetSystemName());

        if (arguments.IsNotNullOrEmpty())
            newProcess.Arguments = arguments;
        newProcess.CreateNoWindow = false;
        newProcess.ErrorDialog = true;
        newProcess.RedirectStandardError = true;
        newProcess.RedirectStandardInput = true;
        newProcess.RedirectStandardOutput = true;
        newProcess.UseShellExecute = false;
        using (var proc = new Process())
        {
            proc.StartInfo = newProcess;
            proc.Start();
            Log(proc.StandardOutput.ReadToEnd());
        }
    }

调用该方法的过程

string framework = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe";

                if (8 == IntPtr.Size
                    || (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
                    framework = @"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe";


                RunProcess(framework, "-ga " + GetSystemName());
于 2012-12-06T04:44:04.353 回答
-1
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "dir";
process.Start();

确保您声明了正确的路径。然后用您自己的命令替换 Arguments。或者您可以创建一个设置了路径的批处理文件并执行它。

于 2012-12-06T04:41:51.650 回答