在Windows 2012 64位上,process.startInfo失败

时间:2014-04-10 19:04:11

标签: c# iis windows-server-2012 process.start

我有一个小应用程序来使用Process.StartInfo配置IIS。该应用程序在Windows 2008 R2 64位和所有32位计算机上运行良好。即使我使用Runas,我也没有看到很多不同之处。该应用程序在框中以本地管理员身份运行。

代码在

之下

命名空间ConsoleApplication1 {

class Program
{
    private const string configIISParameters2012 = "/k START /w C:\\Windows\\SysNative\\PKGMGR.EXE /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;
    private const string exeCommand = "CMD.EXE";
    static void Main()
    {
        RunCommand(exeCommand, configIISParameters2012);          
    }

    public static bool RunCommand(String command, String arguments)
    {
        bool ret = false;
        try
        {

            System.Diagnostics.Process process = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.CreateNoWindow = true;
            startInfo.Verb = "unas";

            startInfo.FileName = command;
            startInfo.Arguments = arguments;
            process.StartInfo = startInfo;
            process.StartInfo.UseShellExecute = true;
            process.EnableRaisingEvents = true;

            process.Start();
            process.WaitForExit();

            process.Close();
            ret = true;
        }
        catch (Exception ex)
        {
            //Utility.Log("Exception executing command :" + ex.StackTrace);
        }
        return ret;
    }

0 个答案:

没有答案