rudi Posted April 27, 2012 Share Posted April 27, 2012 (edited) Hi.As a "Checklist Verifyer" I'm doing a Autoit Script, checkin many things, that have to be done, befor the PCs are deployed to the network.One point, that has been missed several times is, that Windows 7 or Office 2010 were *NOT ACTIVATED*.So I'm wondering, if somebody knows howto simply check the ACTIVATION STATUS of Win7 and Office 2010:activated yes/nolicense key present yes/no(The slmgr.vbs commands to fix it, in case license key or activation were missed, are not the problem [1])Thanks for any suggestions, Rudi.[1]start /w slmgr /upkstart /w slmgr /ipk LICEN-SEKEY-GOES-HERE-TEXTstart slmgr /atoedit: typo Edited April 27, 2012 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 27, 2012 Moderators Share Posted April 27, 2012 I know that Office 2010 comes with the ospp.vbs script that will do this for you, not sure about 2007 (Office 2010 install directoryOffice12ospp.vbs), run with the /dstatus switch to find license status. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
NDog Posted July 2, 2012 Share Posted July 2, 2012 (edited) Here's how you do it via WMI. expandcollapse popupIf IsActivated() = False Then ;InstallProductKey($OSkey) ; installs a product key and also activates it Else Return EndIf If OfficeIsActivated() = False Then ;InstallOfficeProductKey($officekey) ; installs a product key and also activates it Else Return EndIf Func IsActivated() $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Description, LicenseStatus, GracePeriodRemaining FROM SoftwareLicensingProduct WHERE PartialProductKey <> null") If IsObj($oCollection) Then For $oItem In $oCollection Switch $oItem.LicenseStatus Case 0 ConsoleWrite("Unlicensed" & @CRLF) Return False Case 1 If $oItem.GracePeriodRemaining Then If StringInStr($oItem.Description, "TIMEBASED_") Then ConsoleWrite("Timebased activation will expire in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Else ConsoleWrite("Volume activation will expire in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False EndIf Else ConsoleWrite("The machine is permanently activated." & @CRLF) Return True EndIf Case 2 ConsoleWrite("Initial grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 3 ConsoleWrite("Additional grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 4 ConsoleWrite("Non-genuine grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 5 ConsoleWrite("Windows is in Notification mode" & @CRLF) Return False Case 6 ConsoleWrite("Extended grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False EndSwitch Next EndIf EndIf EndFunc Func OfficeIsActivated() $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Description, LicenseStatus, GracePeriodRemaining FROM OfficeSoftwareProtectionProduct WHERE PartialProductKey <> null") If IsObj($oCollection) Then For $oItem In $oCollection Switch $oItem.LicenseStatus Case 0 ConsoleWrite(" ---UNLICENSED--- " & @CRLF) Return False Case 1 ConsoleWrite(" ---LICENSED--- " & @CRLF) ;If licSr = 0 Then ; WScript.Echo MSG_ERRCODE & licSr & " as licensed" ;End If Return True Case 2 ConsoleWrite("---OOB_GRACE--- Initial grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 3 ConsoleWrite("---OOT_GRACE--- Initial grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 4 ConsoleWrite("---NON_GENUINE_GRACE--- Grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 5 ConsoleWrite("---NOTIFICATIONS--- Grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 6 ConsoleWrite("---EXTENDED GRACE--- Extended grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case Else ConsoleWrite("---UNKNOWN---" & @CRLF) Return False EndSwitch Next EndIf EndIf EndFunc If you are interested I will give you the code to activate it directly through WMI as well. Edited July 2, 2012 by NDog Link to comment Share on other sites More sharing options...
nobles Posted October 18, 2012 Share Posted October 18, 2012 Can somebody supply the code to activate Windows through WMI as was mentioned above? Link to comment Share on other sites More sharing options...
NDog Posted October 28, 2012 Share Posted October 28, 2012 Here you go. The IsActivated() Function was written by trancexx (who never replies to PM's TT), and the rest I wrote. I think the Windows XP activation part is a bit broken, maybe someone can check it. Part of this code block here has missing proxy gateway authentication stuff, which may get added eventually. It also has offline token restore for Office 2010 activation, but that is a whole lot more complex and I have not included it here. Please add improvements if you have any. expandcollapse popup$OSkey = "ZZZZZ-VVVVV-XXXXX-VVVVV-ZZZZZ" $officekey = "ZZZZZ-VVVVV-XXXXX-VVVVV-ZZZZZ" ; For WPA activation Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling. $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler ; Detect OS version If @OSVersion == "WIN_8" Or @OSVersion == "WIN_7" Or @OSVersion == "WIN_VISTA" Or @OSVersion = "WIN_2008" Then $OS = 'NT6' ElseIf @OSVersion == "WIN_XP" Then $OS = 'NT5' Else MsgBox(48, "Error", "Wrong OS version") Exit EndIf If IsDeclared('OSkey') Then OSactivate() If IsDeclared('officekey') Then Officeactivate() Func OSactivate() If $OS = 'NT6' Then ; First attempt - go out to the internet directly If IsActivated() = False Then InstallProductKey($OSkey) ; installs a product key and also activates it Else Return EndIf ; Second attempt - set the gateway as the proxy and go to .microsoft.com out the proxy If IsActivated() = False Then ;setgatewayproxy("on") InstallProductKey($OSkey) ; installs a product key and also activates it ;setgatewayproxy("off") Else Return EndIf ; Third attempt - proxy out through gateway using a user/pass combo If IsActivated() = False Then ;setgatewayproxy("on","user","password") InstallProductKey($OSkey) ; installs a product key and also activates it ;setgatewayproxy("off") Else Return EndIf ElseIf $OS = 'NT5' Then $VOL_PROD_KEY = StringReplace($OSkey,"-","") ;remove hyphens if any $x = ObjGet("winmgmts:{impersonationLevel=impersonate}") $y = $x.InstancesOf ("win32_WindowsProductActivation") For $Obj In $y $result = $Obj.SetProductKey ($VOL_PROD_KEY) If $g_eventerror then Msgbox(0,"","The key used is not valid - " & $VOL_PROD_KEY) Next EndIf EndFunc Func IsActivated() $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Description, LicenseStatus, GracePeriodRemaining FROM SoftwareLicensingProduct WHERE PartialProductKey <> null") If IsObj($oCollection) Then For $oItem In $oCollection Switch $oItem.LicenseStatus Case 0 ConsoleWrite("Unlicensed" & @CRLF) Return False Case 1 If $oItem.GracePeriodRemaining Then If StringInStr($oItem.Description, "TIMEBASED_") Then ConsoleWrite("Timebased activation will expire in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Else ConsoleWrite("Volume activation will expire in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False EndIf Else ConsoleWrite("The machine is permanently activated." & @CRLF) Return True EndIf Case 2 ConsoleWrite("Initial grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 3 ConsoleWrite("Additional grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 4 ConsoleWrite("Non-genuine grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 5 ConsoleWrite("Windows is in Notification mode" & @CRLF) Return False Case 6 ConsoleWrite("Extended grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False EndSwitch Next EndIf EndIf EndFunc Func InstallProductKey($strProductKey) $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Version FROM SoftwareLicensingService") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite($oItem.Version & @CRLF) $oItem.InstallProductKey($strProductKey) If $g_eventerror then Return ActivateProduct() Next EndIf EndIf EndFunc Func ActivateProduct() $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT ID, ApplicationId, PartialProductKey, LicenseIsAddon, Description, Name, LicenseStatus FROM SoftwareLicensingProduct WHERE PartialProductKey <> null") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite($oItem.Name & @CRLF) ConsoleWrite($oItem.ID & @CRLF) $oItem.Activate() If $g_eventerror then Return RefreshStatus() ; Needed otherwise windows complains about non genuine key and changes background to black $oItem.refresh_ Next EndIf EndIf EndFunc Func RefreshStatus() $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Version FROM SoftwareLicensingService") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite("Refresh Status" & @CRLF) $oItem.RefreshLicenseStatus() Next EndIf EndIf EndFunc Func Officeactivate() ; First attempt - go out to the internet directly If OfficeIsActivated() = False Then InstallOfficeProductKeyActivateInternet($officekey) ; installs a product key and also activates it Else Return EndIf EndFunc Func OfficeIsActivated() $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Description, LicenseStatus, GracePeriodRemaining FROM OfficeSoftwareProtectionProduct WHERE PartialProductKey <> null") If IsObj($oCollection) Then For $oItem In $oCollection Switch $oItem.LicenseStatus Case 0 ConsoleWrite(" ---UNLICENSED--- " & @CRLF) Return False Case 1 ConsoleWrite(" ---LICENSED--- " & @CRLF) ;If licSr = 0 Then ; WScript.Echo MSG_ERRCODE & licSr & " as licensed" ;End If Return True Case 2 ConsoleWrite("---OOB_GRACE--- Initial grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 3 ConsoleWrite("---OOT_GRACE--- Initial grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 4 ConsoleWrite("---NON_GENUINE_GRACE--- Grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 5 ConsoleWrite("---NOTIFICATIONS--- Grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 6 ConsoleWrite("---EXTENDED GRACE--- Extended grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case Else ConsoleWrite("---UNKNOWN---" & @CRLF) Return False EndSwitch Next EndIf EndIf EndFunc Func InstallOfficeProductKeyOnly($strProductKey) $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Version FROM OfficeSoftwareProtectionService") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite($oItem.Version & @CRLF) $oItem.InstallProductKey($strProductKey) If $g_eventerror then Return Next EndIf EndIf EndFunc Func InstallOfficeProductKeyActivateInternet($strProductKey) $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Version FROM OfficeSoftwareProtectionService") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite($oItem.Version & @CRLF) $oItem.InstallProductKey($strProductKey) If $g_eventerror then Return ActivateOfficeProduct() Next EndIf EndIf EndFunc Func ActivateOfficeProduct() $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT ID, ApplicationId, PartialProductKey, LicenseIsAddon, Description, Name, LicenseStatus FROM OfficeSoftwareProtectionProduct WHERE PartialProductKey <> null") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite($oItem.Name & @CRLF) ConsoleWrite($oItem.ID & @CRLF) $oItem.Activate() If $g_eventerror then Return RefreshOfficeStatus() ; Needed to refresh status $oItem.refresh_ Next EndIf EndIf EndFunc Func RefreshOfficeStatus() $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Version FROM OfficeSoftwareProtectionService") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite("Refresh Status" & @CRLF) $oItem.RefreshLicenseStatus() Next EndIf EndIf EndFunc Link to comment Share on other sites More sharing options...
LynnS Posted September 15, 2014 Share Posted September 15, 2014 NDog, thank you very much for posting that code! Link to comment Share on other sites More sharing options...
phucbk2344 Posted August 14, 2019 Share Posted August 14, 2019 On 10/28/2012 at 1:55 PM, NDog said: Here you go. The IsActivated() Function was written by trancexx (who never replies to PM's TT), and the rest I wrote. I think the Windows XP activation part is a bit broken, maybe someone can check it. Part of this code block here has missing proxy gateway authentication stuff, which may get added eventually. It also has offline token restore for Office 2010 activation, but that is a whole lot more complex and I have not included it here. Please add improvements if you have any. expandcollapse popup$OSkey = "ZZZZZ-VVVVV-XXXXX-VVVVV-ZZZZZ" $officekey = "ZZZZZ-VVVVV-XXXXX-VVVVV-ZZZZZ" ; For WPA activation Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling. $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler ; Detect OS version If @OSVersion == "WIN_8" Or @OSVersion == "WIN_7" Or @OSVersion == "WIN_VISTA" Or @OSVersion = "WIN_2008" Then $OS = 'NT6' ElseIf @OSVersion == "WIN_XP" Then $OS = 'NT5' Else MsgBox(48, "Error", "Wrong OS version") Exit EndIf If IsDeclared('OSkey') Then OSactivate() If IsDeclared('officekey') Then Officeactivate() Func OSactivate() If $OS = 'NT6' Then ; First attempt - go out to the internet directly If IsActivated() = False Then InstallProductKey($OSkey) ; installs a product key and also activates it Else Return EndIf ; Second attempt - set the gateway as the proxy and go to .microsoft.com out the proxy If IsActivated() = False Then ;setgatewayproxy("on") InstallProductKey($OSkey) ; installs a product key and also activates it ;setgatewayproxy("off") Else Return EndIf ; Third attempt - proxy out through gateway using a user/pass combo If IsActivated() = False Then ;setgatewayproxy("on","user","password") InstallProductKey($OSkey) ; installs a product key and also activates it ;setgatewayproxy("off") Else Return EndIf ElseIf $OS = 'NT5' Then $VOL_PROD_KEY = StringReplace($OSkey,"-","") ;remove hyphens if any $x = ObjGet("winmgmts:{impersonationLevel=impersonate}") $y = $x.InstancesOf ("win32_WindowsProductActivation") For $Obj In $y $result = $Obj.SetProductKey ($VOL_PROD_KEY) If $g_eventerror then Msgbox(0,"","The key used is not valid - " & $VOL_PROD_KEY) Next EndIf EndFunc Func IsActivated() $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Description, LicenseStatus, GracePeriodRemaining FROM SoftwareLicensingProduct WHERE PartialProductKey <> null") If IsObj($oCollection) Then For $oItem In $oCollection Switch $oItem.LicenseStatus Case 0 ConsoleWrite("Unlicensed" & @CRLF) Return False Case 1 If $oItem.GracePeriodRemaining Then If StringInStr($oItem.Description, "TIMEBASED_") Then ConsoleWrite("Timebased activation will expire in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Else ConsoleWrite("Volume activation will expire in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False EndIf Else ConsoleWrite("The machine is permanently activated." & @CRLF) Return True EndIf Case 2 ConsoleWrite("Initial grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 3 ConsoleWrite("Additional grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 4 ConsoleWrite("Non-genuine grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 5 ConsoleWrite("Windows is in Notification mode" & @CRLF) Return False Case 6 ConsoleWrite("Extended grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False EndSwitch Next EndIf EndIf EndFunc Func InstallProductKey($strProductKey) $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Version FROM SoftwareLicensingService") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite($oItem.Version & @CRLF) $oItem.InstallProductKey($strProductKey) If $g_eventerror then Return ActivateProduct() Next EndIf EndIf EndFunc Func ActivateProduct() $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT ID, ApplicationId, PartialProductKey, LicenseIsAddon, Description, Name, LicenseStatus FROM SoftwareLicensingProduct WHERE PartialProductKey <> null") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite($oItem.Name & @CRLF) ConsoleWrite($oItem.ID & @CRLF) $oItem.Activate() If $g_eventerror then Return RefreshStatus() ; Needed otherwise windows complains about non genuine key and changes background to black $oItem.refresh_ Next EndIf EndIf EndFunc Func RefreshStatus() $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Version FROM SoftwareLicensingService") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite("Refresh Status" & @CRLF) $oItem.RefreshLicenseStatus() Next EndIf EndIf EndFunc Func Officeactivate() ; First attempt - go out to the internet directly If OfficeIsActivated() = False Then InstallOfficeProductKeyActivateInternet($officekey) ; installs a product key and also activates it Else Return EndIf EndFunc Func OfficeIsActivated() $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Description, LicenseStatus, GracePeriodRemaining FROM OfficeSoftwareProtectionProduct WHERE PartialProductKey <> null") If IsObj($oCollection) Then For $oItem In $oCollection Switch $oItem.LicenseStatus Case 0 ConsoleWrite(" ---UNLICENSED--- " & @CRLF) Return False Case 1 ConsoleWrite(" ---LICENSED--- " & @CRLF) ;If licSr = 0 Then ; WScript.Echo MSG_ERRCODE & licSr & " as licensed" ;End If Return True Case 2 ConsoleWrite("---OOB_GRACE--- Initial grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 3 ConsoleWrite("---OOT_GRACE--- Initial grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 4 ConsoleWrite("---NON_GENUINE_GRACE--- Grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 5 ConsoleWrite("---NOTIFICATIONS--- Grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case 6 ConsoleWrite("---EXTENDED GRACE--- Extended grace period ends in " & $oItem.GracePeriodRemaining & " minutes" & @CRLF) Return False Case Else ConsoleWrite("---UNKNOWN---" & @CRLF) Return False EndSwitch Next EndIf EndIf EndFunc Func InstallOfficeProductKeyOnly($strProductKey) $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Version FROM OfficeSoftwareProtectionService") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite($oItem.Version & @CRLF) $oItem.InstallProductKey($strProductKey) If $g_eventerror then Return Next EndIf EndIf EndFunc Func InstallOfficeProductKeyActivateInternet($strProductKey) $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Version FROM OfficeSoftwareProtectionService") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite($oItem.Version & @CRLF) $oItem.InstallProductKey($strProductKey) If $g_eventerror then Return ActivateOfficeProduct() Next EndIf EndIf EndFunc Func ActivateOfficeProduct() $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT ID, ApplicationId, PartialProductKey, LicenseIsAddon, Description, Name, LicenseStatus FROM OfficeSoftwareProtectionProduct WHERE PartialProductKey <> null") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite($oItem.Name & @CRLF) ConsoleWrite($oItem.ID & @CRLF) $oItem.Activate() If $g_eventerror then Return RefreshOfficeStatus() ; Needed to refresh status $oItem.refresh_ Next EndIf EndIf EndFunc Func RefreshOfficeStatus() $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT Version FROM OfficeSoftwareProtectionService") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite("Refresh Status" & @CRLF) $oItem.RefreshLicenseStatus() Next EndIf EndIf EndFunc Is there any way to check the error code (For example. 0xC004C008) when execute .Activate()? Link to comment Share on other sites More sharing options...
water Posted August 14, 2019 Share Posted August 14, 2019 A COM error handler does this for you. Please see the Autoit help file. BTW: Please do not quote a thread. Simply add your reply at the bottom of the thread. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
phucbk2344 Posted August 14, 2019 Share Posted August 14, 2019 Thanks! Sorry for the inconvenience! Link to comment Share on other sites More sharing options...
Skysnake Posted August 14, 2019 Share Posted August 14, 2019 (edited) If Not IsObj($Outlook) then Exit If Not IsObj($Outlook) then Exit If you use the UDFs they will do most of the hard work, simply exit if the Object does not exit. Note that unlicensed MS Office products do not create objects... Skysnake Edited August 14, 2019 by Skysnake FrancescoDiMuro and Earthshine 2 Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
bbkim Posted August 16, 2019 Share Posted August 16, 2019 I Can not check Activate Error when execute .Activate() $oItem.Activate() It report error ==> The requested action with this object has failed.: $oItem.Activate() $oItem^ ERROR Check it and Error Autoit is "-2147352567 0x80020009 Exception occurred." Please help me fix it! Link to comment Share on other sites More sharing options...
water Posted August 16, 2019 Share Posted August 16, 2019 Did you add a COM error handler as I suggested? Have a look at ObjEvent in the help file. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
bbkim Posted August 17, 2019 Share Posted August 17, 2019 I have use ObjEvent but it don't as I like. It is AutoIT Error not Activate() Error. If Windows not Activated it will report Error Autoit is "-2147352567 0x80020009 Exception occurred." #include <array.au3> local $aErrRet[3] Local $oErrObj = ObjEvent("AutoIt.Error", "_ErrFunc") local $oWMI = ObjGet("winmgmts:\\.\root\cimv2") $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT * FROM SoftwareLicensingProduct WHERE PartialProductKey <> Null", "WQL") If IsObj($oCollection) Then For $oItem In $oCollection ConsoleWrite($oItem.PartialProductKey & @CRLF) local $cQuery = $oItem.Activate() if @error then _arraydisplay($aErrRet) if $cQuery.count = 0 then ConsoleWrite('Nothing found for query' & @CRLF) Next EndIf Else Msgbox(0,"Activator","Activation failed") Endif Func _ErrFunc() $HexNumber = Hex($oErrObj.number, 8) $aErrRet[0] = $HexNumber $aErrRet[1] = StringStripWS($oErrObj.description, 3) $aErrRet[2] = StringStripWS($oErrObj.windescription, 3) SetError(1); something to check for when this function returns EndFunc Link to comment Share on other sites More sharing options...
Skysnake Posted August 20, 2019 Share Posted August 20, 2019 On 8/14/2019 at 5:19 PM, Skysnake said: If Not IsObj($Outlook) then Exit Is this solution simplistic? Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
bbkim Posted August 21, 2019 Share Posted August 21, 2019 18 hours ago, Skysnake said: Is this solution simplistic? I need try method Activate() and read uint32 Activate() in SoftwareLicensingProduct class. Please help me complete script autoit above. Thanks so much! Link to comment Share on other sites More sharing options...
bbkim Posted August 24, 2019 Share Posted August 24, 2019 Can you help me convert VBScript after to au3? strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set objShare = objWMIService.Get("SoftwareLicensingProduct.ID='ac96e1a8-6cc4-4310-a4ff-332ce77fb5b8'") Set objOutParams = objWMIService.ExecMethod("SoftwareLicensingProduct.ID='ac96e1a8-6cc4-4310-a4ff-332ce77fb5b8'", "Activate") Wscript.Echo "Out Parameters: " Wscript.echo "ReturnValue: " & objOutParams.ReturnValue Thanks so much! Link to comment Share on other sites More sharing options...
Developers Jos Posted August 24, 2019 Developers Share Posted August 24, 2019 4 hours ago, bbkim said: Can you help me convert VBScript after to au3? Help or you want us to do it for you? Post what you have tried and isn;t working. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
bbkim Posted August 26, 2019 Share Posted August 26, 2019 (edited) On 8/24/2019 at 3:34 PM, Jos said: Help or you want us to do it for you? Post what you have tried and isn;t working. Jos I code as this post but it isn't working. And I Try With under code #include <array.au3> Local $aErrRet[3] Local $oErrObj = ObjEvent("AutoIt.Error", "_ErrFunc") Local $spp = "SoftwareLicensingProduct" $oWMIService = ObjGet("winmgmts:\\.\root\cimv2") If IsObj($oWMIService) Then $oCollection = $oWMIService.ExecQuery("SELECT * FROM "&$spp&" WHERE PartialProductKey <> Null", "WQL") If IsObj($oCollection) Then For $oItem In $oCollection $objOutParams = $oWMIService.ExecMethod_($spp&".ID='"& $oItem.ID&"'", "Activate") ConsoleWrite($oItem.ID & @CRLF) ConsoleWrite("ReturnValue: " & $objOutParams.ReturnValue & @CRLF) ConsoleWrite("Error: "&$objOutParams & @CRLF) Next EndIf Else Msgbox(0,"Activator","Activation failed") Endif Func _ErrFunc() $HexNumber = Hex($oErrObj.number, 8) $aErrRet[0] = $HexNumber $aErrRet[1] = StringStripWS($oErrObj.description, 3) $aErrRet[2] = StringStripWS($oErrObj.windescription, 3) SetError(1); something to check for when this function returns EndFunc I can't view Error Code while run method Activate() Example: "Error: 0xC004C003 The activation server determined the specified product key is blocked" Product Key Windows 7 Blocked for Error above: "YDDHV-66XXV-RQHQQ-6G733-BDJVX" Edited August 26, 2019 by bbkim Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now