WMI kald fra C# til anden maskine
Hej alleJeg skal hive data fra en anden maskine, men uanset hvad jeg gør får jeg info på localhost. Er der nogen der kan fortælle mig hvad der er forkert i nedenstående, siden jeg ikke får data på "TestMaskine" (men på localhost).
- - - - - - - - - - - -
public string Testing()
{
long mb = 1024 * 1024; //megabyte
//Connection credentials to the remote computer - not needed if the logged in account has access
ConnectionOptions oConn = new ConnectionOptions();
//oConn.Username = "username";
//oConn.Password = "password";
System.Management.ManagementScope oMs = new System.Management.ManagementScope(@"\\" + "TestMaskine", oConn);
//get fixed disk stats
System.Management.ObjectQuery oQuery = new System.Management.ObjectQuery("SELECT FreeSpace, Size, Name FROM Win32_LogicalDisk WHERE DriveType = 3");
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();
//variables
string name = "";
double fs = 0;
double us = 0;
double tot = 0;
double up = 0;
double fp = 0;
//select objects
foreach (ManagementObject oReturn in oReturnCollection)
{
// Disk name
name = oReturn["Name"].ToString();
//Free space in MB
fs = Convert.ToInt64(oReturn["FreeSpace"]) / mb;
//Used space in MB
us = (Convert.ToInt64(oReturn["Size"]) - Convert.ToInt64(oReturn["FreeSpace"])) / mb;
//Total space in MB
tot = Convert.ToInt64(oReturn["Size"]) / mb;
//used percentage
up = us / tot * 100;
//free percentage
fp = fs / tot * 100;
}
string extraInfo = ". Should be around 48 GB (not 8,26 GB, that's localhost).";
switch (1)
{
case 1:
return "Free space in GB: " + (fs / 1024) + extraInfo;
break;
case 2:
return "Used space in GB: " + (us / 1024) + extraInfo;
break;
case 3:
return "Total space in MB: " + tot.ToString() + extraInfo;
break;
case 4:
return "Used percentage: " + up.ToString() + extraInfo;
break;
default:
return "Free percentage: " + fp.ToString() + extraInfo;
break;
}
}
