home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Audio / Office2010 / ProPlus.WW / ProPsWW.cab / OSPP.VBS < prev    next >
Text File  |  2010-03-06  |  49KB  |  1,204 lines

  1. '////////////////////////////////////////////////////////////////////////////////////////
  2. '////////////////////////////////////////////////////////////////////////////////////////
  3. CONST wshOK                             =0
  4. CONST VALUE_ICON_WARNING                =16
  5. CONST wshYesNoDialog                    =4
  6. CONST VALUE_ICON_QUESTIONMARK           =32
  7. CONST VALUE_ICON_INFORMATION            =64
  8. CONST HKEY_LOCAL_MACHINE                =&H80000002
  9. CONST KEY_SET_VALUE                     =&H0002
  10. CONST KEY_QUERY_VALUE                   =&H0001
  11. CONST REG_SZ                            =1
  12. CONST OfficeAppId                       = "59a52881-a989-479d-af46-f275c6370663"
  13. CONST STR_SYS32PATH                     = ":\Windows\System32\"
  14. CONST REG_SPP                           = "SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform"
  15. '////////////////////////////////////////////////////////////////////////////////////////
  16. CONST MSG_NOREGRIGHTS                   = "Insufficient rights to perform operation."
  17. CONST MSG_ISCMD_ELEVATED                = "Ensure cmd.exe is elevated (right click > run as administrator)."
  18. CONST MSG_CREDENTIALFAILURE             = "Connection failed with passed credentials."
  19. CONST MSG_FILENOTFOUND                  = "File not found: "
  20. CONST MSG_CREDENTIALERR                 = "Passing credentials not supported for this option."
  21. CONST MSG_SEPERATE                      = "---------------------------------------"
  22. CONST MSG_PROCESSING                    = "---Processing--------------------------"
  23. CONST MSG_EXIT                          = "---Exiting-----------------------------"
  24. CONST MSG_UNSUPPORTED                   = "Unsupported command passed."
  25. CONST MSG_SUCCESS                       = "Successfully applied setting."
  26. CONST MSG_ACTATTEMPT                    = "Installed product key detected - attempting to activate the following product:"
  27. CONST MSG_TOKACTATTEMPT                 = "Installed product key detected - attempting to token activate the following product:"
  28. CONST MSG_NOKEYSINSTALLED               = "<No installed product keys detected>"
  29. CONST MSG_UNINSTALLKEYSUCCESS           = "<Product key uninstall successful>"
  30. CONST MSG_ACTSUCCESS                    = "<Product activation successful>"
  31. CONST MSG_OFFLINEACTSUCCESS             = "<Offline product activation successful>"
  32. CONST MSG_KEYINSTALLSUCCESS             = "<Product key installation successful>"
  33. CONST MSG_PARTIALKEY                    = "Last 5 characters of installed product key: "
  34. CONST MSG_UNINSTALLKEY                  = "Uninstalling product key for: "
  35. CONST MSG_UNRECOGFILE                   = "Unrecognized file. Office 2010 licenses have an .xrm-ms file extension."
  36. CONST MSG_INSTALLLICENSE                = "Installing Office 2010 license: "
  37. CONST MSG_INSTALLLICSUCCESS             = "Office 2010 license installed successfully."
  38. CONST MSG_SEARCHEVENTSKMS               = "Searching for KMS activation events on machine: "
  39. CONST MSG_SEARCHEVENTSRET               = "Searching for Internet activation failure events on machine: "
  40. CONST MSG_NOEVENTSSKMS                  = "No KMS activation events found on machine: "
  41. CONST MSG_NOEVENTSRET                   = "No failure events found on machine: "
  42. CONST MSG_OSPPSVC_NOINSTALL             = "Error: The Software Protection Platform service is not installed."
  43. CONST MSG_OSPPSVC_NORUN                 = "Error: The Software Protection Platform service is not running."
  44. CONST MSG_ERRPARTIALKEY                 = "The last 5 characters of an installed product key are required to run this option. Run the /dstatus option to display the partial product key."
  45. CONST MSG_KEYNOTFOUND                   = "<Product key not found>"
  46. CONST MSG_CMID                          = "Client Machine ID (CMID): "
  47. CONST MSG_NOLICENSEFOUND                = "<No licenses found>"
  48. CONST MSG_REMILID                       = "Removed Token-based Activation License with License ID (ILID): "
  49. CONST MSG_NOTFOUNDILID                  = "License not found with License ID (ILID): "
  50. '////////////////////////////////////////////////////////////////////////////////////////
  51. CONST MSG_SKUID                         = "SKU ID: "
  52. CONST MSG_LICENSENAME                   = "LICENSE NAME: "
  53. CONST MSG_DESCRIPTION                   = "LICENSE DESCRIPTION: "
  54. CONST MSG_LICSTATUS                     = "LICENSE STATUS: "
  55. CONST MSG_LICENSED                      = " ---LICENSED--- "
  56. CONST MSG_UNLICENSED                    = " ---UNLICENSED--- "
  57. CONST MSG_OOBGRACE                      = " ---OOB_GRACE--- "
  58. CONST MSG_OOTGRACE                      = " ---OOT_GRACE--- "
  59. CONST MSG_NONGENGRACE                   = " ---NON_GENUINE_GRACE--- "
  60. CONST MSG_NOTIFICATION                  = " ---NOTIFICATIONS--- "
  61. CONST MSG_EXTENDEDGRACE                 = " ---EXTENDED GRACE--- "
  62. CONST MSG_LICUNKNOWN                    = " ---UNKNOWN--- "
  63. CONST MSG_REMAINGRACE                   = "REMAINING GRACE: "
  64. CONST MSG_ERRCODE                       = "ERROR CODE: "
  65. CONST MSG_ERRDESC                       = "ERROR DESCRIPTION: "
  66. CONST MSG_ERRUNKNOWN                    = "An unknown error occurred."
  67. CONST MSG_ERRCODEVALUE                  = "An error code must start with '0x'. Example: 0xC004F009"
  68. '////////////////////////////////////////////////////////////////////////////////////////
  69. '////////////////////////////////////////////////////////////////////////////////////////
  70. On Error Resume Next
  71.  
  72. Set WshShell = WSCript.CreateObject("WSCript.Shell")
  73. Set objFSO = CreateObject("Scripting.FileSystemObject")
  74. Set objNetwork = WSCript.CreateObject("WSCript.Network")
  75.  
  76. Dim globalResource, globalErr, foundSlUi, strSluiPath, strLocal, objWMI, objWMI1, wmiErr, productinstances, strValue
  77. globalResource = ""
  78. globalErr = ""
  79. foundSlUi = False
  80.  
  81. currentDir = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\"))
  82.  
  83. Select Case WSCript.Arguments.Count
  84.     Case 0
  85.         verifyFileExists currentDir & "ospp.htm"
  86.         showIePopUp currentDir & "ospp.htm"
  87.         WScript.Quit
  88.     Case 1
  89.         var1 = WSCript.Arguments(0)
  90.     Case 2
  91.         var1 = WSCript.Arguments(0)
  92.         var2 = WSCript.Arguments(1)
  93.     Case 3
  94.         var1 = WSCript.Arguments(0)
  95.         var2 = WSCript.Arguments(1)
  96.         var3 = WSCript.Arguments(2)
  97.     Case 4
  98.         var1 = WSCript.Arguments(0)
  99.         var2 = WSCript.Arguments(1)
  100.         var3 = WSCript.Arguments(2)
  101.         var4 = WSCript.Arguments(3)
  102.     Case Else
  103. End Select
  104. '////////////////////////////////////////////////////////////////////////////////////////
  105. '////////////////////////////////////////////////////////////////////////////////////////
  106. Call Main(var1,var2,var3,var4)
  107. '////////////////////////////////////////////////////////////////////////////////////////
  108. '////////////////////////////////////////////////////////////////////////////////////////
  109. Sub Main(strCommand,strMachine,strUser,strPassword)
  110.  
  111. On Error Resume Next
  112.  
  113. getEngine()
  114. pProcessing()
  115.  
  116. getSlui()
  117. strLocal = objNetwork.ComputerName 
  118. strCommand = LCase(strCommand)
  119.  
  120. Select Case strCommand
  121.     Case "/act", "/dstatus", "/dstatusall", "/dinstid", "/dtokils", _
  122.         "/remhst", "/stokflag", "/ctokflag", "/dcmid", "/dtokcerts"
  123.         connectWMI strMachine,strUser,strPassword,""
  124.         performLicAction strCommand,"",""
  125.     Case "/dhistoryacterr", "/dhistorykms"
  126.         connectWMI strMachine,strUser,strPassword,""
  127.         performLicAction strCommand,"",strMachine
  128.     Case "/puserops", "/duserops"
  129.         connectWMI strMachine,strUser,strPassword,"reg"
  130.         performRegAction strCommand
  131.     Case "/osppsvcrestart", "/osppsvcauto"
  132.         connectWMI strMachine,strUser,strPassword,""
  133.         performServiceAction strCommand
  134.     Case "/help", "help", "?", "/?", "/?"
  135.         verifyFileExists currentDir & "ospp.htm"
  136.         showIePopUp currentDir & "ospp.htm"
  137.         quitExit()
  138.     Case "/regmof"
  139.         registerMof "osppwmi.mof"
  140.     Case Else
  141.         pos = InStr(strCommand,":")
  142.         If pos <> 8 Then
  143.             globalPopFailure MSG_UNSUPPORTED,True
  144.         End If
  145.         
  146.         getCommand = Left(strCommand,7)
  147.         Select Case getCommand
  148.             Case "/inpkey", "/unpkey", "/inslic", "/actcid", "/sethst", "/setprt", "/ddescr", "/rtokil", "/tokact"
  149.                 strValue = Replace(strCommand,getCommand & ":","")
  150.                 If strValue = "" Then
  151.                     globalPopFailure MSG_UNSUPPORTED & " A value is required for: " & strCommand,True
  152.                 End If
  153.                 
  154.                 If getCommand = "/ddescr" Then
  155.                     If Left(strValue,2) = "0x" Then
  156.                         getDescription strValue,""
  157.                     Else
  158.                         WScript.Echo MSG_ERRCODEVALUE
  159.                         quitExit()
  160.                     End If
  161.                 Else
  162.                     connectWMI strMachine,strUser,strPassword,""
  163.                     performLicAction getCommand,strValue,""
  164.                 End If
  165.             Case Else
  166.                 globalPopFailure MSG_UNSUPPORTED,True
  167.         End Select
  168. End Select
  169.  
  170. End Sub
  171. '////////////////////////////////////////////////////////////////////////////////////////
  172. '////////////////////////////////////////////////////////////////////////////////////////
  173. Function showIePopUp(strPath)
  174.  
  175. On Error Resume Next
  176.  
  177. Set objExplorer = CreateObject("InternetExplorer.Application")
  178.     With objExplorer
  179.             .Navigate strPath
  180.             .ToolBar = 0
  181.             .StatusBar = 0
  182.             .Width = 1000
  183.             .Height = 593 
  184.             .Left = 1
  185.             .Top = 1
  186.             .Visible = 1
  187.     End With
  188.         
  189. End Function
  190. '////////////////////////////////////////////////////////////////////////////////////////
  191. '////////////////////////////////////////////////////////////////////////////////////////
  192. Function getEngine()
  193.  
  194. strEngine = LCase(Right(WScript.FullName,12))
  195. If strEngine <> "\cscript.exe" Then
  196.     WshShell.Popup "Unable to perform operation. " & WSCript.ScriptName & " requires the cscript engine." & _
  197.      vbCr & "Command line example: cscript ospp.vbs ?", _
  198.     ,WSCript.ScriptName, VALUE_ICON_WARNING
  199.     WScript.Quit
  200. End If
  201.  
  202. End Function
  203. '////////////////////////////////////////////////////////////////////////////////////////
  204. '////////////////////////////////////////////////////////////////////////////////////////
  205. Function WMIDateStringToDate(dtmEventDate)
  206.  
  207. WMIDateStringToDate = CDate(Mid(dtmEventDate, 5, 2) & "/" & _
  208. Mid(dtmEventDate, 7, 2) & "/" & Left(dtmEventDate, 4) _
  209. & " " & Mid (dtmEventDate, 9, 2) & ":" & _
  210. Mid(dtmEventDate, 11, 2) & ":" & Mid(dtmEventDate, _
  211. 13, 2))
  212.  
  213. End Function
  214. '////////////////////////////////////////////////////////////////////////////////////////
  215. '////////////////////////////////////////////////////////////////////////////////////////
  216. Function getDescription(strSearch,cType)
  217.  
  218. If foundSlUi <> True Then
  219.     If cType <> "wmi" Then
  220.         globalPopFailure "slui.exe not found.",True
  221.         quitExit()
  222.     End If
  223. Else
  224.     Set objScriptExec = WshShell.Exec (strSluiPath & " 0x2a " & strSearch)
  225.     readOut = objScriptExec.StdOut.ReadAll
  226.     quitExit()
  227. End If
  228.  
  229. End Function
  230. '////////////////////////////////////////////////////////////////////////////////////////
  231. '////////////////////////////////////////////////////////////////////////////////////////
  232. Function checkRegRights(wmiObject,strKeyPath)
  233.  
  234. On Error Resume next
  235.  
  236. wmiObject.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_SET_VALUE, _
  237.     bHasAccessRight
  238.  
  239. If bHasAccessRight = True Then
  240.     'Success
  241. Else
  242.     globalPopFailure MSG_NOREGRIGHTS & vbCr & MSG_ISCMD_ELEVATED,True
  243. End If   
  244.  
  245. End Function
  246. '////////////////////////////////////////////////////////////////////////////////////////
  247. '////////////////////////////////////////////////////////////////////////////////////////
  248. Function quitExit()
  249.  
  250. Set WshShell = Nothing
  251. Set objFSO = Nothing
  252. Set objNetwork = Nothing
  253. Set objWMI = Nothing
  254.  
  255. WScript.Echo MSG_SEPERATE
  256. WScript.Echo MSG_EXIT
  257. WSCript.Quit
  258.  
  259. End Function
  260. '////////////////////////////////////////////////////////////////////////////////////////
  261. '////////////////////////////////////////////////////////////////////////////////////////
  262. Function verifyFileExists(file)
  263.  
  264. If Not objFSO.FileExists(file) Then
  265.     If file = currentDir & "slerror.xml" Then
  266.         WScript.Echo "[" & MSG_FILENOTFOUND & file &  "  Unable to display error description.]"
  267.     ElseIf file = currentDir & "ospp.htm" Then
  268.         globalPopFailure MSG_FILENOTFOUND & vbCr & file,False
  269.         quitExit()
  270.     Else
  271.         globalPopFailure MSG_FILENOTFOUND & vbCr & file,True
  272.     End If
  273. End If
  274.  
  275. End Function
  276. '////////////////////////////////////////////////////////////////////////////////////////
  277. '////////////////////////////////////////////////////////////////////////////////////////
  278. Function registerMof(strFile)
  279.  
  280. For Each Drv In objFSO.Drives
  281.     If Drv.DriveType=2 Then
  282.         If objFSO.FileExists(Drv.DriveLetter & STR_SYS32PATH & "wbem\mofcomp.exe") Then
  283.             foundComp = True
  284.             strMofExePath = Drv.DriveLetter & STR_SYS32PATH & "wbem\mofcomp.exe"
  285.             If objFSO.FileExists(Drv.DriveLetter & STR_SYS32PATH & "wbem\" & strFile) Then
  286.                 foundMof = True
  287.                 strOWmi = Drv.DriveLetter & STR_SYS32PATH & "wbem\" & strFile
  288.                 Set objScriptExec = WshShell.Exec (strMofExePath & " " & strOWmi)
  289.                 readOut = objScriptExec.StdOut.ReadAll
  290.                 WScript.Echo readOut
  291.                 quitExit()
  292.             End If
  293.         End If
  294.     End If
  295. Next
  296.  
  297. If foundComp <> True Then
  298.     globalPopFailure MSG_FILENOTFOUND & Replace(STR_SYS32PATH,":","") & "wbem\mofcomp.exe",True
  299. Else
  300.     If foundMof <> True Then
  301.         globalPopFailure MSG_FILENOTFOUND & Replace(STR_SYS32PATH,":","") & "wbem\osppwmi.mof",True
  302.     End If
  303. End If
  304.  
  305. End Function
  306. '////////////////////////////////////////////////////////////////////////////////////////
  307. '////////////////////////////////////////////////////////////////////////////////////////
  308. Function pProcessing()
  309.  
  310. WScript.Echo MSG_PROCESSING
  311. WScript.Echo MSG_SEPERATE
  312.     
  313. End Function
  314. '////////////////////////////////////////////////////////////////////////////////////////
  315. '////////////////////////////////////////////////////////////////////////////////////////
  316. Function getSlui()
  317.  
  318. For Each Drv In objFSO.Drives
  319.     If Drv.DriveType=2 Then
  320.         If objFSO.FileExists(Drv.DriveLetter & STR_SYS32PATH & "slui.exe") Then
  321.             strSluiPath = Drv.DriveLetter & STR_SYS32PATH & "slui.exe"
  322.             foundSlUi = True
  323.             Exit For
  324.         End If
  325.     End If
  326. Next
  327.  
  328. End Function
  329. '////////////////////////////////////////////////////////////////////////////////////////
  330. '////////////////////////////////////////////////////////////////////////////////////////
  331. Function InstallKMSLicense(objSPP,licFile)
  332.  
  333. WScript.Echo MSG_INSTALLLICENSE & licFile
  334.  
  335. LicenseData = ReadAllTextFile(licFile)
  336. sppErrHandle()
  337.  
  338. objSpp.InstallLicense(LicenseData)
  339. sppErrHandle()
  340.     
  341. End Function
  342. '////////////////////////////////////////////////////////////////////////////////////////
  343. '////////////////////////////////////////////////////////////////////////////////////////
  344. ' Returns the encoding for a givven file.
  345. ' Possible return values: ascii, unicode, unicodeFFFE (big-endian), utf-8
  346. Function GetFileEncoding(strFileName)
  347.     Dim strData
  348.     Dim strEncoding
  349.  
  350.     Set oStream = CreateObject("ADODB.Stream")
  351.  
  352.     oStream.Type = 1 'adTypeBinary
  353.     oStream.Open
  354.     oStream.LoadFromFile(strFileName)
  355.  
  356.     ' Default encoding is ascii
  357.     strEncoding =  "ascii"
  358.  
  359.     strData = BinaryToString(oStream.Read(2))
  360.  
  361.     ' Check for little endian (x86) unicode preamble
  362.     If (Len(strData) = 2) and strData = (Chr(255) + Chr(254)) Then
  363.         strEncoding = "unicode"
  364.     Else
  365.         oStream.Position = 0
  366.         strData = BinaryToString(oStream.Read(3))
  367.  
  368.         ' Check for utf-8 preamble
  369.         If (Len(strData) >= 3) and strData = (Chr(239) + Chr(187) + Chr(191)) Then
  370.             strEncoding = "utf-8"
  371.         End If
  372.     End If
  373.  
  374.     oStream.Close
  375.  
  376.     GetFileEncoding = strEncoding
  377.     
  378. End Function
  379. '////////////////////////////////////////////////////////////////////////////////////////
  380. '////////////////////////////////////////////////////////////////////////////////////////
  381. ' Converts binary data (VT_UI1 | VT_ARRAY) to a string (BSTR)
  382. Function BinaryToString(dataBinary)  
  383.     Dim i
  384.     Dim str
  385.  
  386.     For i = 1 To LenB(dataBinary)
  387.         str = str & Chr(AscB(MidB(dataBinary, i, 1)))
  388.     Next
  389.  
  390.     BinaryToString = str
  391.     
  392. End Function
  393. '////////////////////////////////////////////////////////////////////////////////////////
  394. '////////////////////////////////////////////////////////////////////////////////////////
  395. ' Returns string containing the whole text file data. 
  396. ' Supports ascii, unicode (little-endian) and utf-8 encoding.
  397. Function ReadAllTextFile(strFileName)
  398.     Dim strData
  399.     Set oStream = CreateObject("ADODB.Stream")
  400.  
  401.     oStream.Type = 2 'adTypeText
  402.     oStream.Open
  403.     oStream.Charset = GetFileEncoding(strFileName)
  404.     oStream.LoadFromFile(strFileName)
  405.  
  406.     strData = oStream.ReadText(-1) 'adReadAll
  407.  
  408.     oStream.Close
  409.  
  410.     ReadAllTextFile = strData
  411.     
  412. End Function
  413. '////////////////////////////////////////////////////////////////////////////////////////
  414. '////////////////////////////////////////////////////////////////////////////////////////
  415. Function sppErrHandle(strCommand)
  416.  
  417. globalErr = Hex(Err.Number)
  418.  
  419. Select Case Err.Number
  420.     Case 0
  421.         'Success
  422.         Select Case strCommand
  423.             Case "/act","/tokact"
  424.                 WScript.Echo MSG_ACTSUCCESS
  425.             Case "/inpkey"
  426.                 WScript.Echo MSG_KEYINSTALLSUCCESS
  427.                 quitExit()
  428.             Case "/inslic"
  429.                 WScript.Echo MSG_INSTALLLICSUCCESS
  430.                 quitExit()
  431.             Case "/sethst","/setprt","/remhst","/stokflag","/ctokflag"
  432.                 WScript.Echo MSG_SUCCESS
  433.                 quitExit()
  434.             Case "/rtokil"
  435.                 WScript.Echo MSG_REMILID & UCase(strValue)
  436.                 quitExit()
  437.             Case "/unpkey"
  438.                 WScript.Echo MSG_UNINSTALLKEYSUCCESS
  439.                 quitExit()
  440.             Case Else
  441.         End Select
  442.     Case Else
  443.         verifyFileExists currentDir & "slerror.xml"
  444.         getResource("err" & "0x" & globalErr)
  445.         If globalResource = "" Then
  446.             If Len(globalErr) <> "8" Then
  447.                 WScript.Echo MSG_ERRDESC & MSG_ERRUNKNOWN
  448.             Else
  449.                 If foundSlUi = True Then
  450.                     WScript.Echo MSG_ERRCODE & "0x" & globalErr
  451.                     WScript.Echo MSG_ERRDESC & "Run the following: cscript ospp.vbs /ddescr:0x" & globalErr
  452.                 Else
  453.                     WScript.Echo MSG_ERRCODE & "0x" & globalErr 
  454.                 End If
  455.             End If
  456.         Else
  457.             WScript.Echo MSG_ERRCODE & "0x" & globalErr 
  458.             Wscript.Echo MSG_ERRDESC & globalResource
  459.         End If
  460.         
  461.         If strCommand = "/dtokcerts" Or strCommand = "/ignore" Then
  462.             quitExit()
  463.         End If
  464. End Select
  465.  
  466. If globalErr = "C004F074" Then
  467.     WScript.Echo "To view the activation event history run: cscript " & WScript.ScriptName & " /dhistorykms"
  468. End If
  469.  
  470. globalResource = ""
  471. globalErr = ""
  472. Err.Clear
  473.  
  474. End Function
  475. '////////////////////////////////////////////////////////////////////////////////////////
  476. '////////////////////////////////////////////////////////////////////////////////////////
  477. Function ErrHandle()
  478.  
  479. globalErr = Hex(Err.Number)
  480. sppErrHandle()
  481.  
  482. End Function
  483. '////////////////////////////////////////////////////////////////////////////////////////
  484. '////////////////////////////////////////////////////////////////////////////////////////
  485. Function wmiErrHandle()
  486.  
  487. Select Case Err.Number
  488.     Case 0
  489.         'Successs
  490.     Case 424
  491.         globalPopFailure MSG_ERRCODE & Err.Number & vbCr & MSG_ERRDESC & MSG_CREDENTIALFAILURE,True            
  492.     Case Else
  493.         If Err.Description <> "" Then
  494.             globalPopFailure MSG_ERRCODE & Err.Number & vbCr & MSG_ERRDESC & Err.Description,True
  495.         Else
  496.             globalPopFailure "An error occurred while making the connection." & vbCr & MSG_ERRCODE & Err.Number,True
  497.         End If
  498. End Select
  499.  
  500. End Function
  501. '////////////////////////////////////////////////////////////////////////////////////////
  502. '////////////////////////////////////////////////////////////////////////////////////////
  503. Function setRegValue(wmiObject,opsValue,strValueName)
  504.  
  505. On Error Resume Next
  506.  
  507. Err.Clear()
  508. strKeyPath = REG_SPP
  509.  
  510. Select Case strValueName
  511.     Case "UserOperations"
  512.         wmiObject.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
  513.         wmiObject.SetDWORDValue HKEY_LOCAL_MACHINE,_
  514.             strKeyPath,strValueName,opsValue
  515.     Case Else
  516. End Select
  517.  
  518. wmiErrHandle()
  519. WScript.Echo MSG_SUCCESS
  520. quitExit()
  521.  
  522. End Function
  523. '////////////////////////////////////////////////////////////////////////////////////////
  524. '////////////////////////////////////////////////////////////////////////////////////////
  525. Function getResource(resource)
  526.  
  527. On Error Resume Next
  528. Set xmlDoc = CreateObject("Msxml2.DOMDocument") 
  529. xmlDoc.load(currentDir & "slerror.xml")  
  530. Set ElemList = xmlDoc.getElementsByTagName(resource) 
  531. resValue = ElemList.item(0).text
  532. globalResource = resValue 
  533.  
  534. End Function
  535. '////////////////////////////////////////////////////////////////////////////////////////
  536. '////////////////////////////////////////////////////////////////////////////////////////
  537. Function globalPopSuccess(strSuccess,boolQuit)
  538.  
  539. If boolQuit = True Then
  540.     WshShell.Popup strSuccess,,WScript.ScriptName, wshOK + VALUE_ICON_INFORMATION
  541.     quitExit()
  542. Else
  543.     WshShell.Popup strSuccess,,WScript.ScriptName, wshOK + VALUE_ICON_INFORMATION
  544. End If
  545.  
  546. End Function
  547. '////////////////////////////////////////////////////////////////////////////////////////
  548. '////////////////////////////////////////////////////////////////////////////////////////
  549. Function globalPopFailure(strFailure,boolQuit)
  550.  
  551. If boolQuit = True Then
  552.     WshShell.Popup strFailure,,WScript.ScriptName, wshOK + VALUE_ICON_WARNING
  553.     quitExit()
  554. Else
  555.     WshShell.Popup strFailure,,WScript.ScriptName, wshOK + VALUE_ICON_WARNING
  556. End If
  557.  
  558. End Function
  559. '////////////////////////////////////////////////////////////////////////////////////////
  560. '////////////////////////////////////////////////////////////////////////////////////////
  561. Function connectWMI(strMachine,strUser,strPassword,ctype)
  562.  
  563. On Error Resume Next
  564.  
  565. If ctype = "" Then
  566.     If strMachine = "" Or LCase(strMachine) = LCase(strLocal) Then
  567.         Set objWMI = GetObject("winmgmts:" _
  568.                 & "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
  569.     Else
  570.         If strUser = "" And strPassword = "" Then
  571.             Set objWMI = GetObject("winmgmts:" _
  572.                 & "{impersonationLevel=impersonate}!\\" & strMachine & "\root\cimv2")
  573.         Else
  574.             Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
  575.             Set objWMI = objSWbemLocator.ConnectServer _
  576.                 (strMachine, "\root\cimv2", strUser, strPassword)
  577.             wmiErr = CStr(Hex(Err.Number))
  578.             If Len(wmiErr) = "8" Then
  579.                 getDescription "0x" & wmiErr,"wmi"
  580.             End If
  581.             objWMI.Security_.ImpersonationLevel = 3
  582.         End If
  583.     End If
  584. Else
  585.     If strUser <> "" Then
  586.         globalPopFailure MSG_CREDENTIALERR,True
  587.     End If
  588.  
  589.     If strMachine = "" Or LCase(strMachine) = LCase(strLocal) Then
  590.         Set objWMI = GetObject("winmgmts:" _
  591.             & "{impersonationLevel=impersonate}!\\" & "." & "\root\default:StdRegProv")
  592.             
  593.         Set objWMI1 = GetObject("winmgmts:" _
  594.                 & "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
  595.     Else
  596.         Set objWMI = GetObject("winmgmts:" _
  597.             & "{impersonationLevel=impersonate}!\\" & strMachine & "\root\default:StdRegProv")
  598.             
  599.         Set objWMI1 = GetObject("winmgmts:" _
  600.                 & "{impersonationLevel=impersonate}!\\" & strMachine & "\root\cimv2")
  601.     End If
  602. End If
  603.  
  604. wmiErrHandle()
  605.  
  606. End Function
  607. '////////////////////////////////////////////////////////////////////////////////////////
  608. '////////////////////////////////////////////////////////////////////////////////////////
  609. Private Function TkaGetSigner()
  610.  
  611. On Error Resume Next
  612.  
  613.     Set TkaGetSigner = WScript.CreateObject("OSPPWMI.OSppWmiTokenActivationSigner")
  614.     If Hex(Err.Number) = "80020009" Then
  615.         globalPopFailure MSG_ERRCODE & "0x" & Hex(Err.Number) & vbCr & MSG_ERRDESC & Err.Description,True
  616.     End If
  617.  
  618. End Function
  619. '////////////////////////////////////////////////////////////////////////////////////////
  620. '////////////////////////////////////////////////////////////////////////////////////////
  621. Function TkaPrintCertificate(strThumbprint)
  622.  
  623.     arrParams = Split(strThumbprint, "|")
  624.     WScript.Echo "Thumbprint: " & arrParams(0)
  625.     WScript.Echo "Subject: " & arrParams(1)
  626.     WScript.Echo "Issuer: " & arrParams(2)
  627.     vf = FormatDateTime(CDate(arrParams(3)), vbShortDate)
  628.     WScript.Echo "Valid From: " & vf
  629.     vt = FormatDateTime(CDate(arrParams(4)), vbShortDate)
  630.     WScript.Echo "Valid To: " & vt
  631.     WScript.Echo MSG_SEPERATE
  632.     
  633. End Function
  634. '////////////////////////////////////////////////////////////////////////////////////////
  635. '////////////////////////////////////////////////////////////////////////////////////////
  636. Function ExecuteQuery(strSelect,strWhere,strClass)
  637.     
  638. Err.Clear
  639.     
  640. If strWhere = "" Then
  641.     Set productinstances = objWMI.ExecQuery("SELECT " & strSelect & " FROM " & strClass)
  642. Else
  643.     Set productinstances = objWMI.ExecQuery("SELECT " & strSelect & " FROM " & strClass & " WHERE " & strWhere)
  644. End If
  645.     
  646. sppErrHandle ""
  647.  
  648. End Function
  649. '////////////////////////////////////////////////////////////////////////////////////////
  650. '////////////////////////////////////////////////////////////////////////////////////////
  651. Function performLicAction(strCommand,strValue,strMachine)
  652.  
  653. On Error Resume Next
  654.  
  655. If strCommand = "/dhistorykms" Or strCommand = "/dhistoryacterr" Then
  656.     verifyFileExists currentDir & "slerror.xml"
  657.     If strCommand = "/dhistorykms" Then
  658.         '12288 = KMS Activation event id
  659.         eventCode = "12288"
  660.         strSrcEvents = MSG_SEARCHEVENTSKMS
  661.         strNoEvents = MSG_NOEVENTSSKMS
  662.     Else
  663.         '8200 = Internet Activation event id
  664.         eventCode = "8200"
  665.         strSrcEvents = MSG_SEARCHEVENTSRET
  666.         strNoEvents = MSG_NOEVENTSRET
  667.     End If
  668.     
  669.     If strMachine <> "" Then
  670.         WScript.Echo strSrcEvents & strMachine
  671.     Else
  672.         WScript.Echo strSrcEvents & strLocal
  673.     End If
  674.     
  675.     WScript.Echo "Event ID: " & eventCode
  676.     WScript.Echo vbCr
  677.     Set objEvents = objWMI.ExecQuery _
  678.         ("Select * from Win32_NTLogEvent Where Logfile = 'Application' and " _
  679.         & "EventCode = '" & eventCode & "'")
  680.         If objEvents.Count > 0 Then
  681.             For each objEvent in objEvents
  682.                 If strCommand = "/dhistoryacterr" Then
  683.                     i = i + 1
  684.                     dtmEventDate = objEvent.TimeWritten
  685.                     strTimeWritten = WMIDateStringToDate(dtmEventDate)
  686.                     WScript.Echo "Coordinated Universal Time Written: " & strTimeWritten
  687.                     strReplCrs = Replace(objEvent.Message,vbCrLf,"")
  688.                     WScript.Echo "MESSAGE: " & strReplCrs
  689.                     strhr10 = Right(strReplCrs,10)
  690.                     getResource("err" & strhr10)
  691.                     If globalResource = "" Then
  692.                         If foundSlUi = True Then
  693.                             WScript.Echo MSG_ERRDESC & "Run the following: cscript ospp.vbs /ddescr:" & strhr10
  694.                         Else
  695.                             WScript.Echo MSG_ERRDESC & "Not available."
  696.                         End If
  697.                     Else
  698.                         Wscript.Echo MSG_ERRDESC & globalResource
  699.                     End If
  700.                     WScript.Echo MSG_SEPERATE        
  701.                 Else
  702.                     strhr10 = Mid(objEvent.Message,90,10)
  703.                     strReplCrs = Replace(objEvent.Message,vbCrLf,"")
  704.                     If Right(strReplCrs,2) = " 5" Then
  705.                         strReplStrs = Replace(strReplCrs,"The client has sent an activation request to the key management service machine.Info:","")
  706.                         dtmEventDate = objEvent.TimeWritten
  707.                         strTimeWritten = WMIDateStringToDate(dtmEventDate)
  708.                         WScript.Echo "Coordinated Universal Time Written: " & strTimeWritten
  709.                         intColon = InStr(strReplStrs,":")
  710.                         strErrHost = Left(strReplStrs,intColon)
  711.                         strErrHost = Trim(strErrHost)
  712.                         strErrHost = Replace(strErrHost,":","")
  713.                         WScript.Echo "ERROR/HOST: " & strErrHost
  714.                         Select Case strhr10
  715.                             Case "0x00000000"
  716.                                 WScript.Echo MSG_ERRDESC & "N/A"
  717.                             Case Else
  718.                                 getResource("err" & strhr10)
  719.                                 If globalResource = "" Then
  720.                                     If foundSlUi = True Then
  721.                                         WScript.Echo MSG_ERRDESC & "Run the following: cscript ospp.vbs /ddescr:" & strhr10
  722.                                     Else
  723.                                         WScript.Echo MSG_ERRDESC & "Not available."
  724.                                     End If
  725.                                 Else
  726.                                     Wscript.Echo MSG_ERRDESC & globalResource
  727.                                 End If
  728.                         End Select
  729.                         WScript.Echo MSG_SEPERATE
  730.                     End If
  731.                 End If
  732.             Next
  733.         Else
  734.             WScript.Echo MSG_SEPERATE
  735.             If strMachine <> "" Then
  736.                 WScript.Echo strNoEvents & strMachine
  737.             Else
  738.                 WScript.Echo strNoEvents & strLocal
  739.             End If
  740.             WScript.Echo MSG_SEPERATE
  741.         End If
  742.         quitExit()
  743. End If
  744.  
  745. Set colListOfServices = objWMI.ExecQuery _
  746.     ("Select * from Win32_Service ")
  747. For Each objService in colListOfServices
  748.     If objService.Name = "osppsvc" Then
  749.         installed = True
  750.         If LCASE(objService.State) = "running" Then
  751.             running = True
  752.         End If
  753.         Exit For
  754.     End If
  755. Next
  756.     
  757. If installed <> True Then
  758.     globalPopFailure MSG_OSPPSVC_NOINSTALL,True
  759. End If
  760.  
  761. If running <> True Then
  762.     Set colOperatingSystems = objWMI.ExecQuery _
  763.         ("Select * from Win32_OperatingSystem")
  764.     For Each objOperatingSystem in colOperatingSystems
  765.         strOsVersion = Left(objOperatingSystem.Version,3)
  766.         Exit For
  767.     Next
  768.     
  769.     Select Case strOsVersion
  770.         Case "5.0", "5.1", "5.2"
  771.             globalPopFailure MSG_OSPPSVC_NORUN & vbcr & "Current State: " & objService.State & vbCr & "Run: cscript ospp.vbs /osppsvcrestart",True
  772.         Case Else
  773.     End Select    
  774. End If
  775.         
  776. Select Case strCommand
  777.     Case "/inpkey", "/dcmid", "/inslic", "/sethst", "/setprt", "/remhst", "/stokflag", "/ctokflag"
  778.         For Each objService in objWMI.InstancesOf("OfficeSoftwareProtectionService")
  779.             Set objOspp = objService
  780.             Exit For
  781.         Next
  782.     Case Else
  783. End Select
  784.  
  785. sppErrHandle ""
  786.  
  787. If strCommand = "/inpkey" Then
  788.         i = i + 1
  789.         Err.Clear
  790.         objOspp.InstallProductKey(strValue)
  791.         SppErrHandle(strCommand)
  792. ElseIf strCommand = "/dcmid" Then
  793.     If objOspp.ClientMachineID <> "" Or objOspp.ClientMachineID <> Null Then
  794.         WScript.Echo MSG_CMID & objOspp.ClientMachineID
  795.     Else
  796.         WScript.Echo MSG_CMID & "Not found."
  797.     End If
  798.     quitExit()
  799. ElseIf strCommand = "/inslic" Then
  800.     i = i + 1
  801.     If Right(strValue,7) = ".xrm-ms" Then
  802.         verifyFileExists strValue
  803.         WScript.Echo MSG_INSTALLLICENSE & strValue
  804.     Else
  805.         globalPopFailure MSG_UNRECOGFILE,True
  806.     End If
  807.     LicenseData = ReadAllTextFile(strValue)
  808.     objOSpp.InstallLicense(LicenseData)
  809.     SppErrHandle(strCommand)
  810. ElseIf strCommand = "/sethst" Then
  811.     i = i + 1
  812.     objOspp.SetKeyManagementServiceMachine(strValue)
  813.     SppErrHandle(strCommand)
  814. ElseIf strCommand = "/setprt" Then
  815.     i = i + 1
  816.     objOspp.SetKeyManagementServicePort(strValue)
  817.     SppErrHandle(strCommand)
  818. ElseIf strCommand = "/remhst" Then
  819.     i = i + 1
  820.     objOspp.ClearKeyManagementServiceMachine()
  821.     sppErrHandle ""
  822.     objOspp.ClearKeyManagementServicePort()
  823.     SppErrHandle(strCommand)
  824. ElseIf strCommand = "/stokflag" Then
  825.     i = i + 1
  826.     objOspp.DisableKeyManagementServiceActivation(True)
  827.     SppErrHandle(strCommand)
  828. ElseIf strCommand = "/ctokflag" Then
  829.     i = i + 1
  830.     objOspp.DisableKeyManagementServiceActivation(False)
  831.     SppErrHandle(strCommand)
  832. ElseIf strCommand = "/dtokils" Then
  833.     Err.Clear
  834.     Set objWmiDate = CreateObject("WBemScripting.SWbemDateTime")
  835.     ExecuteQuery "ILID, ILVID, AuthorizationStatus, ExpirationDate, Description, AdditionalInfo","","OfficeSoftwareProtectionTokenActivationLicense"
  836.     
  837.     For Each instance in productinstances
  838.         sppErrHandle ""
  839.         i = i + 1
  840.         WScript.Echo "License ID (ILID): " & instance.ILID
  841.         WScript.Echo "Version ID (ILvID): " & instance.ILVID
  842.         If Not IsNull(instance.ExpirationDate) Then
  843.             objWmiDate.Value = instance.ExpirationDate
  844.             If (objWmiDate.GetFileTime(false) <> 0) Then
  845.                 WScript.Echo "Expiry Date: " & objWmiDate.GetVarDate
  846.             End If
  847.         End If
  848.         If Not IsNull(instance.AdditionalInfo) Then
  849.             WScript.Echo "Additional Info: " & instance.AdditionalInfo
  850.         End If
  851.         If Not IsNull(instance.AuthorizationStatus) And instance.AuthorizationStatus <> 0 Then
  852.             globalErr = CStr(Hex(instance.AuthorizationStatus))
  853.             sppErrHandle()
  854.         Else            
  855.             WScript.Echo "Description: " & instance.Description
  856.         End If
  857.         WScript.Echo MSG_SEPERATE
  858.     Next
  859.     If i = 0 Then
  860.         WScript.Echo MSG_NOLICENSEFOUND
  861.     End If
  862.     quitExit()
  863. ElseIf strCommand = "/rtokil" Then
  864.     Err.Clear    
  865.     ExecuteQuery "ILID, ID","","OfficeSoftwareProtectionTokenActivationLicense"
  866.     
  867.     For Each instance in productinstances
  868.         sppErrHandle ""
  869.         i = i + 1
  870.         If LCase(strValue) = LCase(instance.ILID) Then
  871.             instance.Uninstall
  872.             SppErrHandle(strCommand)
  873.         Else
  874.             WScript.Echo MSG_NOTFOUNDILID & strValue & " Run /dtokils to display the ILID for installed licenses."
  875.         End If
  876.     Next
  877.     If i = 0 Then
  878.         WScript.Echo MSG_NOLICENSEFOUND
  879.     End If
  880.     quitExit()
  881. ElseIf strCommand = "/dtokcerts" Then
  882.     Err.Clear
  883.     Set objSigner = TkaGetSigner()
  884.     sppErrHandle(strCommand)
  885.     ExecuteQuery "ID, Name, ApplicationId, PartialProductKey, Description, LicenseIsAddon ","ApplicationId = '" & OfficeAppId & "' " & "AND PartialProductKey <> NULL " & "AND LicenseIsAddon = FALSE","OfficeSoftwareProtectionProduct"
  886.     
  887.     For each instance in productinstances
  888.         i = i + 1
  889.         sppErrHandle ""
  890.         iRet = instance.GetTokenActivationGrants(arrGrants)
  891.         If Err.Number = 0 Then
  892.             arrThumbprints = objSigner.GetCertificateThumbprints(arrGrants)
  893.             If Err.Number = 0 Then
  894.                 For Each strThumbprint in arrThumbprints
  895.                     TkaPrintCertificate strThumbprint
  896.                 Next
  897.             Else
  898.                 sppErrHandle ""
  899.             End If
  900.         Else
  901.             sppErrHandle ""
  902.         End If
  903.         WScript.Echo MSG_SEPERATE
  904.         Err.Clear
  905.     Next
  906. ElseIf strCommand = "/tokact" Then
  907.     Err.Clear
  908.     Set objSigner  = TkaGetSigner()
  909.     sppErrHandle "/ignore"
  910.     pos1 = InStr(strValue,":")
  911.     If pos1 = 0 Then
  912.         'PIN not passed
  913.         strThumbprint = strValue
  914.     Else
  915.         'PIN passed
  916.         strThumbprint = Left(strValue,pos1 - 1)
  917.         strPin = Replace(strValue,strThumbprint & ":","")
  918.     End If
  919.     
  920.     ExecuteQuery "ID, Name, ApplicationId, PartialProductKey, Description, LicenseIsAddon ","ApplicationId = '" & OfficeAppId & "' " & "AND PartialProductKey <> NULL " & "AND LicenseIsAddon = FALSE","OfficeSoftwareProtectionProduct"
  921.     
  922.     For each instance in productinstances
  923.         i = i + 1
  924.         sppErrHandle ""        
  925.         WScript.Echo MSG_TOKACTATTEMPT 
  926.         WScript.Echo MSG_SKUID & instance.ID
  927.         WScript.Echo MSG_LICENSENAME & instance.Name
  928.         WScript.Echo MSG_DESCRIPTION & instance.Description
  929.         WScript.Echo MSG_PARTIALKEY & instance.PartialProductKey
  930.         iRet = instance.GenerateTokenActivationChallenge(strChallenge)
  931.         If Err.Number = 0 Then
  932.             strAuthInfo1 = objSigner.Sign(strChallenge, strThumbprint, strPin, strAuthInfo2)
  933.             If Err.Number = 0 Then
  934.                 iRet = instance.DepositTokenActivationResponse(strChallenge, strAuthInfo1, strAuthInfo2)
  935.                 SppErrHandle(strCommand)
  936.             Else
  937.                 sppErrHandle ""
  938.             End If
  939.         Else
  940.             sppErrHandle ""
  941.         End If
  942.         WScript.Echo MSG_SEPERATE
  943.     Next
  944. Else
  945.     Err.Clear
  946.     If strCommand = "/dstatus" or strCommand = "/dstatusall" Then
  947.         ExecuteQuery "ID, ApplicationId, PartialProductKey, Description, Name, LicenseStatus, LicenseStatusReason, ProductKeyID, GracePeriodRemaining","","OfficeSoftwareProtectionProduct"
  948.     ElseIf strCommand = "/act" Then
  949.         ExecuteQuery "ID, ApplicationId, PartialProductKey, Description, Name","PartialProductKey <> null","OfficeSoftwareProtectionProduct"
  950.     ElseIf strCommand = "/unpkey" Then
  951.         ExecuteQuery "ID, ApplicationId, PartialProductKey, Name, ProductKeyID","","OfficeSoftwareProtectionProduct"
  952.     ElseIf strCommand = "/dinstid" Or strCommand = "/actcid" Then
  953.         ExecuteQuery "ID, ApplicationId, PartialProductKey, Name, OfflineInstallationId","PartialProductKey <> null","OfficeSoftwareProtectionProduct"
  954.     End If
  955.             
  956.     For Each instance in productinstances
  957.         sppErrHandle ""
  958.         If (LCase(instance.ApplicationId) = OfficeAppId) Then
  959.             If instance.PartialProductKey <> "" Then
  960.                 i = i + 1
  961.             End If
  962.             Select Case strCommand
  963.                 Case "/act"
  964.                     WScript.Echo MSG_ACTATTEMPT 
  965.                     WScript.Echo MSG_SKUID & instance.ID
  966.                     WScript.Echo MSG_LICENSENAME & instance.Name
  967.                     WScript.Echo MSG_DESCRIPTION & instance.Description
  968.                     WScript.Echo MSG_PARTIALKEY & instance.PartialProductKey            
  969.                     instance.Activate
  970.                     SppErrHandle(strCommand)
  971.                     WScript.Echo MSG_SEPERATE
  972.                 Case "/unpkey"
  973.                     If Len(strValue) <> "5" Then
  974.                         globalPopFailure MSG_ERRPARTIALKEY,True
  975.                     End If
  976.                     If UCase(strValue) = instance.PartialProductKey Then
  977.                         y = y + 1
  978.                         WScript.Echo MSG_UNINSTALLKEY & instance.Name
  979.                         instance.UninstallProductKey(instance.ProductKeyID)                            
  980.                         SppErrHandle(strCommand)
  981.                     End If
  982.                 Case "/dinstid"
  983.                     WScript.Echo "Installation ID for: " & instance.Name & ": " & instance.OfflineInstallationId
  984.                     WScript.Echo MSG_SEPERATE
  985.                 Case "/actcid"
  986.                     instance.DepositOfflineConfirmationId instance.OfflineInstallationId, strValue
  987.                     If Err.Number = 0 Then
  988.                         If telsuccess <> True Then
  989.                             WScript.Echo MSG_LICENSENAME & instance.Name
  990.                             WScript.Echo MSG_OFFLINEACTSUCCESS
  991.                             telsuccess = True
  992.                         End If
  993.                     Else
  994.                         WScript.Echo MSG_LICENSENAME & instance.Name
  995.                         sppErrHandle ""
  996.                     End If
  997.                     WScript.Echo MSG_SEPERATE
  998.                 Case "/dstatus", "/dstatusall"
  999.                     getInstalled = False
  1000.                     verifyFileExists currentDir & "slerror.xml"
  1001.                     licSr = Hex(instance.LicenseStatusReason)
  1002.                     If strCommand = "/dstatusall" Then
  1003.                         getInstalled = True
  1004.                         WScript.Echo MSG_SKUID & instance.ID
  1005.                         WScript.Echo MSG_LICENSENAME & instance.Name
  1006.                         WScript.Echo MSG_DESCRIPTION & instance.Description            
  1007.                     Else
  1008.                         If instance.ProductKeyID <> "" Then
  1009.                             getInstalled = True
  1010.                             WScript.Echo MSG_SKUID & instance.ID
  1011.                             WScript.Echo MSG_LICENSENAME & instance.Name
  1012.                             WScript.Echo MSG_DESCRIPTION & instance.Description
  1013.                         End If
  1014.                     End If
  1015.                     
  1016.                     If getInstalled = True Then
  1017.                         Select Case instance.LicenseStatus
  1018.                             Case 0
  1019.                                 WScript.Echo MSG_LICSTATUS & MSG_UNLICENSED
  1020.                             Case 1
  1021.                                 WScript.Echo MSG_LICSTATUS & MSG_LICENSED
  1022.                                     If licSr = 0 Then
  1023.                                         WScript.Echo MSG_ERRCODE & licSr & " as licensed"    
  1024.                                     End If
  1025.                             Case 2
  1026.                                 WScript.Echo MSG_LICSTATUS & MSG_OOBGRACE        
  1027.                             Case 3
  1028.                                 WScript.Echo MSG_LICSTATUS & MSG_OOTGRACE
  1029.                             Case 4
  1030.                                 WScript.Echo MSG_LICSTATUS & MSG_NONGENGRACE
  1031.                             Case 5
  1032.                                 WScript.Echo MSG_LICSTATUS & MSG_NOTIFICATION
  1033.                             Case 6
  1034.                                 WScript.Echo MSG_LICSTATUS & MSG_EXTENDEDGRACE    
  1035.                             Case Else
  1036.                                 WScript.Echo MSG_LICSTATUS & MSG_LICUNKNOWN
  1037.                         End Select
  1038.                             
  1039.                         If licSr <> "0" Then
  1040.                             WScript.Echo MSG_ERRCODE & "0x" & licSr
  1041.                             getResource("err" & "0x" & licSr)
  1042.                             If globalResource = "" Then
  1043.                                 If foundSlUi <> True Then
  1044.                                     WScript.Echo MSG_ERRDESC & "Not available."
  1045.                                 Else
  1046.                                     WScript.Echo MSG_ERRDESC & "Run the following: cscript ospp.vbs /ddescr:0x" & licSr
  1047.                                 End if
  1048.                             Else
  1049.                                 WScript.Echo MSG_ERRDESC & globalResource
  1050.                             End If
  1051.                         End If
  1052.                             
  1053.                         If instance.PartialProductKey <> "" Then
  1054.                             WScript.Echo MSG_PARTIALKEY & instance.PartialProductKey
  1055.                         End If
  1056.                             
  1057.                         If instance.GracePeriodRemaining <> 0 Then
  1058.                             dGrace = instance.GracePeriodRemaining / 60 / 24
  1059.                             WScript.Echo MSG_REMAINGRACE & Round(dGrace) & " days " & " (" & instance.GracePeriodRemaining & " minute(s) before expiring" & ")"
  1060.                         End If
  1061.                             WScript.Echo MSG_SEPERATE
  1062.                     End If
  1063.                 Case Else
  1064.             End Select
  1065.         End If
  1066.     Next
  1067. End If
  1068.  
  1069. If strCommand = "/unpkey" And y = 0 Then
  1070.     WScript.Echo MSG_KEYNOTFOUND
  1071.     quitExit()
  1072. End If
  1073.  
  1074. If i = 0 Then
  1075.     WScript.Echo MSG_NOKEYSINSTALLED
  1076.     WScript.Echo MSG_SEPERATE
  1077. End If
  1078. quitExit()
  1079.  
  1080. End Function
  1081. '////////////////////////////////////////////////////////////////////////////////////////
  1082. '////////////////////////////////////////////////////////////////////////////////////////
  1083. Function performRegAction(strCommand)
  1084.  
  1085. On Error Resume Next
  1086.  
  1087. Set colListOfServices = objWMI1.ExecQuery _
  1088.     ("Select * from Win32_Service ")
  1089. For Each objService in colListOfServices
  1090.     If objService.Name = "osppsvc" Then
  1091.         installed = True
  1092.         Exit For
  1093.     End If
  1094. Next
  1095.     
  1096. If installed <> True Then
  1097.     globalPopFailure MSG_OSPPSVC_NOINSTALL,True
  1098. End If
  1099.  
  1100. checkRegRights objWMI,REG_SPP
  1101.  
  1102. Select Case strCommand
  1103.     Case "/puserops"
  1104.         setRegValue objWMI,"1","UserOperations"
  1105.     Case "/duserops"
  1106.         setRegValue objWMI,"0","UserOperations"
  1107. End Select
  1108.  
  1109. End Function
  1110. '////////////////////////////////////////////////////////////////////////////////////////
  1111. '////////////////////////////////////////////////////////////////////////////////////////
  1112. Function performServiceAction(strCommand)
  1113.  
  1114. On Error Resume Next
  1115.  
  1116. Set colListOfServices = objWMI.ExecQuery _
  1117.     ("Select * from Win32_Service ")
  1118. For Each objService in colListOfServices
  1119.     If objService.Name = "osppsvc" Then
  1120.         installed = True
  1121.         Exit For
  1122.     End If
  1123. Next
  1124.     
  1125. If installed <> True Then
  1126.     globalPopFailure MSG_OSPPSVC_NOINSTALL,True
  1127. End If
  1128.  
  1129. Set objService = Nothing
  1130. Set colListOfServices = Nothing
  1131.  
  1132. If strCommand = "/osppsvcauto" Then
  1133.     Set colListOfServices = objWMI.ExecQuery _
  1134.         ("Select * from Win32_Service where StartMode = 'Manual' or StartMode = 'Disabled'")
  1135.         For Each objService in colListOfServices
  1136.             If LCase(objService.Name) = "osppsvc" Then
  1137.                 foundOsppNonAuto = True
  1138.                 objService.Change , , , , "Automatic"
  1139.                 WScript.Sleep(15000)
  1140.                 Exit For
  1141.             End If
  1142.         Next
  1143.         If foundOsppNonAuto <> True Then
  1144.             WScript.Echo "Service startup type already set to automatic: Office Software Protection Platform"
  1145.             quitExit()
  1146.         End If
  1147.         
  1148.         Set objService = Nothing
  1149.         Set colListOfServices = Nothing
  1150.         Set colListOfServices = objWMI.ExecQuery _
  1151.         ("Select * from Win32_Service where StartMode = 'Auto'")
  1152.         For Each objService in colListOfServices
  1153.             If LCase(objService.Name) = "osppsvc" Then
  1154.                 foundOsppAuto = True
  1155.                 WScript.Echo "Successfully set service startup to automatic:" & objService.DisplayName
  1156.                 quitExit()
  1157.             End If
  1158.         Next
  1159.         
  1160.         If foundOsppAuto <> True Then
  1161.             WScript.Echo "Unsuccessful setting service startup to automatic. " & MSG_ISCMD_ELEVATED
  1162.             quitExit()
  1163.         End If
  1164. Else
  1165.     Set colListOfServices = objWMI.ExecQuery _
  1166.         ("Select * from Win32_Service ")
  1167.     For Each objService in colListOfServices
  1168.         If LCase(objService.Name) = "osppsvc" Then
  1169.             Select Case LCase(objService.State)
  1170.                 Case "running"
  1171.                     objService.StopService()
  1172.                     WScript.Sleep(15000)
  1173.                     objService.StartService()
  1174.                     WScript.Sleep(15000)
  1175.                 Case Else
  1176.                     objService.StartService()
  1177.                     WScript.Sleep(15000)
  1178.             End Select
  1179.             Exit For
  1180.         End If
  1181.     Next
  1182.     
  1183.     Set objService = Nothing
  1184.     Set colListOfServices = Nothing
  1185.     Set colListOfServices = objWMI.ExecQuery _
  1186.         ("Select * from Win32_Service ")
  1187.     For Each objService in colListOfServices
  1188.         If LCase(objService.Name) = "osppsvc" Then
  1189.             If LCase(objService.State) = "running" Then
  1190.                 WScript.Echo "Successfully restarted: " & objService.DisplayName
  1191.                 quitExit()
  1192.             Else
  1193.                 WScript.Echo "Unsuccessful restart: " & objService.DisplayName & ". Status: " _
  1194.                     & objService.State & ". " & MSG_ISCMD_ELEVATED
  1195.                 quitExit()
  1196.             End If
  1197.             Exit For
  1198.         End If
  1199.     Next
  1200. End If
  1201.  
  1202. End Function
  1203. '////////////////////////////////////////////////////////////////////////////////////////
  1204. '////////////////////////////////////////////////////////////////////////////////////////