本文整理汇总了C#中System.Management.ManagementBaseObject类的典型用法代码示例。如果您正苦于以下问题:C# ManagementBaseObject类的具体用法?C# ManagementBaseObject怎么用?C# ManagementBaseObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ManagementBaseObject类属于System.Management命名空间,在下文中一共展示了ManagementBaseObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NTLogEvent
public NTLogEvent(System.Management.ManagementBaseObject theObject) {
Initialize();
embeddedObj = theObject;
// PrivateSystemProperties = new ManagementSystemProperties(theObject);
curObj = embeddedObj;
isEmbedded = true;
}
示例2: ManagementException
internal ManagementException(Exception e, string msg, ManagementBaseObject errObj) : base(msg, e)
{
try
{
if (e as ManagementException == null)
{
if (e as COMException == null)
{
this.errorCode = (ManagementStatus)base.HResult;
}
else
{
this.errorCode = (ManagementStatus)((COMException)e).ErrorCode;
}
}
else
{
this.errorCode = ((ManagementException)e).ErrorCode;
if (this.errorObject == null)
{
this.errorObject = null;
}
else
{
this.errorObject = (ManagementBaseObject)((ManagementException)e).errorObject.Clone();
}
}
}
catch
{
}
}
示例3: OS
public OS(ManagementBaseObject instance)
{
caption = (instance.Properties["Caption"].Value != null)
? instance.Properties["Caption"].Value.ToString().Trim()
: string.Empty;
version = (instance.Properties["Version"].Value != null)
? instance.Properties["Version"].Value.ToString().Trim()
: string.Empty;
buildNumber = (instance.Properties["BuildNumber"].Value != null)
? instance.Properties["BuildNumber"].Value.ToString().Trim()
: string.Empty;
buildType = (instance.Properties["BuildType"].Value != null)
? instance.Properties["BuildType"].Value.ToString().Trim()
: string.Empty;
bootDevice = (instance.Properties["BootDevice"].Value != null)
? instance.Properties["BootDevice"].Value.ToString().Trim()
: string.Empty;
systemDevice = (instance.Properties["SystemDevice"].Value != null)
? instance.Properties["SystemDevice"].Value.ToString().Trim()
: string.Empty;
windowsDirectory = (instance.Properties["WindowsDirectory"].Value != null)
? instance.Properties["WindowsDirectory"].Value.ToString().Trim()
: string.Empty;
systemDirectory = (instance.Properties["SystemDirectory"].Value != null)
? instance.Properties["SystemDirectory"].Value.ToString().Trim()
: string.Empty;
cSName = (instance.Properties["CSName"].Value != null)
? instance.Properties["CSName"].Value.ToString().Trim()
: string.Empty;
csdVersion = (instance.Properties["CsdVersion"].Value != null)
? instance.Properties["CsdVersion"].Value.ToString().Trim()
: string.Empty;
currentTimeZone = (instance.Properties["CurrentTimeZone"].Value != null)
? instance.Properties["CurrentTimeZone"].Value.ToString().Trim()
: string.Empty;
installDate = (instance.Properties["InstallDate"].Value != null)
? instance.Properties["InstallDate"].Value.ToString().Trim()
: string.Empty;
lastBootUpTime = (instance.Properties["LastBootUpTime"].Value != null)
? instance.Properties["LastBootUpTime"].Value.ToString().Trim()
: string.Empty;
organization = (instance.Properties["Organization"].Value != null)
? instance.Properties["Organization"].Value.ToString().Trim()
: string.Empty;
osLanguage = (instance.Properties["OsLanguage"].Value != null)
? instance.Properties["OsLanguage"].Value.ToString().Trim()
: string.Empty;
primary = (instance.Properties["Primary"].Value != null)
? instance.Properties["Primary"].Value.ToString().Trim()
: string.Empty;
registeredUser = (instance.Properties["RegisteredUser"].Value != null)
? instance.Properties["RegisteredUser"].Value.ToString().Trim()
: string.Empty;
serialNumber = (instance.Properties["SerialNumber"].Value != null)
? instance.Properties["SerialNumber"].Value.ToString().Trim()
: string.Empty;
totalVirtualMemorySize = (instance.Properties["TotalVirtualMemorySize"].Value != null)
? instance.Properties["TotalVirtualMemorySize"].Value.ToString().Trim()
: string.Empty;
}
示例4: ObjectReadyEventArgs
/// <summary>
/// Constructor.
/// </summary>
/// <param name="context">The operation context which is echoed back
/// from the operation which triggerred the event.</param>
/// <param name="wmiObject">The newly arrived WmiObject.</param>
internal ObjectReadyEventArgs (
object context,
ManagementBaseObject wmiObject
) : base (context)
{
this.wmiObject = wmiObject;
}
示例5: 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;
}
示例6: PropertyData
internal PropertyData(ManagementBaseObject parent, string propName)
{
this.parent = parent;
this.propertyName = propName;
this.qualifiers = null;
this.RefreshPropertyInfo();
}
示例7: FillDetails
private static EntBios FillDetails(ManagementBaseObject obj)
{
EntBios objEntBios = new EntBios();
try
{
objEntBios.ReleaseDate = WMIUtil.ToDateTime((string)obj["ReleaseDate"]);
}
catch (Exception)
{
objEntBios.ReleaseDate = DateTime.MinValue;
}
try
{
objEntBios.Manufacturer = WMIUtil.ToString(obj["Manufacturer"]);
}
catch (Exception)
{
objEntBios.Manufacturer = "";
}
try
{
objEntBios.Version = WMIUtil.ToString(obj["SMBIOSBIOSVersion"]);
}
catch (Exception)
{
objEntBios.Version = "";
}
return objEntBios;
}
示例8: GetFromWmi
public static VirtualMachineSnapshot GetFromWmi(ManagementBaseObject objSnapshot)
{
if (objSnapshot == null || objSnapshot.Properties.Count == 0)
return null;
VirtualMachineSnapshot snapshot = new VirtualMachineSnapshot();
snapshot.Id = (string)objSnapshot["InstanceID"];
snapshot.Name = (string)objSnapshot["ElementName"];
string parentId = (string)objSnapshot["Parent"];
if (!String.IsNullOrEmpty(parentId))
{
int idx = parentId.IndexOf("Microsoft:");
snapshot.ParentId = parentId.Substring(idx, parentId.Length - idx - 1);
snapshot.ParentId = snapshot.ParentId.ToLower().Replace("microsoft:", "");
}
if (!String.IsNullOrEmpty(snapshot.Id))
{
snapshot.Id = snapshot.Id.ToLower().Replace("microsoft:", "");
}
snapshot.Created = Wmi.ToDateTime((string)objSnapshot["CreationTime"]);
if (string.IsNullOrEmpty(snapshot.ParentId))
snapshot.ParentId = null; // for capability
return snapshot;
}
示例9: Add
public virtual void Add(string methodName, ManagementBaseObject inParameters, ManagementBaseObject outParameters)
{
IWbemClassObjectFreeThreaded pInSignature = null;
IWbemClassObjectFreeThreaded pOutSignature = null;
if (this.parent.GetType() == typeof(ManagementObject))
{
throw new InvalidOperationException();
}
if (inParameters != null)
{
pInSignature = inParameters.wbemObject;
}
if (outParameters != null)
{
pOutSignature = outParameters.wbemObject;
}
int errorCode = -2147217407;
try
{
errorCode = this.parent.wbemObject.PutMethod_(methodName, 0, pInSignature, pOutSignature);
}
catch (COMException exception)
{
ManagementException.ThrowWithExtendedInfo(exception);
}
if ((errorCode & 0xfffff000L) == 0x80041000L)
{
ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
}
else if ((errorCode & 0x80000000L) != 0L)
{
Marshal.ThrowExceptionForHR(errorCode);
}
}
示例10: RetrieveProcessInfo
static ProcessInfo RetrieveProcessInfo( ManagementBaseObject o )
{
return new ProcessInfo(
Convert.ToInt32( o[ "ProcessId" ] ),
(string)o[ "Name" ],
(string)o[ "CommandLine" ] );
}
示例11: GetAddressHeaders
static IEnumerable<AddressHeader> GetAddressHeaders (ManagementBaseObject obj, bool isLocal)
{
yield return CreateAddressHeader ("ClassName", CimNamespaces.CimNamespace, obj.ClassPath.ClassName);
yield return CreateAddressHeader ("IsClass", CimNamespaces.CimNamespace, obj.ClassPath.IsClass);
yield return CreateAddressHeader ("IsInstance", CimNamespaces.CimNamespace, obj.ClassPath.IsInstance);
yield return CreateAddressHeader ("IsSingleton", CimNamespaces.CimNamespace, obj.ClassPath.IsSingleton);
yield return CreateAddressHeader ("NamespacePath", CimNamespaces.CimNamespace, obj.ClassPath.NamespacePath);
yield return CreateAddressHeader ("ServerName", CimNamespaces.CimNamespace, obj.ClassPath.Server);
yield return CreateAddressHeader ("ObjectExits", CimNamespaces.CimNamespace, obj.ObjectExits);
yield return CreateAddressHeader ("Qualifiers", CimNamespaces.CimNamespace, Serialize (obj.Qualifiers));
yield return CreateAddressHeader ("Properties", CimNamespaces.CimNamespace, Serialize (obj.Properties, isLocal));
yield return CreateAddressHeader ("SystemProperties", CimNamespaces.CimNamespace, SerializeSystem(obj.SystemProperties));
ManagementObject o = obj as ManagementObject;
if (o != null) {
yield return CreateAddressHeader ("RelativePath", CimNamespaces.CimNamespace, o.Path.RelativePath);
yield return CreateAddressHeader ("Path", CimNamespaces.CimNamespace, o.Path.Path);
} else {
yield return CreateAddressHeader ("Path", CimNamespaces.CimNamespace, obj.ClassPath.Path);
yield return CreateAddressHeader ("RelativePath", CimNamespaces.CimNamespace, obj.ClassPath.RelativePath);
}
ManagementClass classObj = obj as ManagementClass;
if (classObj != null) {
yield return CreateAddressHeader ("CimClassName", CimNamespaces.CimNamespace, "Meta_Class");
yield return CreateAddressHeader ("Methods", CimNamespaces.CimNamespace, Serialize (classObj.Methods, isLocal));
}
else {
yield return CreateAddressHeader ("CimClassName", CimNamespaces.CimNamespace, obj.ClassPath.ClassName);
}
}
示例12: FillDetails
private static EntServices FillDetails(ManagementBaseObject obj)
{
EntServices objEntServices = new EntServices();
try
{
objEntServices.DisplayName = WMIUtil.ToString(obj["DisplayName"]);
}
catch (Exception)
{
objEntServices.DisplayName = "";
}
try
{
objEntServices.Account = WMIUtil.ToString(obj["StartName"]);
}
catch (Exception)
{
objEntServices.Account = "";
}
try
{
objEntServices.Description = WMIUtil.ToString(obj["Description"]);
}
catch (Exception)
{
objEntServices.Description = "";
}
try
{
objEntServices.Path = WMIUtil.ToString(obj["PathName"]);
}
catch (Exception)
{
objEntServices.Path= "";
}
try
{
objEntServices.StartMode = WMIUtil.ToString(obj["StartMode"]);
}
catch (Exception)
{
objEntServices.StartMode = "";
}
try
{
objEntServices.State = WMIUtil.ToString(obj["State"]);
}
catch (Exception)
{
objEntServices.State = "";
}
return objEntServices;
}
示例13: CreateShare
/// <summary>
/// Creates the share.
/// </summary>
/// <param name="shareName">Name of the share.</param>
/// <param name="folderPath">The folder path.</param>
/// <returns>WindwsShare instance.</returns>
public static WindowsShare CreateShare(string shareName, string folderPath)
{
ManagementClass shareClass = null;
ManagementClass sd = null;
ManagementBaseObject inParams = null;
ManagementBaseObject outParams = null;
try
{
sd = new ManagementClass(new ManagementPath("Win32_SecurityDescriptor"), null);
sd["ControlFlags"] = 0x4;
sd["DACL"] = new ManagementBaseObject[] { };
shareClass = new ManagementClass("Win32_Share");
inParams = shareClass.GetMethodParameters("Create");
inParams["Name"] = shareName;
inParams["Path"] = new DirectoryInfo(folderPath).FullName;
//// inParams["Description"] = description;
inParams["Type"] = 0x0; // Type of Disk Drive
inParams["Access"] = sd;
outParams = shareClass.InvokeMethod("Create", inParams, null);
if ((uint)outParams["ReturnValue"] != 0)
{
throw new WindowsShareException("Unable to create share. Win32_Share.Create Error Code: " + outParams["ReturnValue"]);
}
}
catch (Exception ex)
{
throw new WindowsShareException("Unable to create share", ex);
}
finally
{
if (shareClass != null)
{
shareClass.Dispose();
}
if (inParams != null)
{
inParams.Dispose();
}
if (outParams != null)
{
outParams.Dispose();
}
if (sd != null)
{
sd.Dispose();
}
}
return new WindowsShare(shareName);
}
示例14: FillDetails
private static EntNetworkAdapter FillDetails(ManagementBaseObject obj)
{
EntNetworkAdapter objEntNetworkAdapter = new EntNetworkAdapter();
try
{
objEntNetworkAdapter.AdapterMACAddress = WMIUtil.ToString(obj["MACAddress"]);
}
catch (Exception)
{
objEntNetworkAdapter.AdapterMACAddress = "";
}
try
{
objEntNetworkAdapter.AdapterType = WMIUtil.ToString(obj["AdapterType"]);
}
catch (Exception)
{
objEntNetworkAdapter.AdapterType = "";
}
try
{
objEntNetworkAdapter.Description = WMIUtil.ToString(obj["Description"]);
}
catch (Exception)
{
objEntNetworkAdapter.Description = "";
}
try
{
objEntNetworkAdapter.Manufacturer = WMIUtil.ToString(obj["Manufacturer"]);
}
catch (Exception)
{
objEntNetworkAdapter.Manufacturer = "";
}
try
{
objEntNetworkAdapter.Name = WMIUtil.ToString(obj["Name"]);
}
catch (Exception)
{
objEntNetworkAdapter.Name = "";
}
try
{
AvailabilityValues avaiType = (AvailabilityValues)WMIUtil.ToInteger(obj["Availability"]);
objEntNetworkAdapter.Availability = avaiType.ToString();
}
catch (Exception)
{
objEntNetworkAdapter.Availability = "";
}
return objEntNetworkAdapter;
}
示例15: GetProperty
private static string GetProperty(ManagementBaseObject obj, string property)
{
var value = (obj.GetPropertyValue(property) == null)
? "NA"
: obj.GetPropertyValue(property).ToString();
return value;
}