Hello I am trying to use wmi code for my app and would like to know if there is an activate command similar to the slmgr - ato command for windows? Thanks Flare4000
I manage to covert most of the code to vb.net although I can't get the loop to work. Here is vb.net Code: Dim classInstance As ManagementObject Dim outParams As ManagementBaseObject Dim inParams As ManagementBaseObject ' Get Windows Version To Pass It To Future proof code from version changes (Like Service Packs) Dim WinVersion As String = String.Empty Try Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM SoftwareLicensingService") For Each queryObj As ManagementObject In searcher.[Get]() WinVersion = Convert.ToString(queryObj("Version")) Next Catch generatedExceptionName As Exception End Try ' Set Windows KMS Host Try classInstance = New ManagementObject("root\CIMV2", "SoftwareLicensingService.Version='" + WinVersion + "'", Nothing) ' Obtain in-parameters for the method inParams = classInstance.GetMethodParameters("SetKeyManagementServiceMachine") ' Add the input parameters. inParams("MachineName") = "127.0.0.1" Catch Err As Exception End Try ' Execute the method and obtain the return values. Try outParams = classInstance.InvokeMethod("SetKeyManagementServiceMachine", inParams, Nothing) Catch generatedExceptionName As Exception End Try ' Determine the SKUID of the active Windows license (We need it to call Activate via WMI) Dim SKUID As String = String.Empty Try Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM SoftwareLicensingProduct") For Each queryObj As ManagementObject In searcher.[Get]() SKUID = Convert.ToString(queryObj("ID")) Dim LicStatus As Integer = Convert.ToInt32(queryObj("LicenseStatus")) ' Zero means the license is not active, 1 means it is. Only 1 Windows key should be active so stop the loop when we don't get a zero. If LicStatus <> 0 Then Exit For End If Next Catch generatedExceptionName As Exception End Try ' Activate (Uses Loop to retry for KMS) Dim [loop] As Integer = 1 Dim success As Boolean = False classInstance = New ManagementObject("root\CIMV2", "SoftwareLicensingProduct.ID='" + SKUID + "'", Nothing) outParams = classInstance.InvokeMethod("Activate", Nothing, Nothing) success = True classInstance.InvokeMethod("ClearKeyManagementServiceMachine", Nothing, Nothing) End Sub
Ya I'm trying to eliminate the use of slmgr I might just use your code for the loop and convert the 50% of the kms in my app to C# lol since the loop is important for kms
Your code is very enlightening. You use Code: Settings.AutoKMSSettings which comes from another library, i guess. Is it also available in C# somewhere? I searched but i didn't find anything.