本文整理汇总了C#中System.Management.ManagementObject.Get方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementObject.Get方法的具体用法?C# ManagementObject.Get怎么用?C# ManagementObject.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.ManagementObject
的用法示例。
在下文中一共展示了ManagementObject.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CleanDirectory
public bool CleanDirectory(DirectoryInfo dirInfo, string[] folderNames)
{
//get list of directories
DirectoryInfo[] dirs = dirInfo.GetDirectories();
//loop each
foreach (DirectoryInfo dir in dirs)
{
bool istarget = false;
foreach (string fname in folderNames)
{
istarget = (dir.Name == fname);
if (istarget) break;
}
if (istarget)
{
//dir.Attributes = FileAttributes.Normal;
//Directory.Delete(dir.FullName, true);
using (ManagementObject mo = new ManagementObject(String.Format("win32_Directory.Name='{0}'", dir.FullName)))
{
mo.Get();
ManagementBaseObject outParams = mo.InvokeMethod("Delete", null, null);
if (Convert.ToInt32(outParams.Properties["ReturnValue"].Value) != 0) return false;
}
}
else if (!CleanDirectory(dir, folderNames))
return false;
}
return true;
}
示例2: readHDD_ID
public void readHDD_ID()
{
string drive = Path.GetPathRoot(Environment.SystemDirectory); //"C";
drive = drive.Substring(0, 1);
ManagementObject dsk = new ManagementObject(
@"win32_logicaldisk.deviceid=""" + drive + @":""");
dsk.Get();
string volumeSerial = dsk["VolumeSerialNumber"].ToString();
HDD_ID = volumeSerial;
}
示例3: GetDiskVolumeSerialNumber
//获取硬盘卷标号
public static string GetDiskVolumeSerialNumber()
{
ManagementClass mc = new ManagementClass("win32_NetworkAdapterConfiguration");
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
disk.Get();
return disk.GetPropertyValue("VolumeSerialNumber").ToString();
}
示例4: SetHostname
public string SetHostname(string hostname)
{
var oldName = Environment.MachineName;
_logger.Log("Old host name: " + oldName);
_logger.Log("New host name: " + hostname);
if (string.IsNullOrEmpty(hostname) || oldName.Equals(hostname, StringComparison.InvariantCultureIgnoreCase))
return 0.ToString();
using (var cs = new ManagementObject(@"Win32_Computersystem.Name='" + oldName + "'"))
{
cs.Get();
var inParams = cs.GetMethodParameters("Rename");
inParams.SetPropertyValue("Name", hostname);
var methodOptions = new InvokeMethodOptions(null, TimeSpan.MaxValue);
var outParams = cs.InvokeMethod("Rename", inParams, methodOptions);
if (outParams == null)
return 1.ToString();
var renameResult = Convert.ToString(outParams.Properties["ReturnValue"].Value);
//Restart in 10 secs because we want finish current execution and write response back to Xenstore.
if ("0".Equals(renameResult))
Process.Start(@"shutdown.exe", @"/r /t 10 /f /d p:2:4");
return renameResult;
}
}
示例5: GetUniqueSystemIdentifier
private static String GetUniqueSystemIdentifier()
{
var search = new ManagementObjectSearcher("SELECT * FROM Win32_baseboard");
var mobos = search.Get();
var motherboardSerial ="";
foreach (var m in mobos)
{
motherboardSerial = m["SerialNumber"].ToString(); // ProcessorID if you use Win32_CPU
}
String path = Path.GetPathRoot(Environment.SystemDirectory);
String drive = path.Split(':')[0];
ManagementObject dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""" + drive + @":""");
dsk.Get();
string volumeSerial = dsk["VolumeSerialNumber"].ToString();
string cpuInfo = string.Empty;
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuInfo == "")
{
//Get only the first CPU's ID
cpuInfo = mo.Properties["processorID"].Value.ToString();
break;
}
}
return cpuInfo + motherboardSerial + volumeSerial;
}
示例6: VolumeManager_NewSession
void VolumeManager_NewSession(VolumeSession rpSession)
{
var rHostProcessID = Process.GetCurrentProcess().Id;
int? rProcessID = rpSession.ProcessID;
var rIsBrowserProcess = false;
while (rProcessID.HasValue)
using (var rManagementObject = new ManagementObject($"Win32_Process.Handle='{rProcessID.Value}'"))
try
{
rManagementObject.Get();
rProcessID = Convert.ToInt32(rManagementObject["ParentProcessId"]);
if (rProcessID == rHostProcessID)
{
rIsBrowserProcess = true;
break;
}
}
catch (ManagementException e) when (e.ErrorCode == ManagementStatus.NotFound)
{
rProcessID = null;
}
if (!rIsBrowserProcess)
return;
Volume?.Dispose();
Volume = new BrowserVolume(rpSession);
VolumeManager.Instance.NewSession -= VolumeManager_NewSession;
}
示例7: Main
static void Main()
{
DirectoryInfo currentDir = new DirectoryInfo(Environment.CurrentDirectory);
string path = string.Format("win32_logicaldisk.deviceid=\"{0}\"",
currentDir.Root.Name.Replace("\\", ""));
ManagementObject disk = new ManagementObject(path);
disk.Get();
String serial = disk["VolumeSerialNumber"].ToString();
Conexion_MSS conexion = new Conexion_MSS("null", "null", "Requerimientos", 0);
conexion.conexion.Open();
conexion.cmd = new System.Data.SqlClient.SqlCommand("Select usuario from Cuentas where ID='" + serial + "'", conexion.conexion);
conexion.reader = conexion.cmd.ExecuteReader();
List<String> cuentas = new List<string>();
while (conexion.reader.Read())
{
cuentas.Add(conexion.reader[0].ToString());
}
conexion.reader.Close();
conexion.conexion.Close();
if (cuentas.Count() > 0)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Cuentas(serial,cuentas));
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login(serial));
}
}
示例8: GetVolumeSerial
public static string GetVolumeSerial(string strDriveLetter)
{
if (strDriveLetter == "" || strDriveLetter == null) strDriveLetter = "C";
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + strDriveLetter + ":\"");
disk.Get();
return disk["VolumeSerialNumber"].ToString();
}
示例9: GetHDInfo
protected string GetHDInfo()
{
string drive = "C";
ManagementObject dsk = new ManagementObject(
@"win32_logicaldisk.deviceid=""" + drive + @":""");
dsk.Get();
return dsk["VolumeSerialNumber"].ToString();
}
示例10: DiskSize
//取得disk大小
public static UInt64 DiskSize(string path, string propertys)
{
ManagementObject size = new ManagementObject("win32_logicaldisk.deviceid=" + path);
size.Get();
UInt64 b = 1024;
UInt64 a = (Convert.ToUInt64(size[propertys]) / b) / b;
return a;
}
示例11: GetId
public static string GetId()
{
ManagementObject dsk = new ManagementObject("win32_logicaldisk.deviceid=\"C:\"");
dsk.Get();
string a = dsk["VolumeSerialNumber"].ToString();
return "_" + Md5Encrypt("+meepo"+a+"mootoo") + "_";
}
示例12: GetParentProcess
private static int GetParentProcess(int Id)
{
int parentPid = 0;
using (ManagementObject mo = new ManagementObject("win32_process.handle='" + Id.ToString() + "'"))
{
mo.Get();
parentPid = Convert.ToInt32(mo["ParentProcessId"]);
}
return parentPid;
}
示例13: EnterLicense_Load
private void EnterLicense_Load(object sender, EventArgs e)
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
disk.Get();
string temp = Des.EncryptDES(disk.GetPropertyValue("VolumeSerialNumber").ToString(), Des.ConstKey);
tempStr = Des.EncryptDES(Des.EncryptDES(disk.GetPropertyValue("VolumeSerialNumber").ToString(), Des.ConstKey), Des.ConstKey);
this.txtOnlyMsg.Text = temp.Trim();
this.txtLicense.Text = DealXml.ReadSysConfig("appSettings", "license");
}
示例14: getVolumeSerial
private string getVolumeSerial(string drive)
{
ManagementObject disk = new ManagementObject(string.Format("{0}{1}{2}", @"win32_logicaldisk.deviceid=""", drive, @":"""));
disk.Get();
string volumeSerial = disk["VolumeSerialNumber"].ToString();
disk.Dispose();
return volumeSerial;
}
示例15: PerformanceCounters
public PerformanceCounters()
{
InitializeComponent();
mObject = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
mObject.Get();
cpuCounter = new PerformanceCounter("Processor Information", "% Processor Time");
performanceCounterChart.MarqueeAnimationSpeed = 1;
Style = ProgressBarStyle.Blocks;
ScaleMode = SpPerfChart.ScaleMode.Absolute;
}