gpt4 book ai didi

c# - 如何获取使用 System.Diagnostics.Process.GetProcess(string) 的权限?

转载 作者:太空狗 更新时间:2023-10-29 23:34:07 25 4
gpt4 key购买 nike

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

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

最佳答案

为此您可以尝试使用 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。

第一个

关于c# - 如何获取使用 System.Diagnostics.Process.GetProcess(string) 的权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6757711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com