C#中的appcmd代码? [英] appcmd code in C#?

查看:85
本文介绍了C#中的appcmd代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行如下的Web服务:

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();

bat文件具有:

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

如果我在服务器上的localhost上运行,则可以正常工作.但是,如果我通过Web服务在服务器上运行它,则会失败.

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.

我可以用纯C#代码实现与appcmd相同的功能吗?

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

编辑

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

推荐答案

我通过直接从c#调用appcmd进行了类似的操作.使我的情况适应原始问题,代码将是:

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\"
    });

这篇关于C#中的appcmd代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆