0
如何使用C#使用WMIUserID
,WMIPassword
,WMIAlternateCredentials
?迫切需要關於WMI的解釋...請幫助
另外,是否有可能獲得遠程計算機的管理員密碼?
請嘗試用例子來解釋。
謝謝。
如何使用C#使用WMIUserID
,WMIPassword
,WMIAlternateCredentials
?迫切需要關於WMI的解釋...請幫助
另外,是否有可能獲得遠程計算機的管理員密碼?
請嘗試用例子來解釋。
謝謝。
她的一些示例代碼
using System;
using System.Text;
using System.Threading;
using Microsoft.Management.Infrastructure;
using Microsoft.Management.Infrastructure.Options;
using System.Security;
namespace SMAPIQuery
{
class Program
{
static void Main(string[] args)
{
string computer = "Computer_B";
string domain = "DOMAIN";
string username = "AdminUserName";
string plaintextpassword;
Console.WriteLine("Enter password:");
plaintextpassword = Console.ReadLine();
SecureString securepassword = new SecureString();
foreach (char c in plaintextpassword)
{
securepassword.AppendChar(c);
}
// create Credentials
CimCredential Credentials = new CimCredential(PasswordAuthenticationMechanism.Default,
domain,
username,
securepassword);
// create SessionOptions using Credentials
WSManSessionOptions SessionOptions = new WSManSessionOptions();
SessionOptions.AddDestinationCredentials(Credentials);
// create Session using computer, SessionOptions
CimSession Session = CimSession.Create(computer, SessionOptions);
var allVolumes = Session.QueryInstances(@"root\cimv2", "WQL", "SELECT * FROM Win32_Volume");
var allPDisks = Session.QueryInstances(@"root\cimv2", "WQL", "SELECT * FROM Win32_DiskDrive");
// Loop through all volumes
foreach (CimInstance oneVolume in allVolumes)
{
// Show volume information
if (oneVolume.CimInstanceProperties["DriveLetter"].ToString()[0] > ' ' )
{
Console.WriteLine("Volume ‘{0}’ has {1} bytes total, {2} bytes available",
oneVolume.CimInstanceProperties["DriveLetter"],
oneVolume.CimInstanceProperties["Size"],
oneVolume.CimInstanceProperties["SizeRemaining"]);
}
}
// Loop through all physical disks
foreach (CimInstance onePDisk in allPDisks)
{
// Show physical disk information
Console.WriteLine("Disk {0} is model {1}, serial number {2}",
onePDisk.CimInstanceProperties["DeviceId"],
onePDisk.CimInstanceProperties["Model"].ToString().TrimEnd(),
onePDisk.CimInstanceProperties["SerialNumber"]);
}
Console.ReadLine();
}
}
}
你是認真的管理員密碼? – 2010-05-29 11:53:03
那麼,我想如何設置WMI連接到使用該計算機的管理權限的遠程計算機? – Samiul 2010-05-30 11:05:30
@Samiul:取決於環境。如果在一個域中,您應該使用域管理員帳戶進行連接。如果在工作組中,遠程計算機需要將要用於連接的帳戶添加到其本地管理員組。遠程檢索管理員帳戶的密碼顯然應該是一個有點漏洞的安全漏洞;因此不能作爲選項提供。 – Flater 2017-06-26 09:39:12