appcmd code in C#?

余生长醉 提交于 2019-12-25 12:27:07

问题


I have an web service that run's this:

 var Proc = new Process();
                Proc.StartInfo.FileName = CredentialBatFile;
                Proc.StartInfo.Arguments = WebSiteName + " " + Apppool_Username 
                                                    + " " + Apppool_Password;
                Proc.Start();

The bat file has:

C:\Windows\system32\inetsrv\appcmd.exe set site "%1" 
              -virtualDirectoryDefaults.userName:%2 
              -virtualDirectoryDefaults.password:%3

If I run on localhost (on the server) it works fine. however if I run it on the server from the web service it fails.

Can I achieve the same function as appcmd in pure C# code?

EDIT

Exception: Unknown error (0xfffffffe) StackTrace: at    
System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) 

回答1:


I did something similar by calling the appcmd directly from c#. Adapting my case into the original question the code would be:

System.Diagnostics.Process.Start(
    new System.Diagnostics.ProcessStartInfo
    {
        Arguments = "set site \""+ WebSiteName + "\" -virtualDirectoryDefaults.userName:"+ Apppool_Username + " -virtualDirectoryDefaults.password:"+ Apppool_Password,
        FileName = "appcmd.exe",
        WorkingDirectory = @"c:\windows\system32\inetsrv\"
    });



回答2:


Looks like you can. Check out this example code.



来源:https://stackoverflow.com/questions/8584603/appcmd-code-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!