如何让Cers中的模拟正常运行? [英] How do I get Impersonation to work correctly in C#?

查看:66
本文介绍了如何让Cers中的模拟正常运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在C#中编写一个程序来访问另一台服务器,以便我可以看到某个特定服务是否正在运行。我有权使用相关服务器并通过RDP和Windows资源管理器完成此操作。当我尝试在代码中执行此操作时,我能够连接到服务器但是当我尝试访问服务时,我收到以下消息:无法在计算机上打开服务控制管理器'XSERVER2'。此操作可能需要其他权限。



任何人都可以提供此帮助吗? Google搜索未被证明有用。提前谢谢。



代码示例:

  private   void  test1()
{
ConnectionOptions options = new ConnectionOptions();
options.Password = MyPassword;
options.Username = John.Doe;
options.Authority = ntlmdomain:EXTREMEWORKS;
options.EnablePrivileges = true ;
options.Impersonation =
System.Management.ImpersonationLevel.Impersonate;

ManagementScope范围=
ManagementScope(
\\\\XSERVER2 \\root \\cimv2,options);
scope.Connect();


ServiceController sc = new ServiceController( ServiceToCheck XSERVER2);
MessageBox.Show( Status = + sc.Status.ToString());
// sc.Start();
}



我毫无问题地进入MessageBox。我在Messagebox行上收到错误。我想我已经确定我实际上是通过输入无效的用户名/密码登录到服务器而且它不会连接。

解决方案

你真的有服务吗?叫做ServiceToCheck在XSERVER2上运行?????



通常在测试时我会选择Spooler或更平凡的东西。



您可以通过手动检查您是否可以访问该服务



控制面板 - > ;管理工具 - >服务



打开操作菜单....连接到另一台计算机...以用户身份登录,看看是否可以看到该服务

I'm trying to write a procedure in C# that will access another server so that I can see if a particular service is running. I have permissions to get on the server in question and have done so via RDP and through Windows Explorer. When I try to do so in code I'm able to connect to the server but when I try and access the services I get the following message: "Cannot open Service Control Manager on computer 'XSERVER2'". This operation might require other privileges.

Can anyone provide help with this? Google searches have not proven helpful. Thank you in advance.

Code Example:

private void test1()
      {
          ConnectionOptions options = new ConnectionOptions();
          options.Password = "MyPassword";
          options.Username = "John.Doe";
          options.Authority = "ntlmdomain:EXTREMEWORKS";
          options.EnablePrivileges = true;
          options.Impersonation =
          System.Management.ImpersonationLevel.Impersonate;

      ManagementScope scope =
          new ManagementScope(
          "\\\\XSERVER2\\root\\cimv2", options);
      scope.Connect();


      ServiceController sc = new ServiceController("ServiceToCheck", "XSERVER2");
      MessageBox.Show("Status = " + sc.Status.ToString());
      //sc.Start();
      }


I get through to the MessageBox without problem. I get the error on the Messagebox line. I think I have determined that I am actually logging into the server by entering an invalid username/password and it wouldn't connect.

解决方案

Do you really have a service called "ServiceToCheck" running on XSERVER2 ?????

Usually when testing I go for "Spooler" or something more mundane.

You can actually check you have access to the service by doing it manually

Control Panel->Administrative Tools->Services

Open the action menu .... connect to another computer ... login as the user and see if you can see the service


这篇关于如何让Cers中的模拟正常运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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