Jump to content
Sign in to follow this  
Kovacic

Trying to make script to see if Windows 7 is activated.

Recommended Posts

Kovacic

One of the simplest things I need to do, and I cant do it. All I need is a script that checks to see if Windows 7 has been activated. I looked through many of the WMI references from the website below and cant find the right one to query.

http://www.activexperts.com/admin/scripts/wmi/vbscript/

I was wondering if anyone has one.

Thanks in advance!!


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites
guinness

Search Scriptomatic in the Forum and use Win32_WindowsProductActivation.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
FireFox

Note that if you have a pirated copy the WMI samples won't work.

Edit :

Global $strComputer, $objWMIService, $colWPA

$strComputer = "."

$objWMIService = ObjGet("winmgmts:" _
         & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")

If IsObj($objWMIService) Then
    $colWPA = $objWMIService.ExecQuery _
            ("Select * from Win32_WindowsProductActivation")

    If IsObj($colWPA) Then
        Local $blHasWPA = False

        For $objWPA In $colWPA
            $blHasWPA = True

            ConsoleWrite( _
                    "Activation Required: " & $objWPA.ActivationRequired & @CRLF & _
                    "Caption: " & $objWPA.Caption & @CRLF & _
                    "Description: " & $objWPA.Description & @CRLF & _
                    "IsNotificationOn: " & $objWPA.IsNotificationOn & @CRLF & _
                    "Product ID: " & $objWPA.ProductID & @CRLF & _
                    "Remaining Evaluation Period: " & $objWPA.RemainingEvaluationPeriod & @CRLF & _
                    "Remaining Grace Period: " & $objWPA.RemainingGracePeriod & @CRLF & _
                    "Server Name: " & $objWPA.ServerName & @CRLF & _
                    "Setting ID: " & $objWPA.SettingID & @CRLF)
        Next

        If Not $blHasWPA Then
            ConsoleWrite("Bad guy I gotya !" & @CRLF)
        EndIf
    EndIf
EndIf
Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Kovacic

Im not running pirated copies, at least I hope I'm not... I am writing a profiler for the company I work for, and part of it is to activate windows and office if its not already activated. I have the Office portion working, but when I ran the code above, I got "Bad guy I gotya !"

I did find this though: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394520(v=vs.85).aspx People are saying Win32_WindowsProductActivation class doesnt work in vista and 7 :/

I found this, but I'm not 100% sure how to invoke it, looks like I have some testing to do:

class SoftwareLicensingProduct

{

string ID;

string Name;

string Description;

string ApplicationID;

string ProcessorURL;

string MachineURL;

string ProductKeyURL;

string UseLicenseURL;

uint32 LicenseStatus;

uint32 LicenseStatusReason;

uint32 GracePeriodRemaining;

datetime EvaluationendDate;

string OfflineInstallationId;

string PartialProductKey;

string ProductKeyID;

string LicenseFamily;

string LicenseDependsOn;

boolean LicenseIsAddon;

uint32 VLActivationInterval;

uint32 VLRenewalInterval;

string KeyManagementServiceProductKeyID;

string KeyManagementServiceMachine;

uint32 KeyManagementServicePort;

string DiscoveredKeyManagementServiceMachineName;

uint32 DiscoveredKeyManagementServiceMachinePort;

uint32 IsKeyManagementServiceMachine;

uint32 KeyManagementServiceCurrentCount;

uint32 RequiredClientCount;

uint32 KeyManagementServiceUnlicensedRequests;

uint32 KeyManagementServiceLicensedRequests;

uint32 KeyManagementServiceOOBGraceRequests;

uint32 KeyManagementServiceOOTGraceRequests;

uint32 KeyManagementServiceNonGenuineGraceRequests;

uint32 KeyManagementServiceTotalRequests;

uint32 KeyManagementServiceFailedRequests;

uint32 KeyManagementServiceNotificationRequests;

uint32 GenuineStatus;

uint32 ExtendedGrace;

string TokenActivationILID;

uint32 TokenActivationILVID;

uint32 TokenActivationGrantNumber;

string TokenActivationCertificateThumbprint;

string TokenActivationAdditionalInfo;

datetime TrustedTime;

};

Edited by Kovacic

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites
guinness

You're not a "bad guy" read towards the end of this page.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Kovacic

I know what the product key should be, so what I might do is something like this, taking code from FireFox of course (the user, not the browser)

Global $strComputer, $objWMIService, $colWPA

$strComputer = "."

$objWMIService = ObjGet("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")

If IsObj($objWMIService) Then
$colWPA = $objWMIService.ExecQuery _
("Select * from SoftwareLicensingProduct")

If IsObj($colWPA) Then
Local $blHasWPA = False

For $objWPA In $colWPA
$blHasWPA = True

MsgBox(0,"", _
"Partial Product Key: " & $objWPA.PartialProductKey)
Next

If Not $blHasWPA Then
MsgBox(0,"","Aw crap, you bootleggin")
EndIf
EndIf
EndIf
Edited by Kovacic

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites
JLogan3o13

This is what I use, works well on both Windows 7 and Server 2008 boxes:

$WMI = ObjGet("winmgmts:\\.\root\cimv2")
$aLicenses = $WMI.ExecQuery("Select * From SoftwareLicensingProduct")
 
   For $element In $aLicenses
      If StringInStr($element.Description, "Windows Operating System") Then
         If $element.GracePeriodRemaining = 0 Then
            MsgBox(0, "", "Product is Activated")
            ExitLoop
         Else
            ;Call SLMgr.vbs with your selected options
            ;http://technet.microsoft.com/en-us/library/ff793433.aspx
         EndIf
      EndIf
   Next
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
Chimaera

This may help with this, i bodged this together for something i was doing a while ago

Global $ActiveCheck, $result

If @OSVersion = "WIN_2000" Or @OSVersion = "WIN_2003" Or @OSVersion = "WIN_XP" Or @OSVersion = "WIN_XPe" Then
$ActiveCheck = _XPActivationCheck()
Else
$ActiveCheck = _ActivationStatus()
EndIf

Func _ActivationStatus() ; Vista + Only ~ author trancexx
Local $oWMIService = ObjGet("winmgmts:\\.\root\cimv2")
If IsObj($oWMIService) Then
Local $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, 2 To 4, 6
$result = "Windows Is NOT Activated"
Case 1
$result = "Windows Is Activated"
Case 5
$result = "Possible Fixed Windows (Notification Mode)"
EndSwitch
;~ Return ConsoleWrite( $result & @CRLF)
Return MsgBox(0, "Activation Result", $result & @CRLF)
Next
EndIf
EndIf
EndFunc ;==>_ActivationStatus

Func _XPActivationCheck() ; XP only
Local $x = ObjGet("winmgmts:{impersonationLevel=impersonate}")
Local $y = $x.InstancesOf("win32_WindowsProductActivation")
For $Obj In $y
If $Obj.ActivationRequired Then
$result = 'Windows Is NOT Activated'
Else
$result = 'Windows Is Activated'
EndIf
Next
;~ Return ConsoleWrite( $result & @CRLF)
Return MsgBox(0, "Activation Result", $result & @CRLF)
EndFunc ;==>_XPActivationCheck

I found the Possible Fixed Windows (Notification Mode) answer usefull for Hooky/Dodgy OS because its looking for a different param which the cracks exploit but don't take it as verbatim

I would prob test it thoroughly as i cant remember whether i finished it completely

Edited by Chimaera

Share this post


Link to post
Share on other sites
Colyn1337

This might be blasphemous, however this is my Powershell script for activating windows 7. It also refreshes at the higher level so the OS can see that the license has been activated without a reboot. Note, this is for after you've already programatically had the activation code entered (ours is in our base image).

(Get-WmiObject -Namespace "root\cimv2" -Class SoftwareLicensingProduct | Where-Object {$_.productkeyid -ne $null}).activate()
(Get-WmiObject -Namespace "root\cimv2" -Class SoftwareLicensingService).RefreshLicenseStatus()

EDIT: I highly recommend WMI Tools from microsoft, it makes scraping the WMI landscape so much easier.

Edited by Colyn1337

Share this post


Link to post
Share on other sites
Kovacic

Actually Colyn, I was planning on bringing in much more powershell to the profiler, but I have much to learn first. 95% of my information gathering is through WMI, but I am finding some resources that work on XP, don't work on 7 or vista (not like I use vista ;) )

JLogan3o13, I did try that code, but every laptop I ran it on, said that windows was activated, even if it wasnt.

Chimaera, This is working for me! Thanks!!!


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • Iznogoud
      By Iznogoud
      Hi,
      Does anyone knows why this command doesn't work?
      Run(@ComSpec & " /c " & "devcon.exe hwids * | findstr /R ""1050&PID_0114&REV_0340&MI_01"" || (rundll32.exe user32.dll, LockWorkStation)", "", "") This is the command in commandline:
      devcon.exe hwids * | findstr /R "1050&PID_0114&REV_0340&MI_01" && (echo USB Device is connected) || (rundll32.exe user32.dll, LockWorkStation) This works, but i want to convert this to AutoIT, but it doesn't work.
       
      In short what i am trying to accomplish is that a script checks every 1 sec. if there is an USB device plugged in and if not ( so it is removed ) it will lock Windows OS.
      Can someone help me with this?
    • VITSUSA
      By VITSUSA
      I am using window XP in my desktop, so I want to convert basic disk to a dynamic disk, so how it is possible?
    • XaelloNegative
      By XaelloNegative
      Hi,
      I'm currently saving process time stamps of my employer's other employees and saving it in a text document as data storage. However, my employer wants it to be processed in a day to day basis to generate their average process time per day. How can I compare today from yesterday and so on and so forth with the succeeding days? Whats the best approach to this?
      Thank you.
      ~XN~
    • mdwerne
      By mdwerne
      Hello,
      I'm working on a script that writes detailed application event logs, and I'd like to know if there is a way with Autoit to write multiple lines of XML EventData (see example below):
      <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="Application" /> <EventID Qualifiers="0">1001</EventID> <Level>4</Level> <Task>0</Task> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2015-07-12T21:26:07.000000000Z" /> <EventRecordID>86554</EventRecordID> <Channel>Application</Channel> <Computer>YOUR_COMPUTER</Computer> <Security /> </System> <EventData> <Data>DeskTop Agent: Mike</Data> <Data>Observer Username: Miguel</Data> etc... </EventData> </Event> So far, using EventCreate, everything I send end's up in a single <data> entry (see below):
      <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="Application" /> <EventID Qualifiers="0">1001</EventID> <Level>4</Level> <Task>0</Task> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2015-07-12T21:26:07.000000000Z" /> <EventRecordID>86554</EventRecordID> <Channel>Application</Channel> <Computer>YOUR_COMPUTER</Computer> <Security /> </System> <EventData> <Data>DeskTop Agent: Mike Observer Username: Miguel</Data> </EventData> </Event> Here is the code I'm using thus far (which does not work the way I'd like):
      $LogData = @CRLF & "DeskTop Agent: " & @UserName & @CRLF & "Observer Username: " & $DTObserver & @CRLF & "File name/s with extension: " & $FilenameWextension & @CRLF & "Action Performed: " & $ActionPerformed & @CRLF & "Explanation: " & $Explanation & @CRLF & "Machine Name: " & @ComputerName & @CRLF & "IP Address: " & @IPAddress1 & @CRLF & "App1Installed: " & $App1 & @CRLF & "App2Installed: " & $App2 Run("eventcreate /T Information /ID 100 /L Application /SO DTALog /D " & Chr(34) & "DTALog Details: " & $LogData & Chr(34), "", @SW_HIDE, 2) I found a Stackoverflow post that talks about doing it in C# (https://stackoverflow.com/questions/7694276/how-to-add-multiple-lines-of-eventdata-to-an-eventlog-in-windows)
      but I'd like to determine if it can be accomplished with AutoIt!.
      Thanks for your time,
      -Mike
    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      i am working on a application where if the flashing is success i get a window saying "SUCCESS" and if the flashing failed a window saying "FAILED" and i have to automatically identify pass or fail.the problem is both the windows are having the same control ID. how can i differentiate between both windows? so that i can make use of that in script for automation///
       
       
      Thanks
×