如何获得使用System.Diagnostics.Process.GetProcess(string)的权限?

发布于 2024-11-25 07:53:20 字数 176 浏览 1 评论 0原文

我正在使用 Microsoft Visual Studio 制作一个简单的远程任务管理器以供体验。

我想使用 Process.GetProcesses(string); 但存在访问被拒绝异常,不允许我获取远程计算机进程。事实上这是正常的,因为我们应该使用用户名和密码进行身份验证,但如何

I'm using Microsoft Visual Studio to make a simple remote task manager for experience purposes.

I want to use Process.GetProcesses(string); but there is an access denied exception that won't allow me to get the remote computer process. In fact it is normal because we should authenticate using a user name and password, but how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葬花如无物 2024-12-02 07:53:20

您可以尝试使用WMI来实现此目的

/// using System.Management;  
// don't forget! in VS you may have to add a new reference to this DLL
ConnectionOptions op = new ConnectionOptions();
op.Username = "REMOTE_USER";
op.Password = "REMOTE_PASSWORD";

ManagementScope sc = new ManagementScope(@"\\REMOTE_COMPUTER_NAME\root\cimv2", op);

ObjectQuery query = new ObjectQuery("Select * from Win32_Process");

ManagementObjectSearcher searcher = new ManagementObjectSearcher(sc, query);
ManagementObjectCollection result = searcher.Get();

foreach (ManagementObject obj in result)
{
     if (obj["Caption"] != null) Console.Write(obj["Caption"].ToString() + "\t");
     if (obj["CommandLine"] != null) Console.WriteLine(obj["CommandLine"].ToString());
}

有关Win32_Process 类请参阅 MSDN。

You may try to use WMI for this purpose

/// using System.Management;  
// don't forget! in VS you may have to add a new reference to this DLL
ConnectionOptions op = new ConnectionOptions();
op.Username = "REMOTE_USER";
op.Password = "REMOTE_PASSWORD";

ManagementScope sc = new ManagementScope(@"\\REMOTE_COMPUTER_NAME\root\cimv2", op);

ObjectQuery query = new ObjectQuery("Select * from Win32_Process");

ManagementObjectSearcher searcher = new ManagementObjectSearcher(sc, query);
ManagementObjectCollection result = searcher.Get();

foreach (ManagementObject obj in result)
{
     if (obj["Caption"] != null) Console.Write(obj["Caption"].ToString() + "\t");
     if (obj["CommandLine"] != null) Console.WriteLine(obj["CommandLine"].ToString());
}

For further details on Win32_Process class see MSDN.

hth

雨落□心尘 2024-12-02 07:53:20

编辑:再次阅读您的帖子,我的帖子中描述的步骤仅适用于域,我假设您在工作组中工作。对不起。

我最近在 Windows 7 上以管理员身份运行 Visual Studio 时遇到了类似的问题。如果您将程序提升为以本地管理员身份运行,远程计算机和网络共享上的权限似乎会被删除(即使在域中!),这将是如果您在 VS 以管理员身份运行时在 VS 之外运行程序,就会出现这种情况。如果您拥有域范围的管理员帐户,甚至会发生这种情况。

尝试以下操作:

  • 构建解决方案
  • 使用您的帐户手动运行它,希望有
    从 Windows 资源管理器获得远程计算机上的权限,无需提升

如果这有帮助,您可以停止以管理员身份运行 VS。这对我来说很有效。

EDIT: Just read your post again, the steps described in my post only apply in a domain, I assume you work inside a workgroup. I'm sorry.

I recently ran into a similar issue when running Visual Studio as Administrator on Windows 7. It seems like permissions on remote machines and network shares are dropped (even in a domain!) if you elevate your program to run as local administrator, which will be the case if you run a program out of VS when VS is run as admin. This even happens if you have domain wide admin accounts.

Try the following:

  • Build the solution
  • Run it manually with your account which has hopefully
    privileges on the remote computer from windows explorer, without elevation

If this helps, you could stop running VS as administrator. It worked out for me.

ヤ经典坏疍 2024-12-02 07:53:20

我很确定您需要提升才能执行此操作,或者至少通过 冒充

I'm pretty sure you need elevation to do this, or at least use a stronger user by impersonation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文