mbt masai
 
Welcome !
         

                                
After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 Retrieve Windows Product Key

Change Page: < 123 | Showing page 3 of 3, messages 41 to 45 of 45
Author Message
mbouchard

  • Total Posts : 2110
  • Scores: 27
  • Reward points : 0
  • Joined: 5/15/2003
  • Location: USA
  • Status: offline
RE: Retrieve Windows Product Key Wednesday, September 03, 2008 11:12 PM (permalink)
0
The error you are getting means that you have arrDPID dimmed twice.  If you are only using it in the function, remove the dim at the top of the script.  If you are using it in both places, remove the dim from the function.
Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.
#41
    fletchjake

    • Total Posts : 1
    • Scores: 0
    • Reward points : 0
    • Joined: 11/7/2008
    • Status: offline
    RE: Retrieve Windows Product Key Friday, November 07, 2008 9:16 AM (permalink)
    0
    Hi,
    This is a great script, I am ENTIRELY new to VB so I am lost...I got it running pulled my windows product id from the domain and all is good that way.

    I have a couple questions though:

    1.  I can't get it to work so I can pull the office, visio, or other MS product id's?  Anyone able to help?  I am using the script below: 
    2.  I also want to see if this can go to a csv file or excel? 

    '  ##########################################
    '  #            #
    '  #  VBScript to Retrieve a List of Computers from Active  #
    '  #  Directory, check connectivity and generate a report file #
    '  #  containing Microsoft Windows Licensing Information.  #
    '  #            #
    '  ##########################################
    '
    Dim objDomain, strComputer, strADComputer, PC, strKeyPath, strValueName, oReg
    Dim ADCompList, ActiveCompList, RetrievedKeys
    Dim IE, oFSO, objShell, strPath, objFile
    Set IE = CreateObject("InternetExplorer.Application")
    Set objShell = CreateObject("Wscript.Shell")
    strPath = Wscript.ScriptFullName
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.GetFile(strPath)
    strPath = objFSO.GetParentFolderName(objFile)
    With IE
    .left=200
    .top=200
    .height=140
    .width=250
    .menubar=0
    .toolbar=0
    .statusBar=0
    .navigate "About:Blank"
    .visible=1
    End With
    'wait a while until IE as finished to load
    Do while IE.busy
    loop
    With IE.document
    .Open
    .WriteLn "<html>"
    .WriteLn "<head>"
    .WriteLn "<HTA:APPLICATION "
    .WriteLn "     ID='objNoTitleBar'"
    .WriteLn "     CAPTION=no"
    .WriteLn "     SHOWINTASKBAR='NO'"
    .WriteLn "     BORDER='NONE'"
    .WriteLn "     APPLICATIONNAME='Please Wait'"
    .WriteLn "     SCROLL='AUTO'"
    .WriteLn "     SINGLEINSTANCE='yes'"
    .WriteLn ">"
    .WriteLn "</head>"
    .WriteLn "<body text='#ffffff' bgcolor='#000000'>"
    .WriteLn "<center>Please Wait....<br /><br />"
    .WriteLn "<img src='" & strPath & "\ajax-loader.gif' /></center>"
    .WriteLn "</body>"
    .WriteLn "</html>"
    .Close
    End With
    ADCompList = Array(0)
    ' Connect to root of domain
    Dim rootDSE, domainContainer
    Set rootDSE = GetObject("LDAP://RootDSE")
    domainContainer = rootDSE.Get("defaultNamingContext")
    Set ObjDomain = GetObject("LDAP://" & domainContainer)
    ' Enumerate through the domain
    WorkWithObject(ObjDomain)
    Sub WorkWithObject(oContainer)
    Dim oADObject
    For Each oADObject in oContainer
    Select Case oADObject.Class
    Case "computer"
    Dim strADComputer
    strADComputer = oADObject.cn
    ADCompList(UBound(ADCompList)) = strADComputer
    ReDim Preserve ADCompList(UBound(ADCompList) + 1)
    Case "organizationalUnit" , "container"
    WorkWithObject(oADObject)
    End Select
    Next
    End Sub
    ReDim Preserve ADCompList(UBound(ADCompList) - 1)
    ActiveCompList = Array(0)
    For Each PC In ADCompList
    If Reachable(PC) Then
    ActiveCompList(UBound(ActiveCompList)) = PC
    ReDim Preserve ActiveCompList(UBound(ActiveCompList) + 1)
    End If
    Next
    ReDim Preserve ActiveCompList(UBound(ActiveCompList) - 1)
    Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
    Set rootEl = objXMLDoc.createElement("Computers")
    objXMLDoc.appendChild rootEl
    Dim objCurrNode, objNewNode, objNewText
    ' <--------------- Open Registry Key and populate binary data into an array -------------------------->
    const HKEY_LOCAL_MACHINE = &H80000002
    strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
    strValueName = "DigitalProductId"
    Dim iValues()
    On Error Resume Next
    For Each strComputer In ActiveCompList
    Set objPCField = objXMLDoc.createElement("PC")
    rootEl.appendChild(objPCField)
    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
      strComputer & "\root\default:StdRegProv")
    oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,iValues
    Dim arrDPID
    arrDPID = Array()
    For i = 52 to 66
    ReDim Preserve arrDPID( UBound(arrDPID) + 1 )
    arrDPID( UBound(arrDPID) ) = iValues(i)
    Next
    ' <--------------- Create an array to hold the valid characters for a microsoft Product Key -------------------------->
    Dim arrChars
    arrChars = Array("B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9")
    ' <--------------- The clever bit !!! (Decrypt the base24 encoded binary data)-------------------------->
    strProductKey = ""
    For i = 24 To 0 Step -1
    k = 0
    For j = 14 To 0 Step -1
    k = k * 256 Xor arrDPID(j)
    arrDPID(j) = Int(k / 24)
    k = k Mod 24
    Next
    strProductKey = arrChars(k) & strProductKey
    If i Mod 5 = 0 And i <> 0 Then strProductKey = "-" & strProductKey
    Next
    strFinalKey = strProductKey
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colOperatingSystems = objWMIService.ExecQuery("select * from Win32_OperatingSystem")
    For Each objOperatingsystem in colOperatingSystems
    strOS   = objOperatingsystem.Caption
    strBuild   = objOperatingsystem.BuildNumber
    strSerial   = objOperatingsystem.SerialNumber
    strRegistered  = objOperatingsystem.RegisteredUser
    Next
    Set objNewNode = objXMLDoc.createElement("Name")
    Set objNewText = objXMLDoc.createTextNode(strComputer)
    objPCField.appendChild(objNewNode)
    objNewNode.appendChild(objNewText)
    Set objNewNode = objXMLDoc.createElement("OS")
    Set objNewText = objXMLDoc.createTextNode(strOS)
    objPCField.appendChild(objNewNode)
    objNewNode.appendChild(objNewText)
    Set objNewNode = objXMLDoc.createElement("Build")
    Set objNewText = objXMLDoc.createTextNode(strBuild)
    objPCField.appendChild(objNewNode)
    objNewNode.appendChild(objNewText)
    Set objNewNode = objXMLDoc.createElement("PID")
    Set objNewText = objXMLDoc.createTextNode(strSerial)
    objPCField.appendChild(objNewNode)
    objNewNode.appendChild(objNewText)
    Set objNewNode = objXMLDoc.createElement("RegisteredTo")
    Set objNewText = objXMLDoc.createTextNode(strRegistered)
    objPCField.appendChild(objNewNode)
    objNewNode.appendChild(objNewText)
    Set objNewNode = objXMLDoc.createElement("Key")
    Set objNewText = objXMLDoc.createTextNode(strFinalKey)
    objPCField.appendChild(objNewNode)
    objNewNode.appendChild(objNewText)
    Next
    'Add an XML processing instruction and insert it before the root element
    Set p=objXMLDoc.createProcessingInstruction("xml","version='1.0'")
    xmlDoc.insertBefore p,objXMLDoc.childNodes(0)
    objXMLDoc.Save("report.xml")
    IE.Quit
    set IE = Nothing
    MsgBox("Finished")
    ' <----------------------- Function to check if computer is switched on and responding to Ping ---------------------->
    Function Reachable(strComputer)
    ' On Error Resume Next
    Dim wmiQuery, objWMIService, objPing, objStatus
    wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strComputer & "'"
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set objPing = objWMIService.ExecQuery(wmiQuery)
    For Each objStatus in objPing
    If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
    Reachable = False 'if computer is unreacable, return false
    Else
    Reachable = True 'if computer is reachable, return true
    End If
    Next
    End Function

    #42
      travisb

      • Total Posts : 1
      • Scores: 0
      • Reward points : 0
      • Joined: 5/3/2007
      • Status: offline
      RE: Retrieve Windows Product Key Friday, February 13, 2009 4:01 AM (permalink)
      0
      Is it possible to add a list of computer names or IP addresses that you want scanned? This way you do not have to scan the entire domain. I'm new to VBS and not sure where I would start. Can anyone help with this?
      #43
        dm_4ever

        • Total Posts : 3673
        • Scores: 82
        • Reward points : 0
        • Joined: 6/29/2006
        • Location: Orange County, California
        • Status: offline
        RE: Retrieve Windows Product Key Wednesday, February 18, 2009 4:13 PM (permalink)
        0
        Simply assign computers to the array ActiveCompList and use the existing code.
        dm_4ever

        My philosophy: K.I.S.S - Keep It Simple Stupid
        Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
        Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
        #44
          chrisupman

          • Total Posts : 1
          • Scores: 0
          • Reward points : 0
          • Joined: 3/21/2010
          • Status: offline
          RE: Retrieve Windows Product Key Sunday, March 21, 2010 11:52 PM (permalink)
          0
          Has anyone had any success in getting this script to work in a windows x64 environment? 
           
          I have been trying to get the HTA version to work in windows 7 x64 by spawning the old script host
           Set oSH = CreateObject("WScript.Shell")
          Set oFS = CreateObject("Scripting.FileSystemObject")
           
          strOldWSH = oSH.ExpandEnvironmentStrings("%SYSTEMROOT%\SysWOW64\wscript.exe")
          If oFS.FileExists(strOldWSH) Then
              If Not UCase(WScript.FullName) = UCase(strOldWSH) Then
                  oSH.Run """" & strOldWSH & """ """ & WScript.ScriptFullName & """", 1, False
                  WScript.Echo "Running on 64-bit WSH."
                 
                 
                 
              End If
          End If
          This information was posted on the MS scripting guys site.
                 
          I have had no luck in getting any results.
           
          What tecnniques
          #45

            Online Bookmarks Sharing: Share/Bookmark
            Change Page: < 123 | Showing page 3 of 3, messages 41 to 45 of 45

            Jump to:

            Current active users

            There are 0 members and 2 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.8
            mbt shoes www.wileywilson.com