diff --git a/WmiLight.Native/WmiLight.Native.rc b/WmiLight.Native/WmiLight.Native.rc index 0e0577f..9488db7 100644 --- a/WmiLight.Native/WmiLight.Native.rc +++ b/WmiLight.Native/WmiLight.Native.rc @@ -43,8 +43,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 6,9,1,0 - PRODUCTVERSION 6,9,1,0 + FILEVERSION 6,10,0,0 + PRODUCTVERSION 6,10,0,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -70,12 +70,12 @@ BEGIN VALUE "FileDescription", "The native part of the WmiLight lib." #endif - VALUE "FileVersion", "6.9.1.0" + VALUE "FileVersion", "6.10.0.0" VALUE "InternalName", "WmiLight.Native" VALUE "LegalCopyright", "Copyright 2024 Martin Kuschnik" VALUE "OriginalFilename", "WmiLight.Native.dll" VALUE "ProductName", "WmiLight" - VALUE "ProductVersion", "6.9.1.0" + VALUE "ProductVersion", "6.10.0.0" END END BLOCK "VarFileInfo" diff --git a/WmiLight.Native/WmiLightNative.cpp b/WmiLight.Native/WmiLightNative.cpp index 3563d6b..a1db297 100644 --- a/WmiLight.Native/WmiLightNative.cpp +++ b/WmiLight.Native/WmiLightNative.cpp @@ -305,6 +305,14 @@ extern "C" { // only need to export C interface if return pClassObject->Put(wszName, 0, pVal, type); } + __declspec(dllexport) HRESULT _stdcall PutInstance(IWbemServices* wbemServices, IWbemClassObject* pInst, IWbemContext* ctx) + { + if (wbemServices == nullptr) + return E_POINTER; + + return wbemServices->PutInstance(pInst, WBEM_FLAG_CREATE_OR_UPDATE, ctx, nullptr); + } + __declspec(dllexport) HRESULT _stdcall ExecMethod( IWbemServices* wbemServices, wchar_t* classNameOrPath, diff --git a/WmiLight/Internal/NativeMethods.cs b/WmiLight/Internal/NativeMethods.cs index a19de85..c70b9fc 100644 --- a/WmiLight/Internal/NativeMethods.cs +++ b/WmiLight/Internal/NativeMethods.cs @@ -138,6 +138,9 @@ public static extern HResult Get( [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.StdCall)] public static extern HResult Put(IntPtr pClassObject, [MarshalAs(UnmanagedType.LPWStr)] string wszName, ref VARIANT pvar, CimType cimType); + + [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.StdCall)] + public static extern HResult PutInstance(IntPtr pWbemServices, IntPtr pInst, IntPtr ctx); [DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.StdCall)] public static extern HResult GetType(IntPtr pClassObject, [MarshalAs(UnmanagedType.LPWStr)] string propertyName, out CimType cimType); diff --git a/WmiLight/Wbem/WbemServices.cs b/WmiLight/Wbem/WbemServices.cs index d8fecb4..008c2e9 100644 --- a/WmiLight/Wbem/WbemServices.cs +++ b/WmiLight/Wbem/WbemServices.cs @@ -70,6 +70,17 @@ internal WbemClassObjectEnumerator ExecQuery(string query, WbemClassObjectEnumer return new WbemClassObjectEnumerator(pEnumerator); } + internal void PutInstance(WbemClassObject wbemClassObject, IntPtr ctx) + { + if (this.Disposed) + throw new ObjectDisposedException(nameof(WbemServices)); + + HResult hResult = NativeMethods.PutInstance(this, wbemClassObject, ctx); + + if (hResult.Failed) + throw (Exception)hResult; + } + internal void ExecNotificationQueryAsync(string query, IntPtr ctx, WbemObjectSink sink) { if (this.Disposed) diff --git a/WmiLight/WmiLight.csproj b/WmiLight/WmiLight.csproj index 1ea15d7..de444e3 100644 --- a/WmiLight/WmiLight.csproj +++ b/WmiLight/WmiLight.csproj @@ -23,7 +23,7 @@ - 6.9.1 + 6.10.0 WmiLight Martin Kuschnik Martin Kuschnik diff --git a/WmiLight/WmiMethodParameters.cs b/WmiLight/WmiMethodParameters.cs index 8c616e7..d9069b6 100644 --- a/WmiLight/WmiMethodParameters.cs +++ b/WmiLight/WmiMethodParameters.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics; -using System.Linq; using WmiLight.Wbem; namespace WmiLight @@ -21,136 +20,10 @@ internal WmiMethodParameters(WbemServices wbemServices, WbemClassObject signatur this.signatur = signatur ?? throw new ArgumentNullException(nameof(signatur)); } - #region Description - /// - /// Sets the value of a property. - /// - /// The name of the property that should be changed. - /// The new property value. - #endregion - public void SetPropertyValue(string propertyName, sbyte propertyValue) - { - this.signatur.Put(propertyName, propertyValue); - } - - #region Description - /// - /// Sets the value of a property. - /// - /// The name of the property that should be changed. - /// The new property value. - #endregion - public void SetPropertyValue(string propertyName, byte propertyValue) - { - this.signatur.Put(propertyName, propertyValue); - } - - #region Description - /// - /// Sets the value of a property. - /// - /// The name of the property that should be changed. - /// The new property value. - #endregion - public void SetPropertyValue(string propertyName, short propertyValue) - { - this.signatur.Put(propertyName, propertyValue); - } - - #region Description - /// - /// Sets the value of a property. - /// - /// The name of the property that should be changed. - /// The new property value. - #endregion - public void SetPropertyValue(string propertyName, ushort propertyValue) - { - this.signatur.Put(propertyName, propertyValue); - } - - #region Description - /// - /// Sets the value of a property. - /// - /// The name of the property that should be changed. - /// The new property value. - #endregion - public void SetPropertyValue(string propertyName, int propertyValue) - { - this.signatur.Put(propertyName, propertyValue); - } - - #region Description - /// - /// Sets the value of a property. - /// - /// The name of the property that should be changed. - /// The new property value. - #endregion - public void SetPropertyValue(string propertyName, uint propertyValue) - { - this.signatur.Put(propertyName, propertyValue); - } - - #region Description - /// - /// Sets the value of a property. - /// - /// The name of the property that should be changed. - /// The new property value. - #endregion - public void SetPropertyValue(string propertyName, long propertyValue) - { - this.signatur.Put(propertyName, propertyValue); - } - - #region Description - /// - /// Sets the value of a property. - /// - /// The name of the property that should be changed. - /// The new property value. - #endregion - public void SetPropertyValue(string propertyName, ulong propertyValue) - { - this.signatur.Put(propertyName, propertyValue); - } - - #region Description - /// - /// Sets the value of a property. - /// - /// The name of the property that should be changed. - /// The new property value. - #endregion - public void SetPropertyValue(string propertyName, bool propertyValue) - { - this.signatur.Put(propertyName, propertyValue); - } - - #region Description - /// - /// Sets the value of a property. - /// - /// The name of the property that should be changed. - /// The new property value. - #endregion - public void SetPropertyValue(string propertyName, string propertyValue) - { - this.signatur.Put(propertyName, propertyValue); - } - - #region Description - /// - /// Sets the value of a property. - /// - /// The name of the property that should be changed. - /// The new property value. - #endregion - public void SetPropertyValue(string propertyName, string[] propertyValue) + /// + public override void Put() { - this.signatur.Put(propertyName, propertyValue); + throw new NotSupportedException(); } #region Description diff --git a/WmiLight/WmiObject.cs b/WmiLight/WmiObject.cs index c1e61ee..4856d71 100644 --- a/WmiLight/WmiObject.cs +++ b/WmiLight/WmiObject.cs @@ -324,6 +324,150 @@ public TResult GetPropertyValue(string propertyName) return wbemClassObject.Get(propertyName); } + + + #region Description + /// + /// Sets the value of a property. + /// + /// The name of the property that should be changed. + /// The new property value. + #endregion + public void SetPropertyValue(string propertyName, sbyte propertyValue) + { + this.wbemClassObject.Put(propertyName, propertyValue); + } + + #region Description + /// + /// Sets the value of a property. + /// + /// The name of the property that should be changed. + /// The new property value. + #endregion + public void SetPropertyValue(string propertyName, byte propertyValue) + { + this.wbemClassObject.Put(propertyName, propertyValue); + } + + #region Description + /// + /// Sets the value of a property. + /// + /// The name of the property that should be changed. + /// The new property value. + #endregion + public void SetPropertyValue(string propertyName, short propertyValue) + { + this.wbemClassObject.Put(propertyName, propertyValue); + } + + #region Description + /// + /// Sets the value of a property. + /// + /// The name of the property that should be changed. + /// The new property value. + #endregion + public void SetPropertyValue(string propertyName, ushort propertyValue) + { + this.wbemClassObject.Put(propertyName, propertyValue); + } + + #region Description + /// + /// Sets the value of a property. + /// + /// The name of the property that should be changed. + /// The new property value. + #endregion + public void SetPropertyValue(string propertyName, int propertyValue) + { + this.wbemClassObject.Put(propertyName, propertyValue); + } + + #region Description + /// + /// Sets the value of a property. + /// + /// The name of the property that should be changed. + /// The new property value. + #endregion + public void SetPropertyValue(string propertyName, uint propertyValue) + { + this.wbemClassObject.Put(propertyName, propertyValue); + } + + #region Description + /// + /// Sets the value of a property. + /// + /// The name of the property that should be changed. + /// The new property value. + #endregion + public void SetPropertyValue(string propertyName, long propertyValue) + { + this.wbemClassObject.Put(propertyName, propertyValue); + } + + #region Description + /// + /// Sets the value of a property. + /// + /// The name of the property that should be changed. + /// The new property value. + #endregion + public void SetPropertyValue(string propertyName, ulong propertyValue) + { + this.wbemClassObject.Put(propertyName, propertyValue); + } + + #region Description + /// + /// Sets the value of a property. + /// + /// The name of the property that should be changed. + /// The new property value. + #endregion + public void SetPropertyValue(string propertyName, bool propertyValue) + { + this.wbemClassObject.Put(propertyName, propertyValue); + } + + #region Description + /// + /// Sets the value of a property. + /// + /// The name of the property that should be changed. + /// The new property value. + #endregion + public void SetPropertyValue(string propertyName, string propertyValue) + { + this.wbemClassObject.Put(propertyName, propertyValue); + } + + #region Description + /// + /// Sets the value of a property. + /// + /// The name of the property that should be changed. + /// The new property value. + #endregion + public void SetPropertyValue(string propertyName, string[] propertyValue) + { + this.wbemClassObject.Put(propertyName, propertyValue); + } + + #region Description + /// + /// Commits the changes to the object. + /// + #endregion + public virtual void Put() + { + this.wbemServices.PutInstance(this.wbemClassObject, IntPtr.Zero); + } + #region Description /// /// Executes a static WMI method.