问题
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