拒绝访问.Net GetProcesses

wnvonmuf  于 2023-03-31  发布在  .NET
关注(0)|答案(2)|浏览(119)

我无法连接到远程计算机以获取正在运行的进程列表。对于我的测试机器,我使用用户名@“ownme\veritas”。密码只是“veritas”。示例域是“ownme”。

return new System.Management.ConnectionOptions()
{
    //certainly these variables have been checked and are correct
    Username = UserCredential.DomainUser,
    Password = UserCredential.Password
};

这就是我尝试连接的地方。我不知道,但这可能是这里的问题。也可能是我没有在上面的ConnectionOptions中填写足够的字段。我参考了这两篇文章:
https://www.experts-exchange.com/questions/23514935/How-to-use-GetProcess-for-remote-sytems.html
https://msdn.microsoft.com/en-us/library/system.management.connectionoptions.authentication.aspx
我不知道我做错了什么

ManagementScope scope = new ManagementScope($"\\\\{computer.DnsHostname}\\root\\cimv2", connectionOptions);
scope.Connect();

//Error: Access is denied
var processes = System.Diagnostics.Process.GetProcesses(dnsHostName);
lvjbypge

lvjbypge1#

GetProcesses将使用当前用户的凭据连接到远程计算机,而不是您通过ConnectionOptions指定的凭据。
您需要使用使用正确凭据创建的WMI作用域对象来对进程发出如下查询:

//..

SelectQuery query = new SelectQuery("select * from Win32_Process"); //query processes

using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query))
{
    using (ManagementObjectCollection collection = searcher.Get())
    {
        foreach (var process in collection) //loop through results
        {
            var name = process["name"]; //process name
            //Do something with process
        }
    }
}
wnavrhmk

wnavrhmk2#

我不知道这是一个如此受人关注的问题:我很早就找到了答案,我其实没有用WMI做,我们其实跟微软开了罚单,他们给我们答案后给我们免费打折,答案是:
LogonUser + NEW_CREDENTIALS

相关问题