forked from VHAE04/Activate.AIO.Tools.v3.1.3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOSPP.VBS
2038 lines (1864 loc) · 90.3 KB
/
OSPP.VBS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'Copyright (c) Microsoft Corporation. All rights reserved.
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
CONST wshOK =0
CONST VALUE_ICON_WARNING =16
CONST wshYesNoDialog =4
CONST VALUE_ICON_QUESTIONMARK =32
CONST VALUE_ICON_INFORMATION =64
CONST HKEY_LOCAL_MACHINE =&H80000002
CONST KEY_SET_VALUE =&H0002
CONST KEY_QUERY_VALUE =&H0001
CONST REG_SZ =1
CONST OfficeAppId = "0ff1ce15-a989-479d-af46-f275c6370663"
CONST STR_SYS32PATH = ":\Windows\System32\"
CONST STR_OSPPREARMPATH = "\Microsoft Office\Office16\OSPPREARM.EXE"
CONST STR_OSPPREARMPATH_DEBUG = "\Microsoft Office Debug\Office16\OSPPREARM.EXE"
CONST REG_OSPP = "SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform"
CONST STR_HEARTBEATPATH = "\Microsoft\Office\Heartbeat\HeartbeatCache.xml"
CONST REG_SPP = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform"
CONST VER_INFO = "Version Info: 2016 1.0"
'////////////////////////////////////////////////////////////////////////////////////////
CONST MSG_NOREGRIGHTS = "Insufficient rights to perform operation."
CONST MSG_ISCMD_ELEVATED = "Ensure cmd.exe is elevated (right click > run as administrator)."
CONST MSG_CREDENTIALFAILURE = "Connection failed with passed credentials."
CONST MSG_FILENOTFOUND = "File not found: "
CONST MSG_SEPERATESMALL = "---------------"
CONST MSG_SEPERATE = "---------------------------------------"
CONST MSG_PROCESSING = "---Processing--------------------------"
CONST MSG_EXIT = "---Exiting-----------------------------"
CONST MSG_UNSUPPORTED = "Unsupported command passed."
CONST MSG_UNSUPPORTEDOPEROS7 = "The following command is supported on Windows 7 only: "
CONST MSG_UNSUPPORTEDOPEROS8 = "The following command is supported on Windows 8 and above only: "
CONST MSG_UNSUPPORTEDLOCAL = "The following command is supported on local machine only: "
CONST MSG_CREDENTIALERR = "Passing credentials is not supported for this command."
CONST MSG_SUCCESS = "Successfully applied setting."
CONST MSG_NOKMSLICS = "No Office KMS licenses were found on the system."
CONST MSG_ACTATTEMPT = "Installed product key detected - attempting to activate the following product:"
CONST MSG_TOKACTATTEMPT = "Installed product key detected - attempting to token activate the following product:"
CONST MSG_NOKEYSINSTALLED = "<No installed product keys detected>"
CONST MSG_UNINSTALLKEYSUCCESS = "<Product key uninstall successful>"
CONST MSG_ACTSUCCESS = "<Product activation successful>"
CONST MSG_OFFLINEACTSUCCESS = "<Offline product activation successful>"
CONST MSG_KEYINSTALLSUCCESS = "<Product key installation successful>"
CONST MSG_PARTIALKEY = "Last 5 characters of installed product key: "
CONST MSG_UNINSTALLKEY = "Uninstalling product key for: "
CONST MSG_UNRECOGFILE = "Unrecognized file. Office licenses have an .xrm-ms file extension."
CONST MSG_INSTALLLICENSE = "Installing Office license: "
CONST MSG_INSTALLLICSUCCESS = "Office license installed successfully."
CONST MSG_SEARCHEVENTSKMS = "Searching for KMS activation events on machine: "
CONST MSG_SEARCHEVENTSRET = "Searching for Internet activation failure events on machine: "
CONST MSG_NOEVENTSSKMS = "No KMS activation events found on machine: "
CONST MSG_NOEVENTSRET = "No failure events found on machine: "
CONST MSG_OSPPSVC_NOINSTALL = "Error: The Software Protection Platform service is not installed."
CONST MSG_OSPPSVC_NORUN = "Error: The Software Protection Platform service is not running."
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."
CONST MSG_KEYNOTFOUND = "<Product key not found>"
CONST MSG_CMID = "Client Machine ID (CMID): "
CONST MSG_CMID_NOTFOUND = "Not found."
CONST MSG_NOLICENSEFOUND = "<No licenses found>"
CONST MSG_AUTHERR = "Authorization Error: 0x"
CONST MSG_REMILID = "Removed Token-based Activation License with License ID (ILID): "
CONST MSG_NOTFOUNDILID = "License not found with License ID (ILID): "
CONST MSG_KMSLOOKUP = "KMS Lookup Domain: "
CONST MSG_INFO_ONLY = " (for information purposes only as the status is licensed)"
CONST MSG_ACT_ERROR_FOUND_KB = "NOTICE: A KB article has been detected for activation failure: "
CONST MSG_ACT_ERROR_KB_LINK = "FOR MORE INFORMATION PLEASE VISIT: http://support.microsoft.com/kb/2870357#Error0x"
'////////////////////////////////////////////////////////////////////////////////////////
CONST MSG_VLActivationType = "Activation Type Configuration: "
'////////////////////////////////////////////////////////////////////////////////////////
CONST MSG_Act_Recent = "Most recent successful activation client information: "
CONST MSG_KMS_DNS = "KMS machine name from DNS: "
CONST MSG_KMS_DNS_ERR = "DNS auto-discovery: KMS name not available"
CONST MSG_ADInfoAOName = "Activation Object name: "
CONST MSG_ADInfoAODN = "AO DN: "
CONST MSG_ADInfoExtendedPid = "AO extended PID: "
CONST MSG_ADInfoActID = "AO activation ID: "
CONST MSG_ACTIVATION_INTERVAL = "Activation Interval: "
CONST MSG_RENEWAL_INTERVAL = "Renewal Interval: "
CONST MSG_HOST_CACHING = "KMS host caching: "
CONST MSG_HOST_REG_OVERRIDE = "KMS machine registry override defined: "
CONST MSG_DEFAULT_PORT = "1688"
'////////////////////////////////////////////////////////////////////////////////////////
CONST MSG_PID = "PRODUCT ID: "
CONST MSG_SKUID = "SKU ID: "
CONST MSG_LICENSENAME = "LICENSE NAME: "
CONST MSG_DESCRIPTION = "LICENSE DESCRIPTION: "
CONST MSG_LICSTATUS = "LICENSE STATUS: "
CONST MSG_LICENSED = " ---LICENSED--- "
CONST MSG_UNLICENSED = " ---UNLICENSED--- "
CONST MSG_OOBGRACE = " ---OOB_GRACE--- "
CONST MSG_OOTGRACE = " ---OOT_GRACE--- "
CONST MSG_NONGENGRACE = " ---NON_GENUINE_GRACE--- "
CONST MSG_NOTIFICATION = " ---NOTIFICATIONS--- "
CONST MSG_EXTENDEDGRACE = " ---EXTENDED GRACE--- "
CONST MSG_LICUNKNOWN = " ---UNKNOWN--- "
CONST MSG_REMAINGRACE = "REMAINING GRACE: "
CONST MSG_LICEXPIRY = "BETA EXPIRATION: "
CONST MSG_ERRCODE = "ERROR CODE: "
CONST MSG_ERRDESC = "ERROR DESCRIPTION: "
CONST MSG_ERRUNKNOWN = "An unknown error occurred."
CONST MSG_ERRCODEVALUE = "An error code must start with '0x'. Example: 0xC004F009"
'////////////////////////////////////////////////////////////////////////////////////////
CONST MSG_NOEVENTS = "No events found."
CONST MSG_HEARTBEAT_LOCALONLY = "HEARTBEATCACHE.XML SUPPORTED FOR LOCAL MACHINE ONLY."
CONST MSG_SEARCHFOR = "SEARCHING FOR INSTANCES OF "
CONST MSG_SEARCH_FORKEY = "SEARCHING FOR OFFICE PRODUCT KEYS ON MACHINE: "
CONST MSG_EVENT_1013 = "ACTIVATION SUCCESS EVENT: "
CONST MSG_EVENT_8200 = "ACTIVATION FAILURE EVENT: "
CONST MSG_EVENT_1016 = "INSTALL PRODUCT KEY SUCCESS EVENT: "
CONST MSG_EVENT_1017 = "INSTALL PRODUCT KEY FAILURE EVENT: "
CONST MSG_EVENT_2011 = "OLC-OLS EVENT: "
CONST MSG_NOKEYSINSTALLED_SUB = "<<<<< NO INSTALLED -SUBSCRIPTION- PRODUCT KEYS DETECTED >>>>>"
CONST MSG_NOKEYSINSTALLED_PERP = "<<<<< NO INSTALLED -PERPETUAL- PRODUCT KEYS DETECTED >>>>"
CONST MSG_KEYSINSTALLED_SUB = "<<<<< -SUBSCRIPTION- PRODUCT KEY DETECTED. REPORTING ON ADDITIONAL PROPERTIES >>>>>"
CONST MSG_KEYSINSTALLED_PERP = "<<<<< -PERPETUAL- PRODUCT KEY DETECTED. REPORTING ON ADDITIONAL PROPERTIES >>>>>"
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
On Error Resume Next
Set WshShell = WSCript.CreateObject("WSCript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = WSCript.CreateObject("WSCript.Network")
Dim globalResource, globalErr, foundSlUi, strSluiPath, strLocal, objWMI, objWMI1, wmiErr, productinstances, strValue, Win7, productClass, tokenClass, intIsKms, kmsCounter, isAdActivated, dlicense, foundSubKey, foundPerpKey, Win8, strSkuId, errorKBs
globalResource = ""
globalErr = ""
foundSlUi = False
Win7 = False
Win8 = False
kmsCounter = 0
isAdActivated = False
dlicense = False
strSkuId = Null
currentDir = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\"))
' Activation error codes for which a KB is available
errorKBs = "80070422|80070426|C004F074|80070001|80070005|8007000D|8007232B|8007251D|C004F014|C004F038|C004F039|C004F041|C004F042|C004C003|4004F040"
Select Case WSCript.Arguments.Count
Case 0
verifyFileExists currentDir & "ospp.htm"
showIePopUp currentDir & "ospp.htm"
WScript.Quit
Case 1
var1 = WSCript.Arguments(0)
Case 2
var1 = WSCript.Arguments(0)
var2 = WSCript.Arguments(1)
Case 3
var1 = WSCript.Arguments(0)
var2 = WSCript.Arguments(1)
var3 = WSCript.Arguments(2)
Case 4
var1 = WSCript.Arguments(0)
var2 = WSCript.Arguments(1)
var3 = WSCript.Arguments(2)
var4 = WSCript.Arguments(3)
Case Else
End Select
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Call Main(var1,var2,var3,var4)
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Sub Main(strCommand,strMachine,strUser,strPassword)
On Error Resume Next
getEngine()
pProcessing()
getSlui()
strLocal = objNetwork.ComputerName
strCommand = LCase(strCommand)
Select Case strCommand
Case "/act", "/dstatus", "/dstatusall", "/dinstid", "/dtokils", _
"/remhst", "/stokflag", "/ctokflag", "/dcmid", "/dtokcerts", "/ckms-domain", "/dpid"
connectWMI strMachine,strUser,strPassword,""
performLicAction strCommand,"",""
Case "/dlicenseinfo"
If strMachine <> "" Then
WScript.Echo MSG_SEARCH_FORKEY & strMachine
Else
WScript.Echo MSG_SEARCH_FORKEY & strLocal
End If
WScript.Echo MSG_SEPERATE
'Connect WMI
dlicense = True
connectWMI strMachine,strUser,strPassword,""
'Display licensestatus for all product keys
performLicAction "/dstatusall","",""
'Display PID/MachineID for sub keys
performLicAction "/dpid","",strMachine
WScript.Echo MSG_SEPERATE
'Display MachineId
getMachineId strMachine
'Display HeartBeatXml
getHeartbeatXml strMachine
'Display OLC-OLS events
getEvents MSG_EVENT_2011,"Application","2011","Microsoft Office 15",strMachine
'Display SPP related events: InstallProof & SLActivate
If Win7 = True Then
getEvents MSG_EVENT_1016,"Application","1016","Office Software Protection Platform Service",strMachine
getEvents MSG_EVENT_1017,"Application","1017","Office Software Protection Platform Service",strMachine
getEvents MSG_EVENT_1013,"Application","1013","Office Software Protection Platform Service",strMachine
getEvents MSG_EVENT_8200,"Application","8200","Office Software Protection Platform Service",strMachine
Else
getEvents MSG_EVENT_1016,"Application","1016","Microsoft-Windows-Security-SPP",strMachine
getEvents MSG_EVENT_1017,"Application","1017","Microsoft-Windows-Security-SPP",strMachine
getEvents MSG_EVENT_1013,"Application","1013","Microsoft-Windows-Security-SPP",strMachine
getEvents MSG_EVENT_8200,"Application","1014","Microsoft-Windows-Security-SPP",strMachine
End If
quitExit()
Case "/dhistoryacterr", "/dhistorykms"
connectWMI strMachine,strUser,strPassword,""
performLicAction strCommand,"",strMachine
Case "/puserops", "/duserops"
connectWMI strMachine,strUser,strPassword,"reg"
performRegAction strCommand
Case "/osppsvcrestart", "/osppsvcauto"
connectWMI strMachine,strUser,strPassword,""
performServiceAction strCommand
Case "/help", "help", "?", "/?", "/?"
verifyFileExists currentDir & "ospp.htm"
showIePopUp currentDir & "ospp.htm"
quitExit()
Case "/regmof"
registerMof "osppwmi.mof"
Case "/rearm"
If strMachine = "" Then
reARM ""
Else
globalPopFailure MSG_UNSUPPORTEDLOCAL & vbCr & strCommand,True
End If
quitExit()
Case "/version"
globalPopSuccess VER_INFO,True
Case Else
pos = InStr(strCommand,":")
Select Case pos
Case 7
getCommand = Left(strCommand,6)
Case 8
getCommand = Left(strCommand,7)
Case 13
getCommand = Left(strCommand,12)
Case Else
globalPopFailure MSG_UNSUPPORTED,True
End Select
Select Case getCommand
Case "/skms-domain", "/actype", "/inpkey", "/unpkey", "/inslic", "/actcid", "/sethst", "/setprt", "/ddescr", "/rtokil", "/tokact", "/cachst", "/rearm"
strValue = Replace(strCommand,getCommand & ":","")
If strValue = "" Then
globalPopFailure MSG_UNSUPPORTED & " A value is required for: " & strCommand,True
End If
If getCommand = "/ddescr" Then
If Left(strValue,2) = "0x" Then
getDescription strValue,""
Else
WScript.Echo MSG_ERRCODEVALUE
quitExit()
End If
ElseIf getCommand = "/rearm" Then
If strMachine = "" Then
reARM strValue
Else
globalPopFailure MSG_UNSUPPORTEDLOCAL & vbCr & strCommand,True
End If
quitExit()
Else
connectWMI strMachine,strUser,strPassword,""
performLicAction getCommand,strValue,""
End If
Case Else
globalPopFailure MSG_UNSUPPORTED,True
End Select
End Select
End Sub
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function showIePopUp(strPath)
On Error Resume Next
Set objExplorer = CreateObject("InternetExplorer.Application")
With objExplorer
.Navigate strPath
.ToolBar = 0
.StatusBar = 0
.Width = 1000
.Height = 593
.Left = 1
.Top = 1
.Visible = 1
End With
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function getEngine()
strEngine = LCase(Right(WScript.FullName,12))
If strEngine <> "\cscript.exe" Then
WshShell.Popup "Unable to perform operation. " & WSCript.ScriptName & " requires the cscript engine." & _
vbCr & "Command line example: cscript ospp.vbs ?", _
,WSCript.ScriptName, VALUE_ICON_WARNING
WScript.Quit
End If
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function WMIDateStringToDate(dtmEventDate)
WMIDateStringToDate = CDate(Mid(dtmEventDate, 5, 2) & "/" & _
Mid(dtmEventDate, 7, 2) & "/" & Left(dtmEventDate, 4) _
& " " & Mid (dtmEventDate, 9, 2) & ":" & _
Mid(dtmEventDate, 11, 2) & ":" & Mid(dtmEventDate, _
13, 2))
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function getDescription(strSearch,cType)
If foundSlUi <> True Then
If cType <> "wmi" Then
globalPopFailure "slui.exe not found.",True
quitExit()
End If
Else
Set objScriptExec = WshShell.Exec (strSluiPath & " 0x2a " & strSearch)
readOut = objScriptExec.StdOut.ReadAll
quitExit()
End If
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function checkRegRights(wmiObject,strKeyPath)
On Error Resume next
wmiObject.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_SET_VALUE, _
bHasAccessRight
If bHasAccessRight = True Then
'Success
Else
globalPopFailure MSG_NOREGRIGHTS & vbCr & MSG_ISCMD_ELEVATED,True
End If
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function quitExit()
Set WshShell = Nothing
Set objFSO = Nothing
Set objNetwork = Nothing
Set objWMI = Nothing
WScript.Echo MSG_SEPERATE
WScript.Echo MSG_EXIT
WSCript.Quit
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function verifyFileExists(file)
If Not objFSO.FileExists(file) Then
If file = currentDir & "slerror.xml" Then
WScript.Echo "[" & MSG_FILENOTFOUND & file & " Unable to display error description.]"
ElseIf file = currentDir & "ospp.htm" Then
globalPopFailure MSG_FILENOTFOUND & vbCr & file,False
quitExit()
Else
globalPopFailure MSG_FILENOTFOUND & vbCr & file,True
End If
End If
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function registerMof(strFile)
For Each Drv In objFSO.Drives
If Drv.DriveType=2 Then
If objFSO.FileExists(Drv.DriveLetter & STR_SYS32PATH & "wbem\mofcomp.exe") Then
foundComp = True
strMofExePath = Drv.DriveLetter & STR_SYS32PATH & "wbem\mofcomp.exe"
If objFSO.FileExists(Drv.DriveLetter & STR_SYS32PATH & "wbem\" & strFile) Then
foundMof = True
strOWmi = Drv.DriveLetter & STR_SYS32PATH & "wbem\" & strFile
Set objScriptExec = WshShell.Exec (strMofExePath & " " & strOWmi)
readOut = objScriptExec.StdOut.ReadAll
WScript.Echo readOut
quitExit()
End If
End If
End If
Next
If foundComp <> True Then
globalPopFailure MSG_FILENOTFOUND & Replace(STR_SYS32PATH,":","") & "wbem\mofcomp.exe",True
Else
If foundMof <> True Then
globalPopFailure MSG_FILENOTFOUND & Replace(STR_SYS32PATH,":","") & "wbem\osppwmi.mof",True
End If
End If
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function pProcessing()
WScript.Echo MSG_PROCESSING
WScript.Echo MSG_SEPERATE
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function getSlui()
For Each Drv In objFSO.Drives
If Drv.DriveType=2 Then
If objFSO.FileExists(Drv.DriveLetter & STR_SYS32PATH & "slui.exe") Then
strSluiPath = Drv.DriveLetter & STR_SYS32PATH & "slui.exe"
foundSlUi = True
Exit For
End If
End If
Next
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
' Returns the encoding for a givven file.
' Possible return values: ascii, unicode, unicodeFFFE (big-endian), utf-8
Function GetFileEncoding(strFileName)
Dim strData
Dim strEncoding
Set oStream = CreateObject("ADODB.Stream")
oStream.Type = 1 'adTypeBinary
oStream.Open
oStream.LoadFromFile(strFileName)
' Default encoding is ascii
strEncoding = "ascii"
strData = BinaryToString(oStream.Read(2))
' Check for little endian (x86) unicode preamble
If (Len(strData) = 2) and strData = (Chr(255) + Chr(254)) Then
strEncoding = "unicode"
Else
oStream.Position = 0
strData = BinaryToString(oStream.Read(3))
' Check for utf-8 preamble
If (Len(strData) >= 3) and strData = (Chr(239) + Chr(187) + Chr(191)) Then
strEncoding = "utf-8"
End If
End If
oStream.Close
GetFileEncoding = strEncoding
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
' Converts binary data (VT_UI1 | VT_ARRAY) to a string (BSTR)
Function BinaryToString(dataBinary)
Dim i
Dim str
For i = 1 To LenB(dataBinary)
str = str & Chr(AscB(MidB(dataBinary, i, 1)))
Next
BinaryToString = str
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
' Returns string containing the whole text file data.
' Supports ascii, unicode (little-endian) and utf-8 encoding.
Function ReadAllTextFile(strFileName)
Dim strData
Set oStream = CreateObject("ADODB.Stream")
oStream.Type = 2 'adTypeText
oStream.Open
oStream.Charset = GetFileEncoding(strFileName)
oStream.LoadFromFile(strFileName)
strData = oStream.ReadText(-1) 'adReadAll
oStream.Close
ReadAllTextFile = strData
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function sppErrHandle(strCommand)
globalErr = Hex(Err.Number)
Select Case Err.Number
Case 0
'Success
Select Case strCommand
Case "/act","/tokact"
WScript.Echo MSG_ACTSUCCESS
Case "/inpkey"
WScript.Echo MSG_KEYINSTALLSUCCESS
quitExit()
Case "/inslic"
WScript.Echo MSG_INSTALLLICSUCCESS
quitExit()
Case "/ckms-domain","/skms-domain","/actype","/sethst","/setprt","/remhst","/stokflag","/ctokflag","/cachst"
WScript.Echo MSG_SUCCESS
quitExit()
Case "/rtokil"
WScript.Echo MSG_REMILID & UCase(strValue)
quitExit()
Case "/unpkey"
WScript.Echo MSG_UNINSTALLKEYSUCCESS
quitExit()
Case Else
End Select
Case Else
verifyFileExists currentDir & "slerror.xml"
getResource("err" & "0x" & globalErr)
If globalResource = "" Then
If Len(globalErr) <> "8" Then
WScript.Echo MSG_ERRDESC & MSG_ERRUNKNOWN
Else
If foundSlUi = True Then
WScript.Echo MSG_ERRCODE & "0x" & globalErr
WScript.Echo MSG_ERRDESC & "Run the following: cscript ospp.vbs /ddescr:0x" & globalErr
Else
WScript.Echo MSG_ERRCODE & "0x" & globalErr
End If
End If
If strCommand <> "/act" Then
quitExit()
End If
Else
WScript.Echo MSG_ERRCODE & "0x" & globalErr
Wscript.Echo MSG_ERRDESC & globalResource
End If
If strCommand = "/dtokcerts" Or strCommand = "/ignore" Then
quitExit()
End If
End Select
If globalErr = "C004F074" Then
WScript.Echo "To view the activation event history run: cscript " & WScript.ScriptName & " /dhistorykms"
End If
If strCommand = "/act" And globalErr <> "0" Then
' If a KB article is found, show the KB link
lookupKBArticle(globalErr)
End If
globalResource = ""
globalErr = ""
Err.Clear
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function wmiErrHandle()
Select Case Err.Number
Case 0
'Successs
Case 424
globalPopFailure MSG_ERRCODE & Err.Number & vbCr & MSG_ERRDESC & MSG_CREDENTIALFAILURE,True
Case Else
If Err.Description <> "" Then
globalPopFailure MSG_ERRCODE & Err.Number & vbCr & MSG_ERRDESC & Err.Description,True
Else
globalPopFailure "An error occurred while making the connection." & vbCr & MSG_ERRCODE & Err.Number,True
End If
End Select
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function setRegValue(wmiObject,opsValue,strValueName)
On Error Resume Next
Err.Clear()
If Win7 = True Then
strKeyPath = REG_OSPP
Else
strKeyPath = REG_SPP
End If
Select Case strValueName
Case "UserOperations"
wmiObject.CreateKey HKEY_LOCAL_MACHINE,strKeyPath
wmiObject.SetDWORDValue HKEY_LOCAL_MACHINE,_
strKeyPath,strValueName,opsValue
Case Else
End Select
wmiErrHandle()
WScript.Echo MSG_SUCCESS
quitExit()
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function getResource(resource)
On Error Resume Next
Set xmlDoc = CreateObject("Msxml2.DOMDocument.6.0")
xmlDoc.load(currentDir & "slerror.xml")
Set ElemList = xmlDoc.getElementsByTagName(resource)
resValue = ElemList.item(0).text
globalResource = resValue
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function globalPopSuccess(strSuccess,boolQuit)
If boolQuit = True Then
WshShell.Popup strSuccess,,WScript.ScriptName, wshOK + VALUE_ICON_INFORMATION
quitExit()
Else
WshShell.Popup strSuccess,,WScript.ScriptName, wshOK + VALUE_ICON_INFORMATION
End If
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function globalPopFailure(strFailure,boolQuit)
If boolQuit = True Then
WshShell.Popup strFailure,,WScript.ScriptName, wshOK + VALUE_ICON_WARNING
quitExit()
Else
WshShell.Popup strFailure,,WScript.ScriptName, wshOK + VALUE_ICON_WARNING
End If
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function connectWMI(strMachine,strUser,strPassword,ctype)
On Error Resume Next
If ctype = "" Then
If strMachine = "" Or LCase(strMachine) = LCase(strLocal) Then
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
Else
If strUser = "" And strPassword = "" Then
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strMachine & "\root\cimv2")
Else
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMI = objSWbemLocator.ConnectServer _
(strMachine, "\root\cimv2", strUser, strPassword)
wmiErr = CStr(Hex(Err.Number))
If Len(wmiErr) = "8" Then
getDescription "0x" & wmiErr,"wmi"
End If
objWMI.Security_.ImpersonationLevel = 3
End If
End If
Else
If strUser <> "" Then
globalPopFailure MSG_CREDENTIALERR,True
End If
If strMachine = "" Or LCase(strMachine) = LCase(strLocal) Then
Set objWMI1 = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & "." & "\root\default:StdRegProv")
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
Else
Set objWMI1 = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strMachine & "\root\default:StdRegProv")
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strMachine & "\root\cimv2")
End If
End If
wmiErrHandle()
setWinOS()
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Private Function TkaGetSigner()
On Error Resume Next
If Win7 = True Then
Set TkaGetSigner = WScript.CreateObject("OSPPWMI.OSppWmiTokenActivationSigner")
Else
Set TkaGetSigner = WScript.CreateObject("SPPWMI.SppWmiTokenActivationSigner")
End If
If Hex(Err.Number) = "80020009" Then
globalPopFailure MSG_ERRCODE & "0x" & Hex(Err.Number) & vbCr & MSG_ERRDESC & Err.Description,True
End If
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function TkaPrintCertificate(strThumbprint)
arrParams = Split(strThumbprint, "|")
WScript.Echo "Thumbprint: " & arrParams(0)
WScript.Echo "Subject: " & arrParams(1)
WScript.Echo "Issuer: " & arrParams(2)
vf = FormatDateTime(CDate(arrParams(3)), vbShortDate)
WScript.Echo "Valid From: " & vf
vt = FormatDateTime(CDate(arrParams(4)), vbShortDate)
WScript.Echo "Valid To: " & vt
WScript.Echo MSG_SEPERATE
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function ExecuteQuery(strSelect,strWhere,strClass)
Err.Clear
If strWhere = "" Then
Set productinstances = objWMI.ExecQuery("SELECT " & strSelect & " FROM " & strClass)
Else
Set productinstances = objWMI.ExecQuery("SELECT " & strSelect & " FROM " & strClass & " WHERE " & strWhere)
End If
sppErrHandle ""
End Function
'////////////////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////////////////
Function performLicAction(strCommand,strValue,strMachine)
On Error Resume Next
If strCommand = "/dhistorykms" Or strCommand = "/dhistoryacterr" Then
verifyFileExists currentDir & "slerror.xml"
If strCommand = "/dhistorykms" Then
'12288 = KMS Activation event id
eventCode = "12288"
strSrcEvents = MSG_SEARCHEVENTSKMS
strNoEvents = MSG_NOEVENTSSKMS
Else
'8200 = Internet Activation event id
eventCode = "8200"
strSrcEvents = MSG_SEARCHEVENTSRET
strNoEvents = MSG_NOEVENTSRET
End If
If strMachine <> "" Then
WScript.Echo strSrcEvents & strMachine
Else
WScript.Echo strSrcEvents & strLocal
End If
WScript.Echo "Event ID: " & eventCode
WScript.Echo vbCr
Set objEvents = objWMI.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'Application' and " _
& "EventCode = '" & eventCode & "'")
If objEvents.Count > 0 Then
For each objEvent in objEvents
If strCommand = "/dhistoryacterr" Then
i = i + 1
dtmEventDate = objEvent.TimeWritten
strTimeWritten = WMIDateStringToDate(dtmEventDate)
WScript.Echo "Coordinated Universal Time Written: " & strTimeWritten
strReplCrs = Replace(objEvent.Message,vbCrLf,"")
WScript.Echo "MESSAGE: " & strReplCrs
strhr10 = Right(strReplCrs,10)
getResource("err" & strhr10)
If globalResource = "" Then
If foundSlUi = True Then
WScript.Echo MSG_ERRDESC & "Run the following: cscript ospp.vbs /ddescr:" & strhr10
Else
WScript.Echo MSG_ERRDESC & "Not available."
End If
Else
Wscript.Echo MSG_ERRDESC & globalResource
End If
WScript.Echo MSG_SEPERATE
Else
strhr10 = Mid(objEvent.Message,90,10)
strReplCrs = Replace(objEvent.Message,vbCrLf,"")
If Right(strReplCrs,2) = " 5" Then
strReplStrs = Replace(strReplCrs,"The client has sent an activation request to the key management service machine.Info:","")
dtmEventDate = objEvent.TimeWritten
strTimeWritten = WMIDateStringToDate(dtmEventDate)
WScript.Echo "Coordinated Universal Time Written: " & strTimeWritten
intColon = InStr(strReplStrs,":")
strErrHost = Left(strReplStrs,intColon)
strErrHost = Trim(strErrHost)
strErrHost = Replace(strErrHost,":","")
WScript.Echo "ERROR/HOST: " & strErrHost
Select Case strhr10
Case "0x00000000"
WScript.Echo MSG_ERRDESC & "N/A"
Case Else
getResource("err" & strhr10)
If globalResource = "" Then
If foundSlUi = True Then
WScript.Echo MSG_ERRDESC & "Run the following: cscript ospp.vbs /ddescr:" & strhr10
' If a KB article is found, show the KB link
lookupKBArticle(Right(strhr10, 8))
Else
WScript.Echo MSG_ERRDESC & "Not available."
End If
Else
Wscript.Echo MSG_ERRDESC & globalResource
' If a KB article is found, show the KB link
lookupKBArticle(Right(strhr10, 8))
End If
End Select
WScript.Echo MSG_SEPERATE
End If
End If
Next
Else
WScript.Echo MSG_SEPERATE
If strMachine <> "" Then
WScript.Echo strNoEvents & strMachine
Else
WScript.Echo strNoEvents & strLocal
End If
WScript.Echo MSG_SEPERATE
End If
quitExit()
End If
'Verify osppsvc service is installed for win7 case
If Win7 = True Then
Set colListOfServices = objWMI.ExecQuery _
("Select * from Win32_Service ")
For Each objService in colListOfServices
If objService.Name = "osppsvc" Then
installed = True
Exit For
End If
Next
If installed <> True Then
globalPopFailure MSG_OSPPSVC_NOINSTALL,True
End If
End If
Select Case strCommand
'The following operations are performed @ a service level
Case "/inpkey", "/dcmid", "/inslic", "/cachst", "/stokflag", "/ctokflag", "/dstatus", "/dstatusall", "/dpid"
If Win7 = True Then
For Each objService in objWMI.InstancesOf("OfficeSoftwareProtectionService")
Set objOspp = objService
Exit For
Next
Else
'Win8 and beyond
For Each objService in objWMI.InstancesOf("SoftwareLicensingService")
Set objOspp = objService
Exit For
Next
End If
Case Else
End Select
sppErrHandle ""
If strCommand = "/inpkey" Then
i = i + 1
Err.Clear
objOspp.InstallProductKey(strValue)
sppErrHandle(strCommand)
ElseIf strCommand = "/cachst" Then
i = i + 1
If strValue = "true" Then
objOspp.DisableKeyManagementServiceHostCaching(False)
sppErrHandle(strCommand)
ElseIf strValue = "false" Then
objOspp.DisableKeyManagementServiceHostCaching(True)
sppErrHandle(strCommand)
Else
globalPopFailure MSG_UNSUPPORTED & " A TRUE or FALSE value is required for: " & strCommand,True
End If
ElseIf strCommand = "/dcmid" Then
If Win8 = True Then
'Check if KMS key installed. If yes retrieve the SKUID value.
ExecuteQuery "ID, ApplicationId, Description, Name","ApplicationId = '" & OfficeAppId & "' " & "AND PartialProductKey <> NULL ",productClass
For each instance in productinstances
sppErrHandle ""
intIsKms = InStr(UCase(instance.Description),"KMS")
If intIsKms <> 0 Then
strSkuId = instance.ID
Exit For
End If
Next
If strSkuId = Null Then
WScript.Echo MSG_CMID & MSG_CMID_NOTFOUND
quitExit()
End If
'Return the last Office KMS event containing containing the SKUID value for the installed KMS key.
'& retrieve the CMID value from the event.
oKmsEventCounter = 0
eventCode = "12288"
Set objEvents = objWMI.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'Application' and " _
& "EventCode = '" & eventCode & "'")
If objEvents.Count > 0 Then
For each objEvent in objEvents
oKmsEvent = InStr(objEvent.Message,strSkuId)
If oKmsEvent <> 0 Then
oKmsEventCounter = oKmsEventCounter + 1
parseEvntMsg1 = InStr(objEvent.Message, ", ")
parseEvntMsg2 = InStr(parseEvntMsg1 + 2,objEvent.Message, ", ")
parseEvntMsg3 = InStr(parseEvntMsg2 + 2,objEvent.Message, ", ")
parseEvntMsg4 = InStr(parseEvntMsg3 + 2,objEvent.Message, ", ")
WScript.Echo MSG_CMID & Mid(objEvent.Message,parseEvntMsg3 + 2,parseEvntMsg4 - (parseEvntMsg3 + 2))
Exit For
End If
Next
End If
If oKmsEventCounter = 0 Then
WScript.Echo MSG_CMID & MSG_CMID_NOTFOUND
End If
Else
If objOspp.ClientMachineID <> "" Or objOspp.ClientMachineID <> Null Then
WScript.Echo MSG_CMID & objOspp.ClientMachineID
Else
WScript.Echo MSG_CMID & MSG_CMID_NOTFOUND
End If
End If
quitExit()
ElseIf strCommand = "/inslic" Then
i = i + 1
If Right(strValue,7) = ".xrm-ms" Then
verifyFileExists strValue
WScript.Echo MSG_INSTALLLICENSE & strValue
Else
globalPopFailure MSG_UNRECOGFILE,True
End If
LicenseData = ReadAllTextFile(strValue)
objOSpp.InstallLicense(LicenseData)
SppErrHandle(strCommand)
ElseIf strCommand = "/stokflag" Then
i = i + 1
If Win7 = True Then
objOspp.DisableKeyManagementServiceActivation(True)
sppErrHandle(strCommand)
Else
'Unsupported - osppsvc only supports this.
globalPopFailure MSG_UNSUPPORTEDOPEROS7 & vbCr & strCommand,True
End If
ElseIf strCommand = "/ctokflag" Then
i = i + 1
If Win7 = True Then
objOspp.DisableKeyManagementServiceActivation(False)
SppErrHandle(strCommand)
Else
'Unsupported - osppsvc only supports this.
globalPopFailure MSG_UNSUPPORTEDOPEROS7 & vbCr & strCommand,True
End If