本文整理汇总了C#中System.Management.ManagementObject类的典型用法代码示例。如果您正苦于以下问题:C# ManagementObject类的具体用法?C# ManagementObject怎么用?C# ManagementObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ManagementObject类属于System.Management命名空间,在下文中一共展示了ManagementObject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: IisAppPool
public IisAppPool(ManagementScope scope, string name)
{
string path = String.Format("IIsApplicationPool='W3SVC/AppPools/{0}'", name);
this.scope = scope;
appPool = new ManagementObject(scope, new ManagementPath(path), null);
Name = name;
}
开发者ID:jimbutler,项目名称:bounce,代码行数:7,代码来源:IisAppPool.cs
示例2: HotFixes
public HotFixes(ManagementObject instance)
{
hotFixID = (instance.Properties["HotFixID"].Value != null && instance.Properties["HotFixID"].Value != null)
? instance.Properties["HotFixID"].Value.ToString().Trim()
: string.Empty;
description = (instance.Properties["Description"].Value != null && instance.Properties["Description"].Value != null)
? instance.Properties["Description"].Value.ToString().Trim()
: string.Empty;
servicePackInEffect = (instance.Properties["ServicePackInEffect"].Value != null && instance.Properties["ServicePackInEffect"].Value.ToString() != string.Empty)
? instance.Properties["ServicePackInEffect"].Value.ToString().Trim()
: string.Empty;
caption = (instance.Properties["Caption"].Value != null && instance.Properties["Caption"].Value.ToString() != string.Empty)
? instance.Properties["Caption"].Value.ToString().Trim()
: string.Empty;
cSName = (instance.Properties["CSName"].Value != null && instance.Properties["CSName"].Value.ToString() != string.Empty)
? instance.Properties["CSName"].Value.ToString().Trim()
: string.Empty;
installDate = (instance.Properties["InstallDate"].Value != null && instance.Properties["InstallDate"].Value != null && instance.Properties["InstallDate"].Value.ToString() != string.Empty)
? instance.Properties["InstallDate"].Value.ToString().Trim()
: string.Empty;
fixComments = (instance.Properties["FixComments"].Value != null && instance.Properties["FixComments"].Value.ToString() != string.Empty)
? instance.Properties["FixComments"].Value.ToString().Trim()
: string.Empty;
installedBy = (instance.Properties["InstalledBy"].Value != null && instance.Properties["InstalledBy"].Value.ToString() != string.Empty)
? instance.Properties["InstalledBy"].Value.ToString().Trim()
: string.Empty;
installedOn = (instance.Properties["InstalledOn"].Value != null && instance.Properties["InstalledOn"].Value.ToString() != string.Empty)
? instance.Properties["InstalledOn"].Value.ToString().Trim()
: string.Empty;
status = (instance.Properties["Status"].Value != null && instance.Properties["Status"].Value.ToString() != string.Empty)
? instance.Properties["Status"].Value.ToString().Trim()
: string.Empty;
}
开发者ID:hydrayu,项目名称:imobile-src,代码行数:33,代码来源:HotFixes.cs
示例3: Win32_SharesSearcher
private static void Win32_SharesSearcher()
{
SelectQuery query = new SelectQuery("select * from Win32_Share where Name=\"" + sharename + "\"");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
{
foreach (ManagementObject mo in searcher.Get())
{
foreach (PropertyData prop in mo.Properties)
{
form.textBox1.AppendText(prop.Name + " = " + mo[prop.Name] + Environment.NewLine); }
//form.textBox1.AppendText(string.Format("Win32ShareName: {0} Description {1} Path {2} ", mo.Properties["Name"].Value, mo.Properties["Description"].Value, mo.Properties["Path"].Value) + Environment.NewLine);
}
}
ManagementObject winShareP = new ManagementObject("root\\CIMV2", "Win32_Share.Name=\"" + sharename + "\"", null);
ManagementBaseObject outParams = winShareP.InvokeMethod("GetAccessMask", null, null);
form.textBox1.AppendText(String.Format("access Mask = {0:x}", outParams["ReturnValue"]) + Environment.NewLine);
ManagementBaseObject inParams = winShareP.GetMethodParameters("SetShareInfo");
form.textBox1.AppendText("SetShareInfor in parameters" + Environment.NewLine);
foreach (PropertyData prop in inParams.Properties)
{
form.textBox1.AppendText(String.Format("PROP = {0}, TYPE = {1} ", prop.Name, prop.Type.ToString()) + Environment.NewLine);
}
Object access = inParams.GetPropertyValue("Access");
//Stopped development here because ShareAFolder project exists. The rest of the development is there
//Maybe should copy Sahare a Folder content to here at some point
}
开发者ID:chughes-3,项目名称:WMI-Accessing,代码行数:26,代码来源:W32ShareSecurity.cs
示例4: DriveSN
public static string DriveSN(string DriveLetter)
{
ManagementObject disk = new ManagementObject(String.Format("Win32_Logicaldisk='{0}'", DriveLetter));
string VolumeName = disk.Properties["VolumeName"].Value.ToString();
string SerialNumber = disk.Properties["VolumeSerialnumber"].Value.ToString();
return SerialNumber.Insert(4, "-");
}
开发者ID:mattocchi,项目名称:VS2010Commons,代码行数:7,代码来源:DiskUtils.cs
示例5: VideoController
public VideoController(ManagementObject instance)
{
description = (instance.Properties["Description"].Value != null)
? instance.Properties["Description"].Value.ToString().Trim()
: string.Empty;
currentHorizontalResolution = (instance.Properties["CurrentHorizontalResolution"].Value !=
null)
?
instance.Properties["CurrentHorizontalResolution"].Value.
ToString().Trim()
: string.Empty;
currentVerticalResolution = (instance.Properties["CurrentVerticalResolution"].Value != null)
?
instance.Properties["CurrentVerticalResolution"].Value.ToString().
Trim()
: string.Empty;
currentNumberOfColors = (instance.Properties["CurrentNumberOfColors"].Value != null)
?
instance.Properties["CurrentNumberOfColors"].Value.ToString().Trim()
: string.Empty;
videoProcessor = (instance.Properties["VideoProcessor"].Value != null)
? instance.Properties["VideoProcessor"].Value.ToString().Trim()
: string.Empty;
adapterRAM = (instance.Properties["AdapterRAM"].Value != null)
? instance.Properties["AdapterRAM"].Value.ToString().Trim()
: string.Empty;
installedDisplayDrivers = (instance.Properties["InstalledDisplayDrivers"].Value != null)
?
instance.Properties["InstalledDisplayDrivers"].Value.ToString().Trim
()
: string.Empty;
driverVersion = (instance.Properties["DriverVersion"].Value != null)
? instance.Properties["DriverVersion"].Value.ToString().Trim()
: string.Empty;
}
开发者ID:hydrayu,项目名称:imobile-src,代码行数:35,代码来源:VideoController.cs
示例6: 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();
}
开发者ID:PavelAlekseyuk,项目名称:Online-Processing-System-code-samples,代码行数:7,代码来源:Program.cs
示例7: DataStatistics
int wnicIndex; //the index of the wireless network interface
#endregion Fields
#region Constructors
public DataStatistics(Hashtable param)
{
SaveResult = PublicFuns.str2Int32((String)param["SaveResult"], 1);
FileName = (String)param["FileName"];
StatisticLevel = PublicFuns.str2Int32((String)param["StatisticLevel"], 0);
wnicIndex = PublicFuns.str2Int32((String)param["WNICIndex"], 0);
tempData = new StatData(param);
hasWNIC = false;
sysInfo = new SystemInfo();
win32ProcessorObj = RetrieveManagementObject("Win32_Processor");
processor.update(win32ProcessorObj);
sysInfo.pro = processor;
try
{
getSystemInfo();
createSystemCounters();
initLog();
}
catch (MyException ex)
{
throw ex;
}
}
开发者ID:hch-im,项目名称:ptopw,代码行数:32,代码来源:DataStatistics.cs
示例8: Disk
public Disk(ManagementObject instance)
{
PropertyDataCollection.PropertyDataEnumerator enumerator = instance.Properties.GetEnumerator();
while (enumerator.MoveNext())
{
Console.WriteLine(enumerator.Current.Name);
}
manufacturer = (instance.Properties["Manufacturer"].Value != null)
? instance.Properties["Manufacturer"].Value.ToString().Trim()
: string.Empty;
model = (instance.Properties["Model"].Value != null)
? instance.Properties["Model"].Value.ToString().Trim()
: string.Empty;
description = (instance.Properties["Description"].Value != null)
? instance.Properties["Description"].Value.ToString().Trim()
: string.Empty;
interfaceType = (instance.Properties["InterfaceType"].Value != null)
? instance.Properties["InterfaceType"].Value.ToString().Trim()
: string.Empty;
size = (instance.Properties["Size"].Value != null)
? instance.Properties["Size"].Value.ToString().Trim()
: string.Empty;
partitions = (instance.Properties["Partitions"].Value != null)
? instance.Properties["Partitions"].Value.ToString().Trim()
: string.Empty;
scsiBus = (instance.Properties["ScsiBus"].Value != null)
? instance.Properties["ScsiBus"].Value.ToString().Trim()
: string.Empty;
scsiTargetID = (instance.Properties["ScsiTargetID"].Value != null)
? instance.Properties["ScsiTargetID"].Value.ToString().Trim()
: string.Empty;
deviceID = (instance.Properties["DeviceID"].Value != null)
? instance.Properties["DeviceID"].Value.ToString().Trim()
: string.Empty;
}
开发者ID:hydrayu,项目名称:imobile-src,代码行数:35,代码来源:Disk.cs
示例9: Volume
// Expects a Win32_DiskDrive object
// http://msdn.microsoft.com/en-us/library/aa394132%28v=VS.85%29.aspx
internal Volume(ManagementObject o)
{
if (o.ClassPath.ClassName != "Win32_DiskDrive")
throw new ArgumentException (o.ClassPath.ClassName, "o");
Uuid = o.Str ("PNPDeviceID");
Name = o.Str ("Caption");
// Get USB vendor/product ids from the associated CIM_USBDevice
// This way of associating them (via a substring of the PNPDeviceID) is quite a hack; patches welcome
var match = regex.Match (Uuid);
if (match.Success) {
string query = String.Format ("SELECT * FROM CIM_USBDevice WHERE DeviceID LIKE '%{0}'", match.Groups[1].Captures[0].Value);
UsbDevice = HardwareManager.Query (query).Select (u => new UsbDevice (u)).FirstOrDefault ();
}
// Get MountPoint and more from the associated LogicalDisk
// FIXME this assumes one partition for the device
foreach (ManagementObject partition in o.GetRelated ("Win32_DiskPartition")) {
foreach (ManagementObject disk in partition.GetRelated ("Win32_LogicalDisk")) {
//IsMounted = (bool)ld.GetPropertyValue ("Automount") == true;
//IsReadOnly = (ushort) ld.GetPropertyValue ("Access") == 1;
MountPoint = disk.Str ("Name") + "/";
FileSystem = disk.Str ("FileSystem");
Capacity = (ulong) disk.GetPropertyValue ("Size");
Available = (long)(ulong)disk.GetPropertyValue ("FreeSpace");
return;
}
}
}
开发者ID:kelsieflynn,项目名称:banshee,代码行数:32,代码来源:Volume.cs
示例10: GetSnapshotData
/// <summary>
/// Gets the data for a given snapshot that belongs to the given virtual machine..
/// </summary>
/// <param name="virtualMachine">The virtual machine object.</param>
/// <param name="snapshotName">The name of the snapshot that should be obtained.</param>
/// <returns>The snapshot data object or <see langword="null" /> if no snapshot could be found.</returns>
public static ManagementObject GetSnapshotData(ManagementObject virtualMachine, string snapshotName)
{
ManagementObjectCollection vmSettings = virtualMachine.GetRelated(
"Msvm_VirtualSystemsettingData",
"Msvm_PreviousSettingData",
null,
null,
"SettingData",
"ManagedElement",
false,
null);
ManagementObject vmSetting = null;
foreach (ManagementObject instance in vmSettings)
{
var name = (string)instance["ElementName"];
if (string.Equals(snapshotName, name, StringComparison.Ordinal))
{
vmSetting = instance;
break;
}
}
return vmSetting;
}
开发者ID:pvandervelde,项目名称:Sherlock,代码行数:31,代码来源:WmiUtility.cs
示例11: GetWorkGroupName
public static string GetWorkGroupName()
{
string result = String.Empty;
if (OSVersionPlatform.GetConcretePlatform() == PlatformID.MacOSX)
{
//OS X
string configFilePath = @"/Library/Preferences/SystemConfiguration/com.apple.smb.server.plist";
PlistParser parser = new PlistParser(configFilePath);
result = parser["Workgroup"].ToString();
}
else if (OSVersionPlatform.GetGenericPlatform() == PlatformID.Unix)
{
//Linux
string configFilePath = @"/etc/samba/smb.conf";
IniFileParser parser = new IniFileParser(configFilePath);
result = parser.GetValue("Global", "Workgroup");
}
else
{
//Windows
using (ManagementObject managementObject = new ManagementObject(String.Format("Win32_ComputerSystem.Name='{0}'", Environment.MachineName)))
{
object workgroup;
//Workgroup is NULL under XP
if (OSVersionPlatform.IsWindowsVistaOrHigher())
workgroup = managementObject["Workgroup"];
else
workgroup = managementObject["Domain"];
result = workgroup.ToString();
}
}
return result;
}
开发者ID:RomanySaad,项目名称:MultiMiner,代码行数:34,代码来源:LocalNetwork.cs
示例12: GetUptime
public static string GetUptime()
{
ManagementObject mo = new ManagementObject(@"\\.\root\cimv2:[email protected]");
DateTime lastBootUp = ManagementDateTimeConverter.ToDateTime(mo["LastBootUpTime"].ToString());
TimeSpan temp = DateTime.Now.ToUniversalTime() - lastBootUp.ToUniversalTime();
return temp.Days.ToString() + ":" + temp.Hours.ToString() + ":" + temp.Minutes.ToString() + ":" + temp.Seconds.ToString();
}
开发者ID:GavinKenna,项目名称:Muroidea,代码行数:7,代码来源:Client.cs
示例13: RAM
public RAM(CrystalFontz635 cf)
: base(cf)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
pfRAM = new PerformanceCounter("Memory", "Available MBytes");
using (ManagementObject mo = new ManagementObject(@"Win32_ComputerSystem.Name=""" + Environment.MachineName + "\"")) {
TotalInstalled = (ulong)mo["TotalPhysicalMemory"];
}
pfRAM.NextValue();
LcdModule.ClearScreen();
LcdModule.SetCursorPosition(0, 0);
LcdModule.SendData(0, 0, string.Format("RAM USAGE (T:{0}Mb)", Math.Round(TotalInstalled / 1024.0 / 1024.0)).PadRight(20));
LcdModule.SetCGRAM(0,
new byte[] {
0x3f,
0x3f,
0x3f,
0x3f,
0x3f,
0x3f,
0x3f,
0x3f
});
time = new Stopwatch();
time.Start();
}
开发者ID:CryptonZylog,项目名称:cf635,代码行数:27,代码来源:RAM.cs
示例14: 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;
}
}
开发者ID:kashivreddy,项目名称:openstack-guest-agents-windows-xenserver,代码行数:25,代码来源:SetHostnameAction.cs
示例15: GetImportedPvm
GetImportedPvm(
ManagementBaseObject outputParameters)
{
ManagementObject pvm = null;
ManagementScope scope = new ManagementScope(@"root\virtualization\v2");
if (WmiUtilities.ValidateOutput(outputParameters, scope))
{
if ((uint)outputParameters["ReturnValue"] == 0)
{
pvm = new ManagementObject((string)outputParameters["ImportedSystem"]);
}
if ((uint)outputParameters["ReturnValue"] == 4096)
{
using (ManagementObject job =
new ManagementObject((string)outputParameters["Job"]))
using (ManagementObjectCollection pvmCollection =
job.GetRelated("Msvm_PlannedComputerSystem",
"Msvm_AffectedJobElement", null, null, null, null, false, null))
{
pvm = WmiUtilities.GetFirstObjectFromCollection(pvmCollection);
}
}
}
return pvm;
}
开发者ID:dhanzhang,项目名称:Windows-classic-samples,代码行数:29,代码来源:ImportUtilities.cs
示例16: IsAppPoolRunning
/// <summary>
/// Indicates if the AppPool is running.
/// </summary>
/// <param name="appPoolName">The AppPool name.</param>
/// <returns>An <see cref="bool"/>. Indicating if the AppPool is running.</returns>
public static bool IsAppPoolRunning(string appPoolName)
{
string managementObjectPath = string.Format(CultureInfo.CurrentCulture, "root\\MicrosoftIISv2:IIsApplicationPoolSetting.Name=\"W3SVC/APPPOOLS/{0}\"", appPoolName);
int state;
using (ManagementObject managementObject = new ManagementObject(managementObjectPath))
{
try
{
state = (int)managementObject[IisApplicationPoolSettingPropertyNames.AppPoolState];
}
catch (DirectoryNotFoundException e)
{
if (e.Message == "Win32: The system cannot find the path specified.\r\n")
{
string exceptionMessage = string.Format(CultureInfo.CurrentCulture, "Could not find an AppPool with a name of '{0}'.", appPoolName);
throw new CoreException(exceptionMessage);
}
throw;
}
}
switch (state)
{
case AppPoolStatus.Started:
return true;
case AppPoolStatus.Stopped:
return false;
default:
string exceptionMessage = string.Format(CultureInfo.CurrentCulture, "The AppPool with a name of '{0}' had an unknown status.", appPoolName);
throw new CoreException(exceptionMessage);
}
}
开发者ID:StealFocus,项目名称:Core,代码行数:38,代码来源:Metabase.cs
示例17: Install
public override void Install(System.Collections.IDictionary savedState)
{
try
{
base.Install(savedState);
// Turn on "Allow service to interact with desktop".
// (Note: A published technique to do this by setting a bit in the service's Type registry value (0x100) does not turn this on, so do as follows.)
// This will let the NotifyIcon appear in the sys tray (with balloon at start-up), but not its context menu.
ConnectionOptions options = new ConnectionOptions();
options.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope scope = new ManagementScope(@"root\CIMv2", options); // Common Information Model, version 2.
ManagementObject wmiService = new ManagementObject("Win32_Service.Name='" + this.serviceInstaller.ServiceName + "'");
ManagementBaseObject inParameters = wmiService.GetMethodParameters("Change");
inParameters["DesktopInteract"] = true;
ManagementBaseObject outParameters = wmiService.InvokeMethod("Change", inParameters, null);
}
catch (Exception e)
{
string licenseKey = "";
string licenseName = "";
try
{
licenseKey = Properties.Settings.Default.LicenseKey;
licenseName = Properties.Settings.Default.LicenseName;
}
catch { }
Service.Services.LoggingService.AddLogEntry(WOSI.CallButler.ManagementInterface.LogLevel.ErrorsOnly, Utils.ErrorUtils.FormatErrorString(e), true);
CallButler.ExceptionManagement.ErrorCaptureUtils.SendError(e, licenseKey, licenseName, "");
}
}
开发者ID:hostitherepc,项目名称:Fork-1,代码行数:32,代码来源:ProjectInstaller.cs
示例18: DecompressFolder
private static uint DecompressFolder(string path)
{
using (ManagementObject obj2 = new ManagementObject("Win32_Directory.Name=\"" + path.Replace(@"\", @"\\") + "\""))
{
return (uint)obj2.InvokeMethod("UnCompress", null, null).Properties["ReturnValue"].Value;
}
}
开发者ID:drivelens,项目名称:drivelens,代码行数:7,代码来源:FileOperator.cs
示例19: StorageDisk
/// <summary>
/// <para>Create a new <see cref="StorageDisk"/> from the corresponding <see cref="ManagementObject"/></para>
/// </summary>
/// <param name="mo"></param>
public StorageDisk(ManagementObject mo)
: base(mo["DeviceID"].ToString())
{
this.Model = mo["Model"].ToString();
this.Name = mo["Name"].ToString();
this.Size = Convert.ToUInt64(mo["Size"]);
}
开发者ID:Jonny007-MKD,项目名称:Trigger4Win,代码行数:11,代码来源:StorageDisk.cs
示例20: 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;
}
开发者ID:CodeForCSharp,项目名称:KanColleInspector,代码行数:33,代码来源:GameController.cs
注:本文中的System.Management.ManagementObject类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论