internal PropertyData(ManagementBaseObject parent, string propName)
 {
     this.parent = parent;
     this.propertyName = propName;
     this.qualifiers = null;
     this.RefreshPropertyInfo();
 }
Exemple #2
0
		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);
			}
		}
 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);
     }
 }
Exemple #4
0
		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
			{
			}
		}
 public void ResetLogEntryInfo()
 {
     wmiLogged = false;
     wmiResult = string.Empty;
     wmiPath = @"\root\EnterpriseLibrary";
     wmiLogEntry = null;
 }
Exemple #6
0
        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;
        }
		static ProcessInfo RetrieveProcessInfo( ManagementBaseObject o )
		{
			return new ProcessInfo(
				Convert.ToInt32( o[ "ProcessId" ] ),
				(string)o[ "Name" ],
				(string)o[ "CommandLine" ] );
		}
        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;
        }
Exemple #9
0
 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;
 }
 public NTLogEvent(System.Management.ManagementBaseObject theObject) {
     Initialize();
     embeddedObj = theObject;
     // PrivateSystemProperties = new ManagementSystemProperties(theObject);
     curObj = embeddedObj;
     isEmbedded = true;            
 }
        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;
        }
	/// <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;
	}
Exemple #13
0
        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;
        }
Exemple #14
0
        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;
        }
        /// <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);
        }
		internal QualifierData(ManagementBaseObject parent, string propName, string qualName, QualifierType type)		
		{
			this.parent = parent;
			this.propertyOrMethodName = propName;
			this.qualifierName = qualName;
			this.qualifierType = type;
			RefreshQualifierInfo();
		}
        private static double GetInfo(ManagementBaseObject managedObject, string property)
        {
            var manageObjectProperty = managedObject[property];

            double value = (ulong)manageObjectProperty;

            return value;
        }
        private static string GetProperty(ManagementBaseObject obj, string property)
        {
            var value = (obj.GetPropertyValue(property) == null)
                            ? "NA"
                            : obj.GetPropertyValue(property).ToString();

            return value;
        }
        /// <summary>
        ///     字典安全值
        /// </summary>
        /// <param name="mo"></param>
        /// <param name="pName"></param>
        /// <returns></returns>
        public static string MboSafeValue(ManagementBaseObject mo, string pName)
        {
            string sR = string.Empty;

            if (mo[pName] != null)
                sR = mo[pName].ToString();

            return sR;
        }
Exemple #20
0
 public ProcessInfo(IEnumerable<ProcessInfo> allProcesses, ManagementBaseObject process)
 {
     ProcessId = (uint)process["ProcessId"];
     ParentProcessId = (uint)process["ParentProcessId"];
     Name = (string)process["Name"];
     CommandLine = (string)process["CommandLine"];
     AllProcesses = allProcesses;
     //CreationDate = (DateTime)process["CreationDate"];
 }
Exemple #21
0
 private long ToLong(ManagementBaseObject mo, string name, int divider) {
     int result;
     var value = mo[name];
     if (value != null) {
         var x = value.ToString();
         return Int32.TryParse(x, out result) ? result / divider : 0;
     }
     return 0;
 }
Exemple #22
0
        private static string GetDeviceName(ManagementBaseObject newEvent)
        {
            var targetInstanceData = newEvent.Properties["TargetInstance"];
            var targetInstanceObject = (ManagementBaseObject)targetInstanceData.Value;
            if (targetInstanceObject == null) return "";

            var description = targetInstanceObject.Properties["Name"].Value.ToString();
            return description;
        }
Exemple #23
0
 public Process(System.Management.ManagementObject theObject) {
     if ((CheckIfProperClass(theObject) == true)) {
         PrivateLateBoundObject = theObject;
         PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject);
         curObj = PrivateLateBoundObject;
     }
     else {
         throw new System.ArgumentException("Class name does not match.");
     }
 }
Exemple #24
0
 public Process(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions) {
     if ((path != null)) {
         if ((CheckIfProperClass(mgmtScope, path, getOptions) != true)) {
             throw new System.ArgumentException("Class name does not match.");
         }
     }
     PrivateLateBoundObject = new System.Management.ManagementObject(mgmtScope, path, getOptions);
     PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject);
     curObj = PrivateLateBoundObject;
 }
Exemple #25
0
        private static EntHotfixes FillDetails(ManagementBaseObject obj)
        {
            EntHotfixes objEntHotfix = new EntHotfixes();
            try
            {
                objEntHotfix.Description = WMIUtil.ToString(obj["Description"]);
            }
            catch (Exception)
            {
                objEntHotfix.Description = "";
            }

            try
            {
                objEntHotfix.FixComments = WMIUtil.ToString(obj["FixComments"]);
            }
            catch (Exception)
            {
                objEntHotfix.FixComments = "";
            }

            try
            {
                objEntHotfix.HotfixID = WMIUtil.ToString(obj["HotFixID"]);
            }
            catch (Exception)
            {
                objEntHotfix.HotfixID = "";
            }

            try
            {
                objEntHotfix.InstallBy = WMIUtil.ToString(obj["InstalledBy"]);
            }
            catch (Exception)
            {
                objEntHotfix.InstallBy = "";
            }

            try
            {
                string txtSPEffect = WMIUtil.ToString(obj["ServicePackInEffect"]);
                if ( txtSPEffect == "")
                {
                    txtSPEffect = " ";
                }
                objEntHotfix.SPEffect = txtSPEffect;
            }
            catch (Exception)
            {
                objEntHotfix.SPEffect = " ";
            }

            return objEntHotfix;
        }
Exemple #26
0
		public static EndpointAddress ToEndointAddress (ManagementBaseObject obj, bool isLocal)
		{
			EndpointAddressBuilder builder = new EndpointAddressBuilder();
			builder.Identity = new X509CertificateEndpointIdentity (new X509Certificate2 ("powershell.pfx", "mono"));
			foreach(var header in GetAddressHeaders(obj, isLocal))
			{
				builder.Headers.Add (header);
			}
			builder.Uri = new Uri(CimNamespaces.CimNamespace + "/" + obj.ClassPath.ClassName);
			return builder.ToEndpointAddress ();
		}
 public NetworkAdapterConfiguration(System.Management.ManagementObject theObject) {
     Initialize();
     if ((CheckIfProperClass(theObject) == true)) {
         PrivateLateBoundObject = theObject;
         PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject);
         curObj = PrivateLateBoundObject;
     }
     else {
         throw new System.ArgumentException("Class name does not match.");
     }
 }
Exemple #28
0
 private void InitializeObject(System.Management.ManagementScope mgmtScope, System.Management.ManagementPath path, System.Management.ObjectGetOptions getOptions)
 {
     Initialize();
     if ((path != null))
     {
         if ((CheckIfProperClass(mgmtScope, path, getOptions) != true))
         {
             throw new System.ArgumentException("Class name does not match.");
         }
     }
     PrivateLateBoundObject  = new System.Management.ManagementObject(mgmtScope, path, getOptions);
     PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject);
     curObj = PrivateLateBoundObject;
 }
 public Desktop(System.Management.ManagementObject theObject)
 {
     Initialize();
     if ((CheckIfProperClass(theObject) == true))
     {
         PrivateLateBoundObject  = theObject;
         PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject);
         curObj = PrivateLateBoundObject;
     }
     else
     {
         throw new System.ArgumentException("Class name does not match.");
     }
 }
Exemple #30
0
 public SystemAccount(System.Management.ManagementObject theObject)
 {
     Initialize();
     if ((CheckIfProperClass(theObject) == true))
     {
         PrivateLateBoundObject  = theObject;
         PrivateSystemProperties = new ManagementSystemProperties(PrivateLateBoundObject);
         curObj = PrivateLateBoundObject;
     }
     else
     {
         throw new System.ArgumentException("类名不匹配。");
     }
 }
Exemple #31
0
 protected override void OnAfterInstall(IDictionary savedState)
 {
     try
     {
         System.Management.ManagementObject myService = new System.Management.ManagementObject(
             string.Format("Win32_Service.Name='{0}'", this.serviceInstaller1.ServiceName));
         System.Management.ManagementBaseObject changeMethod = myService.GetMethodParameters("Change");
         changeMethod["DesktopInteract"] = true;
         System.Management.ManagementBaseObject OutParam = myService.InvokeMethod("Change", changeMethod, null);
     }
     catch (Exception)
     {
     }
     base.OnAfterInstall(savedState);
 }
Exemple #32
0
 public uint GetState(out uint State)
 {
     if ((isEmbedded == false))
     {
         System.Management.ManagementBaseObject inParams  = null;
         System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetState", inParams, null);
         State = System.Convert.ToUInt32(outParams.Properties["State"].Value);
         return(System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value));
     }
     else
     {
         State = System.Convert.ToUInt32(0);
         return(System.Convert.ToUInt32(0));
     }
 }
Exemple #33
0
 public SystemAccount(System.Management.ManagementBaseObject theObject)
 {
     Initialize();
     if ((CheckIfProperClass(theObject) == true))
     {
         embeddedObj             = theObject;
         PrivateSystemProperties = new ManagementSystemProperties(theObject);
         curObj     = embeddedObj;
         isEmbedded = true;
     }
     else
     {
         throw new System.ArgumentException("类名不匹配。");
     }
 }
Exemple #34
0
 public EnvironmentWmi(System.Management.ManagementBaseObject theObject)
 {
     Initialize();
     if ((CheckIfProperClass(theObject) == true))
     {
         embeddedObj             = theObject;
         PrivateSystemProperties = new ManagementSystemProperties(theObject);
         curObj     = embeddedObj;
         isEmbedded = true;
     }
     else
     {
         throw new System.ArgumentException("Class name does not match.");
     }
 }
 public bool EnumerateElementTypes(out uint[] Types)
 {
     if ((isEmbedded == false))
     {
         System.Management.ManagementBaseObject inParams  = null;
         System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("EnumerateElementTypes", inParams, null);
         Types = ((uint[])(outParams.Properties["Types"].Value));
         return(System.Convert.ToBoolean(outParams.Properties["ReturnValue"].Value));
     }
     else
     {
         Types = null;
         return(System.Convert.ToBoolean(0));
     }
 }
 public bool DeleteElement(uint Type)
 {
     if ((isEmbedded == false))
     {
         System.Management.ManagementBaseObject inParams = null;
         inParams         = PrivateLateBoundObject.GetMethodParameters("DeleteElement");
         inParams["Type"] = ((System.UInt32)(Type));
         System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("DeleteElement", inParams, null);
         return(System.Convert.ToBoolean(outParams.Properties["ReturnValue"].Value));
     }
     else
     {
         return(System.Convert.ToBoolean(0));
     }
 }
 public bool EnumerateObjects(uint Type, out System.Management.ManagementBaseObject[] Objects)
 {
     if ((isEmbedded == false))
     {
         System.Management.ManagementBaseObject inParams = null;
         inParams         = PrivateLateBoundObject.GetMethodParameters("EnumerateObjects");
         inParams["Type"] = ((System.UInt32)(Type));
         System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("EnumerateObjects", inParams, null);
         Objects = ((System.Management.ManagementBaseObject[])(outParams.Properties["Objects"].Value));
         return(System.Convert.ToBoolean(outParams.Properties["ReturnValue"].Value));
     }
     else
     {
         Objects = null;
         return(System.Convert.ToBoolean(0));
     }
 }
 public bool CopyObjects(uint Flags, string SourceStoreFile, uint Type)
 {
     if ((isEmbedded == false))
     {
         System.Management.ManagementBaseObject inParams = null;
         inParams                    = PrivateLateBoundObject.GetMethodParameters("CopyObjects");
         inParams["Flags"]           = ((System.UInt32)(Flags));
         inParams["SourceStoreFile"] = ((System.String)(SourceStoreFile));
         inParams["Type"]            = ((System.UInt32)(Type));
         System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("CopyObjects", inParams, null);
         return(System.Convert.ToBoolean(outParams.Properties["ReturnValue"].Value));
     }
     else
     {
         return(System.Convert.ToBoolean(0));
     }
 }
        public static bool DeleteSystemStore()
        {
            bool IsMethodStatic = true;

            if ((IsMethodStatic == true))
            {
                System.Management.ManagementBaseObject inParams  = null;
                System.Management.ManagementPath       mgmtPath  = new System.Management.ManagementPath(CreatedClassName);
                System.Management.ManagementClass      classObj  = new System.Management.ManagementClass(statMgmtScope, mgmtPath, null);
                System.Management.ManagementBaseObject outParams = classObj.InvokeMethod("DeleteSystemStore", inParams, null);
                return(System.Convert.ToBoolean(outParams.Properties["ReturnValue"].Value));
            }
            else
            {
                return(System.Convert.ToBoolean(0));
            }
        }
 public bool OpenObject(string Id, out System.Management.ManagementBaseObject Object)
 {
     if ((isEmbedded == false))
     {
         System.Management.ManagementBaseObject inParams = null;
         inParams       = PrivateLateBoundObject.GetMethodParameters("OpenObject");
         inParams["Id"] = ((System.String)(Id));
         System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("OpenObject", inParams, null);
         Object = ((System.Management.ManagementBaseObject)(outParams.Properties["Object"].Value));
         return(System.Convert.ToBoolean(outParams.Properties["ReturnValue"].Value));
     }
     else
     {
         Object = null;
         return(System.Convert.ToBoolean(0));
     }
 }
Exemple #41
0
 public uint Install(bool GrantLogOnAsService, string Logon, string Password)
 {
     if ((isEmbedded == false))
     {
         System.Management.ManagementBaseObject inParams = null;
         inParams = PrivateLateBoundObject.GetMethodParameters("Install");
         inParams["GrantLogOnAsService"] = ((bool)(GrantLogOnAsService));
         inParams["Logon"]    = ((string)(Logon));
         inParams["Password"] = ((string)(Password));
         System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("Install", inParams, null);
         return(System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value));
     }
     else
     {
         return(System.Convert.ToUInt32(0));
     }
 }
Exemple #42
0
        public static uint GetLastRestoreStatus()
        {
            bool IsMethodStatic = true;

            if ((IsMethodStatic == true))
            {
                System.Management.ManagementBaseObject inParams  = null;
                System.Management.ManagementPath       mgmtPath  = new System.Management.ManagementPath(CreatedClassName);
                System.Management.ManagementClass      classObj  = new System.Management.ManagementClass(statMgmtScope, mgmtPath, null);
                System.Management.ManagementBaseObject outParams = classObj.InvokeMethod("GetLastRestoreStatus", inParams, null);
                return(System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value));
            }
            else
            {
                return(System.Convert.ToUInt32(0));
            }
        }
 public bool SetDeviceElement(string AdditionalOptions, uint DeviceType, uint Type)
 {
     if ((isEmbedded == false))
     {
         System.Management.ManagementBaseObject inParams = null;
         inParams = PrivateLateBoundObject.GetMethodParameters("SetDeviceElement");
         inParams["AdditionalOptions"] = ((System.String)(AdditionalOptions));
         inParams["DeviceType"]        = ((System.UInt32)(DeviceType));
         inParams["Type"] = ((System.UInt32)(Type));
         System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetDeviceElement", inParams, null);
         return(System.Convert.ToBoolean(outParams.Properties["ReturnValue"].Value));
     }
     else
     {
         return(System.Convert.ToBoolean(0));
     }
 }
Exemple #44
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            System.Management.ConnectionOptions connOptions =
                new System.Management.ConnectionOptions();

            connOptions.Impersonation    = System.Management.ImpersonationLevel.Impersonate;
            connOptions.EnablePrivileges = true;
            connOptions.Username         = "******";
            connOptions.Password         = "******";

            string compName = "chan-PC";

            System.Management.ManagementScope manScope =
                new System.Management.ManagementScope(
                    String.Format(@"\\{0}\ROOT\CIMV2", compName), connOptions);
            manScope.Connect();

            System.Management.ObjectGetOptions objectGetOptions =
                new System.Management.ObjectGetOptions();

            System.Management.ManagementPath managementPath =
                new System.Management.ManagementPath("Win32_Process");

            System.Management.ManagementClass processClass =
                new System.Management.ManagementClass(manScope, managementPath, objectGetOptions);

            System.Management.ManagementBaseObject inParams =
                processClass.GetMethodParameters("Create");

            inParams["CommandLine"] = @"c:\MalCode\hiWinForm.exe";

            System.Management.ManagementBaseObject outParams =
                processClass.InvokeMethod("Create", inParams, null);

            var returnvalue = outParams["returnValue"];

            if (outParams["returnValue"].ToString().Equals("0"))
            {
                MessageBox.Show("Process execution returned " + unchecked ((int)outParams["returnValue"]));
            }
            else
            {
                MessageBox.Show("No type specified " + unchecked ((int)outParams["returnValue"]));
            }
        }
 public bool GetElementWithFlags(uint Flags, uint Type, out System.Management.ManagementBaseObject Element)
 {
     if ((isEmbedded == false))
     {
         System.Management.ManagementBaseObject inParams = null;
         inParams          = PrivateLateBoundObject.GetMethodParameters("GetElementWithFlags");
         inParams["Flags"] = ((System.UInt32)(Flags));
         inParams["Type"]  = ((System.UInt32)(Type));
         System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("GetElementWithFlags", inParams, null);
         Element = ((System.Management.ManagementBaseObject)(outParams.Properties["Element"].Value));
         return(System.Convert.ToBoolean(outParams.Properties["ReturnValue"].Value));
     }
     else
     {
         Element = null;
         return(System.Convert.ToBoolean(0));
     }
 }
 public bool SetQualifiedPartitionDeviceElement(string DiskSignature, string PartitionIdentifier, uint PartitionStyle, uint Type)
 {
     if ((isEmbedded == false))
     {
         System.Management.ManagementBaseObject inParams = null;
         inParams = PrivateLateBoundObject.GetMethodParameters("SetQualifiedPartitionDeviceElement");
         inParams["DiskSignature"]       = ((System.String)(DiskSignature));
         inParams["PartitionIdentifier"] = ((System.String)(PartitionIdentifier));
         inParams["PartitionStyle"]      = ((System.UInt32)(PartitionStyle));
         inParams["Type"] = ((System.UInt32)(Type));
         System.Management.ManagementBaseObject outParams = PrivateLateBoundObject.InvokeMethod("SetQualifiedPartitionDeviceElement", inParams, null);
         return(System.Convert.ToBoolean(outParams.Properties["ReturnValue"].Value));
     }
     else
     {
         return(System.Convert.ToBoolean(0));
     }
 }
Exemple #47
0
        public static uint Disable(string Drive)
        {
            bool IsMethodStatic = true;

            if ((IsMethodStatic == true))
            {
                System.Management.ManagementBaseObject inParams = null;
                System.Management.ManagementPath       mgmtPath = new System.Management.ManagementPath(CreatedClassName);
                System.Management.ManagementClass      classObj = new System.Management.ManagementClass(statMgmtScope, mgmtPath, null);
                inParams          = classObj.GetMethodParameters("Disable");
                inParams["Drive"] = ((System.String)(Drive));
                System.Management.ManagementBaseObject outParams = classObj.InvokeMethod("Disable", inParams, null);
                return(System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value));
            }
            else
            {
                return(System.Convert.ToUInt32(0));
            }
        }
        public static bool GetSystemPartition(out string Partition)
        {
            bool IsMethodStatic = true;

            if ((IsMethodStatic == true))
            {
                System.Management.ManagementBaseObject inParams  = null;
                System.Management.ManagementPath       mgmtPath  = new System.Management.ManagementPath(CreatedClassName);
                System.Management.ManagementClass      classObj  = new System.Management.ManagementClass(statMgmtScope, mgmtPath, null);
                System.Management.ManagementBaseObject outParams = classObj.InvokeMethod("GetSystemPartition", inParams, null);
                Partition = System.Convert.ToString(outParams.Properties["Partition"].Value);
                return(System.Convert.ToBoolean(outParams.Properties["ReturnValue"].Value));
            }
            else
            {
                Partition = null;
                return(System.Convert.ToBoolean(0));
            }
        }
Exemple #49
0
        public static uint Restore(uint SequenceNumber)
        {
            bool IsMethodStatic = true;

            if ((IsMethodStatic == true))
            {
                System.Management.ManagementBaseObject inParams = null;
                System.Management.ManagementPath       mgmtPath = new System.Management.ManagementPath(CreatedClassName);
                System.Management.ManagementClass      classObj = new System.Management.ManagementClass(statMgmtScope, mgmtPath, null);
                inParams = classObj.GetMethodParameters("Restore");
                inParams["SequenceNumber"] = ((System.UInt32)(SequenceNumber));
                System.Management.ManagementBaseObject outParams = classObj.InvokeMethod("Restore", inParams, null);
                return(System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value));
            }
            else
            {
                return(System.Convert.ToUInt32(0));
            }
        }
        public static bool ImportStore(string File)
        {
            bool IsMethodStatic = true;

            if ((IsMethodStatic == true))
            {
                System.Management.ManagementBaseObject inParams = null;
                System.Management.ManagementPath       mgmtPath = new System.Management.ManagementPath(CreatedClassName);
                System.Management.ManagementClass      classObj = new System.Management.ManagementClass(statMgmtScope, mgmtPath, null);
                inParams         = classObj.GetMethodParameters("ImportStore");
                inParams["File"] = ((System.String)(File));
                System.Management.ManagementBaseObject outParams = classObj.InvokeMethod("ImportStore", inParams, null);
                return(System.Convert.ToBoolean(outParams.Properties["ReturnValue"].Value));
            }
            else
            {
                return(System.Convert.ToBoolean(0));
            }
        }
Exemple #51
0
        public static uint CreateRestorePoint(string Description, uint EventType, uint RestorePointType)
        {
            bool IsMethodStatic = true;

            if ((IsMethodStatic == true))
            {
                System.Management.ManagementBaseObject inParams = null;
                System.Management.ManagementPath       mgmtPath = new System.Management.ManagementPath(CreatedClassName);
                System.Management.ManagementClass      classObj = new System.Management.ManagementClass(statMgmtScope, mgmtPath, null);
                inParams = classObj.GetMethodParameters("CreateRestorePoint");
                inParams["Description"]      = ((System.String)(Description));
                inParams["EventType"]        = ((System.UInt32)(EventType));
                inParams["RestorePointType"] = ((System.UInt32)(RestorePointType));
                System.Management.ManagementBaseObject outParams = classObj.InvokeMethod("CreateRestorePoint", inParams, null);
                return(System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value));
            }
            else
            {
                return(System.Convert.ToUInt32(0));
            }
        }
Exemple #52
0
        public void SendCommand(string hostname, string command, Credential credential)
        {
            ConnectionOptions connectoptions = GetConnectionOptions(hostname, credential);

            connectoptions.Impersonation = System.Management.ImpersonationLevel.Impersonate;

            System.Management.ManagementScope mgmtScope = new System.Management.ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", hostname), connectoptions);
            mgmtScope.Connect();
            System.Management.ObjectGetOptions     objectGetOptions = new System.Management.ObjectGetOptions();
            System.Management.ManagementPath       mgmtPath         = new System.Management.ManagementPath("Win32_Process");
            System.Management.ManagementClass      processClass     = new System.Management.ManagementClass(mgmtScope, mgmtPath, objectGetOptions);
            System.Management.ManagementBaseObject inParams         = processClass.GetMethodParameters("Create");
            ManagementClass startupInfo = new ManagementClass("Win32_ProcessStartup");

            startupInfo.Properties["ShowWindow"].Value = 0;

            inParams["CommandLine"] = command;
            inParams["ProcessStartupInformation"] = startupInfo;

            processClass.InvokeMethod("Create", inParams, null);
        }
        public static uint Create(string Description, string DfsEntryPath, string ServerName, string ShareName)
        {
            bool IsMethodStatic = true;

            if ((IsMethodStatic == true))
            {
                System.Management.ManagementBaseObject inParams = null;
                System.Management.ManagementPath       mgmtPath = new System.Management.ManagementPath(CreatedClassName);
                System.Management.ManagementClass      classObj = new System.Management.ManagementClass(statMgmtScope, mgmtPath, null);
                inParams = classObj.GetMethodParameters("Create");
                inParams["Description"]  = ((System.String)(Description));
                inParams["DfsEntryPath"] = ((System.String)(DfsEntryPath));
                inParams["ServerName"]   = ((System.String)(ServerName));
                inParams["ShareName"]    = ((System.String)(ShareName));
                System.Management.ManagementBaseObject outParams = classObj.InvokeMethod("Create", inParams, null);
                return(System.Convert.ToUInt32(outParams.Properties["ReturnValue"].Value));
            }
            else
            {
                return(System.Convert.ToUInt32(0));
            }
        }
Exemple #54
0
 public bool SetIntegerElement(UInt64 Integer, uint TypeId)
 {
     Log.Logger.Info("Entering SetIntegerElement");
     Log.Logger.Info(string.Format("Type : {0:X}", TypeId));
     Log.Logger.Info("Integer : " + Integer);
     System.Management.ManagementBaseObject inParams = InternalObject.GetMethodParameters("SetIntegerElement");
     inParams["Integer"] = Integer;
     inParams["Type"]    = TypeId;
     System.Management.ManagementBaseObject outParams = InternalObject.InvokeMethod("SetIntegerElement", inParams, null);
     if (System.Convert.ToBoolean(outParams.Properties["ReturnValue"].Value) == true)
     {
         Log.Logger.Info("Succeeded to call SetIntegerElement");
         if (!this.elements.ContainsKey(TypeId))
         {
             this.elements.Add(TypeId, this.GetElement(TypeId));
         }
         Log.Logger.Info("Leaving SetIntegerElement");
         return(true);
     }
     Log.Logger.Info("Leaving SetIntegerElement with false.");
     return(false);
 }
Exemple #55
0
 private bool CheckIfProperClass(System.Management.ManagementBaseObject theObj)
 {
     if (((theObj != null) &&
          (string.Compare(((string)(theObj["__CLASS"])), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)))
     {
         return(true);
     }
     else
     {
         System.Array parentClasses = ((System.Array)(theObj["__DERIVATION"]));
         if ((parentClasses != null))
         {
             int count = 0;
             for (count = 0; (count < parentClasses.Length); count = (count + 1))
             {
                 if ((string.Compare(((string)(parentClasses.GetValue(count))), this.ManagementClassName, true, System.Globalization.CultureInfo.InvariantCulture) == 0))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Exemple #56
0
 public bool DeleteElement(uint Type)
 {
     Log.Logger.Info("Entering DeleteElement");
     Log.Logger.Info(string.Format("Type : {0:X}", Type));
     if (elements.ContainsKey(Type))
     {
         System.Management.ManagementBaseObject inParams = InternalObject.GetMethodParameters("DeleteElement");
         inParams["Type"] = ((System.UInt32)(Type));
         System.Management.ManagementBaseObject outParams = InternalObject.InvokeMethod("DeleteElement", inParams, null);
         if (true == System.Convert.ToBoolean(outParams.Properties["ReturnValue"].Value))
         {
             Log.Logger.Info("Succeeded to call DeleteElement");
             this.elements.Remove(Type);
         }
         Log.Logger.Info("Leaving DeleteElement.");
         return(true);
     }
     else
     {
         Log.Logger.Info(string.Format("No element with type : {0:X} found.", Type));
     }
     Log.Logger.Info("Leaving DeleteElement with false.");
     return(false);
 }
Exemple #57
0
 public ManagementSystemProperties(System.Management.ManagementBaseObject ManagedObject)
 {
     PrivateLateBoundObject = ManagedObject;
 }
 public bool CompareTo(ManagementBaseObject otherObject, ComparisonSettings settings)
 {
     if (otherObject == null)
     {
         throw new ArgumentNullException("otherObject");
     }
     bool flag = false;
     if (this.wbemObject != null)
     {
         int errorCode = 0;
         errorCode = this.wbemObject.CompareTo_((int) settings, otherObject.wbemObject);
         if (0x40003 == errorCode)
         {
             return false;
         }
         if (errorCode == 0)
         {
             return true;
         }
         if ((errorCode & 0xfffff000L) == 0x80041000L)
         {
             ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
             return flag;
         }
         if (errorCode < 0)
         {
             Marshal.ThrowExceptionForHR(errorCode);
         }
     }
     return flag;
 }
Exemple #59
-1
        public static string GetDriveLetter(ManagementBaseObject instance)
        {
            var tmp = new ManagementObjectSearcher("select * from Win32_DiskDrive where InterfaceType='USB'").Get();
            var deviceid = instance["DeviceID"].ToString();
            foreach (var drive in tmp)
            {
                if(drive["PNPDeviceID"].ToString().Contains(deviceid.Remove(0,deviceid.LastIndexOf("\\")+1)))
                {
                    ManagementObject partition = new ManagementObjectSearcher(String.Format(
            "associators of {{Win32_DiskDrive.DeviceID='{0}'}} " +
                  "where AssocClass = Win32_DiskDriveToDiskPartition",
            drive["DeviceID"])).First();

                    if (partition != null)
                    {
                        // associate partitions with logical disks (drive letter volumes)
                        ManagementObject logical = new ManagementObjectSearcher(String.Format(
                            "associators of {{Win32_DiskPartition.DeviceID='{0}'}} " +
                                "where AssocClass= Win32_LogicalDiskToPartition",
                            partition["DeviceID"])).First();

                        if (logical != null)
                        {
                            // finally find the logical disk entry

                            return logical["Name"].ToString();
                        }
                    }
                }
            }
            return "NotFound";
        }
 void watcher_EventArrived(object sender,
                           EventArrivedEventArgs args)
 {
     wmiLogged = true;
     wmiResult = args.NewEvent.GetText(TextFormat.Mof);
     wmiLogEntry = args.NewEvent;
 }