VPN远程服务器的启动/停止窗口服务

时间:2011-11-24 08:36:57

标签: c# .net winforms

我尝试启动/停止VPN远程服务器的窗口服务,但没有运气。

现在我可以使用我的PC在同一个域上启动/停止远程服务器的窗口服务器,如Start A Remote Service From C#中所述。

我尝试使用这种方法:http://www.eggheadcafe.com/community/csharp/2/15950/windows-services--remote-machine.aspx但它会抛出异常WSANO_DATA - 11004 when getting the host name(在行:String hostName = Dns.GetHostEntry(_Server).HostName;)。

示例代码(.NET 4.0)

ConnectionOptions cred = new ConnectionOptions();

cred.Username = _UsrNm;

cred.Password = _Pass;

String hostName = Dns.GetHostEntry(_Server).HostName;

ManagementScope srvScope;

srvScope = new ManagementScope(string.Format("\\\\{0}\\root\\cimv2", hostName), cred);

ManagementPath win32Path = new ManagementPath("Win32_Service");

ManagementClass services;

services = new ManagementClass(srvScope, win32Path, null);

如果有的话,请给我你的意见或建议。

韩国社交协会

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

我尝试使用Impersonate,如本文所述:http://www.codeproject.com/KB/cs/cpimpersonation1.aspx,使用登录类型= LOGON32_LOGON_NEW_CREDENTIALS和登录提供程序= LOGON32_WINNT50,它适用于我(通过安装在远程服务器中的VPN和窗口服务器2008)。 / p>