-
Notifications
You must be signed in to change notification settings - Fork 0
/
iiscnfg.vbs
1392 lines (1175 loc) · 49.5 KB
/
iiscnfg.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.
'
' VBScript Source File
'
' Script Name: IIsCnfg.vbs
'
Option Explicit
On Error Resume Next
' Error codes
Const ERR_OK = 0
Const ERR_GENERAL_FAILURE = 1
'''''''''''''''''''''
' Messages
Const L_ConfImported_Text = "Configuration imported from %1 in file"
Const L_ConfImportedp2_Text = "%1 to %2 in the Metabase."
Const L_ConfExported_Text = "Configuration exported from %1 to file %2."
Const L_MDSaved_Text = "Metadata successfully flushed to disk."
Const L_Error_ErrorMessage = "Error &H%1: %2"
Const L_GetComputerObject_ErrorMessage = "Could not get computer object"
Const L_Import_ErrorMessage = "Error while importing configuration."
Const L_Export_ErrorMessage = "Error while exporting configuration."
Const L_SaveData_ErrorMessage = "Error while flushing metabase."
Const L_OnlyOneOper_ErrorMessage = "Please specify only one operation at a time."
Const L_ScriptHelper_ErrorMessage = "Could not create an instance of the"
Const L_ScriptHelperp2_ErrorMessage = "IIsScriptHelper object."
Const L_ChkScpHelperReg_ErrorMessage = "Please register the Microsoft.IIsScriptHelper"
Const L_ChkScpHelperRegp2_ErrorMessage = "component."
Const L_CmdLib_ErrorMessage = "Could not create an instance of the CmdLib object."
Const L_ChkCmdLibReg_ErrorMessage = "Please register the Microsoft.CmdLib component."
Const L_WMIConnect_ErrorMessage = "Could not connect to WMI provider."
Const L_RequiredArgsMissing_ErrorMessage = "Required arguments are missing."
Const L_FileExpected_ErrorMessage = "Argument is a folder path while expecting a file"
Const L_FileExpectedp2_ErrorMessage = "path."
Const L_ParentFolderDoesntExist_ErrorMessage = "Parent folder doesn't exist."
Const L_FileDoesntExist_ErrorMessage = "Input file doesn't exist."
Const L_FileAlreadyExist_ErrorMessage = "Export file specified already exists."
Const L_NotEnoughParams_ErrorMessage = "Not enough parameters."
Const L_InvalidSwitch_ErrorMessage = "Invalid switch: %1"
Const L_IncorrectPassword_ErrorMessage = "The password specified is incorrect."
Const L_InvalidXML_ErrorMessage = "The import file appears to contain invalid XML."
Const L_Admin_ErrorMessage = "You cannot run this command because you are not an"
Const L_Adminp2_ErrorMessage = "administrator on the server you are trying to configure."
Const L_DriveLetter_Message = "Mapping local drive %1 to admin share on server %2"
Const L_Shell_ErrorMessage = "Could not create an instance of the WScript.Shell"
Const L_Shellp2_ErrorMessage = "object."
Const L_FS_ErrorMessage = "Could not create an instance of the"
Const L_FSp2_ErrorMessage = "Scripting.FileSystemObject object."
Const L_Network_ErrorMessage = "Could not create an instance of the"
Const L_Networkp2_ErrorMessage = "WScript.Network object."
Const L_BackingUp_Message = "Backing up server %1"
Const L_Restoring_Message = "Restoring on server %1"
Const L_Backup_ErrorMessage = "Failure creating backup."
Const L_BackupComplete_Message = "Backup complete."
Const L_Restore_ErrorMessage = "Failure restoring backup."
Const L_RestoreComplete_Message = "Restore complete."
Const L_UnMap_Message = "Unmapping local drive %1"
Const L_NoDrive_ErrorMessage = "No drives available for mapping on local machine."
Const L_Copy_Message = "Copying backup files..."
Const L_Copy_ErrorMessage = "Error copying files."
Const L_ReturnVal_ErrorMessage = "Call returned with code %1"
Const L_CopyComplete_Message = "Copy operation complete."
Const L_AuditAlreadyEnabled_Message = "Auditing is already enabled on %1. No action performed."
Const L_AuditAlreadyDisabled_Message = "Auditing is already disabled on %1. No action performed."
Const L_EnableAuditFail_ErrorMessage = "Failed to enable auditing on %1."
Const L_DisableAuditFail_ErrorMessage = "Failed to disable auditing on %1."
Const L_AuditEnabled_Message = "Auditing was enabled on %1."
Const L_AuditDisabled_Message = "Auditing was disabled on %1."
Const L_GetObject_ErrorMessage = "Error retrieving ADSI object %1."
Const L_GetDataPaths_ErrorMessage = "Error looking for the AdminACL property in the metabase."
'''''''''''''''''''''
' Help
Const L_Empty_Text = ""
' General help messages
Const L_SeeHelp_Message = "Type IIsCnfg /? for help."
Const L_SeeImportHelp_Message = "Type IIsCnfg /import /? for help."
Const L_SeeExportHelp_Message = "Type IIsCnfg /export /? for help."
Const L_SeeEnableAuditHelp_Message = "Type IIsCnfg /EnableAudit /? for help."
Const L_SeeDisableAuditHelp_Message = "Type IIsCnfg /DisableAudit /? for help."
Const L_Help_HELP_General01_Text = "Description: Import and export IIS configuration."
Const L_Help_HELP_General02_Text = "Syntax: IIsCnfg [/s <server> [/u <username> [/p <password>]]]"
Const L_Help_HELP_General03_Text = " /<operation> [arguments]"
Const L_Help_HELP_General04_Text = "Parameters:"
Const L_Help_HELP_General05_Text = ""
Const L_Help_HELP_General06_Text = "Value Description"
Const L_Help_HELP_General07_Text = "/s <server> Connect to machine <server>."
Const L_Help_HELP_General07p2_Text = " [Default: this system]"
Const L_Help_HELP_General08_Text = "/u <username> Connect as <domain>\<username> or"
Const L_Help_HELP_General09_Text = " <username>. [Default: current user]"
Const L_Help_HELP_General10_Text = "/p <password> Password for the <username> user."
Const L_Help_HELP_General11_Text = "<operation> /import Import configuration from"
Const L_Help_HELP_General11p1_Text = " a configuration file."
Const L_Help_HELP_General12_Text = " /export Export configuration into"
Const L_Help_HELP_General12p1_Text = " a configuration file."
Const L_Help_HELP_General13_Text = " /copy Copy configuration from"
Const L_Help_HELP_General13p1_Text = " one machine to another."
Const L_Help_HELP_General14_Text = " /EnableAudit Enable auditing on a"
Const L_Help_HELP_General14p1_Text = " certain metabase path."
Const L_Help_HELP_General15_Text = " /DisableAudit Disable auditing on a"
Const L_Help_HELP_General15p1_Text = " certain metabase path."
Const L_Help_HELP_General22_Text = "For detailed usage:"
Const L_Help_HELP_General23_Text = "IIsCnfg /import /?"
Const L_Help_HELP_General24_Text = "IIsCnfg /export /?"
Const L_Help_HELP_General25_Text = "IIsCnfg /copy /?"
Const L_Help_HELP_General26_Text = "IIsCnfg /save /?"
Const L_Help_HELP_General27_Text = "IIsCnfg /EnableAudit /?"
Const L_Help_HELP_General28_Text = "IIsCnfg /DisableAudit /?"
' Common help messages
Const L_Help_HELP_Common13_Text = "/d <DecryptPass> Specifies the password used to"
Const L_Help_HELP_Common13p1_Text = " decrypt encrypted configuration data."
Const L_Help_HELP_Common13p2_Text = " [Default: """"]"
Const L_Help_HELP_Common14_Text = "/f <File> Configuration file."
Const L_Help_HELP_Common15_Text = "/sp <SourcePath> The full metabase path to start"
Const L_Help_HELP_Common15p1_Text = " reading from the configuration file."
Const L_Help_HELP_Common21_Text = "Examples:"
' Copy help messages
Const L_Help_HELP_Copy1_Text = "Description: Copy configuration from a source server to a"
Const L_Help_HELP_Copy1p2_Text = " target server."
Const L_Help_HELP_Copy2_Text = "Syntax: iiscnfg [/s <server> [/u <username> [/p <password>]]]"
Const L_Help_HELP_Copy2p2_Text = " /copy /ts <target server> /tu <target user>"
Const L_Help_HELP_Copy2p3_Text = " /tp <target password>"
Const L_Help_HELP_Copy3_Text = "Parameters:"
Const L_Help_HELP_Copy4_Text = "Value Description"
Const L_Help_HELP_Copy5_Text = "/s <server> Connect to machine <server>"
Const L_Help_HELP_Copy5p2_Text = " [Default: this system]"
Const L_Help_HELP_Copy6_Text = "/u <username> Connect as <domain>/<username>"
Const L_Help_HELP_Copy7_Text = " or <username> [Default: current user]"
Const L_Help_HELP_Copy8_Text = "/p <password> Password for the <username> user"
Const L_Help_HELP_Copy9_Text = "/ts Target server to copy configuration to"
Const L_Help_HELP_Copy10_Text = "/tu Username to use when connecting to the"
Const L_Help_HELP_Copy10p2_Text = " target server"
Const L_Help_HELP_Copy11_Text = "/tp Password to use when connecting to the"
Const L_Help_HELP_Copy11p2_Text = " target server"
Const L_Help_HELP_Copy12_Text = "Examples:"
Const L_Help_HELP_Copy13_Text = "IIsCnfg /copy /ts TargetServer /tu Administrator /tp Pk$^("
Const L_Help_HELP_Copy14_Text = "IIsCnfg /s SourceServer /u Administrator /p Kj30W /copy"
Const L_Help_HELP_Copy14p2_Text = " /ts TargetServer /tu Administrator /tp Pk$^j"
' Import help messages
Const L_Help_HELP_Import01_Text = "Description: Import configuration from a configuration file."
Const L_Help_HELP_Import02_Text = "Syntax: IIsCnfg [/s <server> [/u <username> [/p <password>]]]"
Const L_Help_HELP_Import02p1_Text = " /import [/d <DeCryptPass>] /f <File> /sp <SourcePath>"
Const L_Help_HELP_Import02p2_Text = " /dp <DestPath> [/inherited] [/children] [/merge]"
Const L_Help_HELP_Import16_Text = "/dp <DestPath> The metabase path destination for"
Const L_Help_HELP_Import16p1_Text = " imported properties. If the keytype"
Const L_Help_HELP_Import16p2_Text = " of the SourcePath and the DestPath do"
Const L_Help_HELP_Import16p3_Text = " not match, an error occurs."
Const L_Help_HELP_Import17_Text = "/inherited Import inherited settings if set."
Const L_Help_HELP_Import18_Text = "/children Import configuration for child nodes."
Const L_Help_HELP_Import19_Text = "/merge Merge imported configuration with"
Const L_Help_HELP_Import19p1_Text = " existing configuration."
Const L_Help_HELP_Import22_Text = "IIsCnfg /import /f c:\config.xml /sp /lm/w3svc/5/Root/401Kapp"
Const L_Help_HELP_Import22p1_Text = " /dp /lm/w3svc/1/Root/401Kapp"
' Export help messages
Const L_Help_HELP_Export01_Text = "Description: Export configuration into a configuration file."
Const L_Help_HELP_Export02_Text = "Syntax: IIsCnfg [/s <server> [/u <username> [/p <password>]]]"
Const L_Help_HELP_Export02p1_Text = " /export [/d <DeCryptPass>] /f <File> /sp <SourcePath>"
Const L_Help_HELP_Export02p2_Text = " [/inherited] [/children]"
Const L_Help_HELP_Export17_Text = "/inherited Export inherited settings if set."
Const L_Help_HELP_Export18_Text = "/children Export configuration for child nodes."
Const L_Help_HELP_Export22_Text = "IIsCnfg /export /f c:\config.xml /sp /lm/w3svc/5/Root/401Kapp"
' Save help messages
Const L_Help_HELP_Save01_Text = "Description: Save configuration to disk."
Const L_Help_HELP_Save02_Text = "Syntax: IIsCnfg [/s <server> [/u <username> [/p <password>]]]"
Const L_Help_HELP_Save02p2_Text = " /save"
Const L_Help_HELP_Save22_Text = "IIsCnfg /save"
Const L_Help_HELP_Save23_Text = "IIsCnfg /s SourceServer /u Administrator /p Kj30W /save"
' EnableAudit help messages
Const L_Help_HELP_EnableAudit01_Text = "Description: Enable auditing on the metabase path indicated."
Const L_Help_HELP_EnableAudit02_Text = "Syntax: IIsCnfg [/s <server> [/u <username> [/p <password>]]]"
Const L_Help_HELP_EnableAudit02p2_Text = " /EnableAudit <path> [/r]"
Const L_Help_HELP_EnableAudit16_Text = "<path> The full metabase path to enable"
Const L_Help_HELP_EnableAudit16p1_Text = " auditing on."
Const L_Help_HELP_EnableAudit17_Text = "/r Recursively enable auditing starting"
Const L_Help_HELP_EnableAudit17p1_Text = " from <path>."
Const L_Help_HELP_EnableAudit22_Text = "IIsCnfg /EnableAudit /w3svc/1/root"
Const L_Help_HELP_EnableAudit23_Text = "IIsCnfg /EnableAudit / /r"
Const L_Help_HELP_EnableAudit24_Text = "IIsCnfg /s SourceServer /u Administrator /p Kj30W /EnableAudit /w3svc/2 /r"
' DisableAudit help messages
Const L_Help_HELP_DisableAudit01_Text = "Description: Disable auditing on the metabase path indicated."
Const L_Help_HELP_DisableAudit02_Text = "Syntax: IIsCnfg [/s <server> [/u <username> [/p <password>]]]"
Const L_Help_HELP_DisableAudit02p2_Text = " /DisableAudit <path> [/r]"
Const L_Help_HELP_DisableAudit16_Text = "<path> The full metabase path to disable"
Const L_Help_HELP_DisableAudit16p1_Text = " auditing on."
Const L_Help_HELP_DisableAudit17_Text = "/r Recursively disable auditing starting"
Const L_Help_HELP_DisableAudit17p1_Text = " from <path>."
Const L_Help_HELP_DisableAudit22_Text = "IIsCnfg /DisableAudit /w3svc/1/root"
Const L_Help_HELP_DisableAudit23_Text = "IIsCnfg /DisableAudit / /r"
Const L_Help_HELP_DisableAudit24_Text = "IIsCnfg /s SourceServer /u Administrator /p Kj30W /DisableAudit /w3svc/2 /r"
''''''''''''''''''''''''
' Operation codes
Const OPER_IMPORT = 1
Const OPER_EXPORT = 2
Const OPER_COPY = 3
Const OPER_SAVE = 4
Const OPER_ENABLE_AUDIT = 5
Const OPER_DISABLE_AUDIT = 6
' Import/Export flags
Const IMPORT_EXPORT_INHERITED = 1
Const IMPORT_EXPORT_NODE_ONLY = 2
Const IMPORT_EXPORT_MERGE = 4
' Used in the call to GetDataPaths
Const IIS_DATA_INHERIT = 1
Const ADMINISTRATORS_GROUP_SID = "S-1-5-32-544"
'
' Main block
'
Dim oScriptHelper, oCmdLib
Dim strServer, strUser, strPassword, strSite
Dim strTarServer, strTarUser, strTarPassword
Dim strFile, strDecPass, strSourcePath, strDestPath, strMBPath
Dim intOperation, intResult, intFlags
Dim bRecurseAuditOperation
Dim aArgs, arg
Dim strCmdLineOptions
Dim oError
' Default values
strServer = "."
strUser = ""
strPassword = ""
strTarServer = ""
strTarUser = ""
strTarPassword = ""
intOperation = 0
strFile = ""
strDecPass = ""
strSourcePath = ""
strDestPath = ""
strMBPath = ""
intFlags = IMPORT_EXPORT_NODE_ONLY
bRecurseAuditOperation = False
' Instantiate the CmdLib for output string formatting
Set oCmdLib = CreateObject("Microsoft.CmdLib")
If Err.Number <> 0 Then
WScript.Echo L_CmdLib_ErrorMessage
WScript.Echo L_ChkCmdLibReg_ErrorMessage
WScript.Quit(ERR_GENERAL_FAILURE)
End If
Set oCmdLib.ScriptingHost = WScript.Application
' Instantiate script helper object
Set oScriptHelper = CreateObject("Microsoft.IIsScriptHelper")
If Err.Number <> 0 Then
WScript.Echo L_ScriptHelper_ErrorMessage
WScript.Echo L_ScriptHelperp2_ErrorMessage
WScript.Echo L_ChkScpHelperReg_ErrorMessage
WScript.Echo L_ChkScpHelperRegp2_ErrorMessage
WScript.Quit(ERR_GENERAL_FAILURE)
End If
Set oScriptHelper.ScriptHost = WScript
' Check if we are being run with cscript.exe instead of wscript.exe
oScriptHelper.CheckScriptEngine
' Minimum number of parameters must exist
If WScript.Arguments.Count < 1 Then
WScript.Echo L_RequiredArgsMissing_ErrorMessage
WScript.Echo L_SeeHelp_Message
WScript.Quit(ERR_GENERAL_FAILURE)
End If
strCmdLineOptions = "[server:s:1;user:u:1;password:p:1];decpass:d:1;file:f:1;sourcepath:sp:1;" & _
"inherited:i:0;children:c:0;[import::0;destpath:dp:1;merge:m:0];save::0;" & _
"export::0;[copy::0;targetserver:ts:1;targetuser:tu:1;targetpassword:tp:1];" & _
"[enableaudit:ea:1;recurse:r:0];[disableaudit:da:1;recurse:r:0]"
Set oError = oScriptHelper.ParseCmdLineOptions(strCmdLineOptions)
If Not oError Is Nothing Then
If oError.ErrorCode = oScriptHelper.ERROR_NOT_ENOUGH_ARGS Then
' Not enough arguments for a specified switch
WScript.Echo L_NotEnoughParams_ErrorMessage
WScript.Echo L_SeeHelp_Message
Else
' Invalid switch
oCmdLib.vbPrintf L_InvalidSwitch_ErrorMessage, Array(oError.SwitchName)
WScript.Echo L_SeeHelp_Message
End If
WScript.Quit(ERR_GENERAL_FAILURE)
End If
If oScriptHelper.GlobalHelpRequested Then
DisplayHelpMessage
WScript.Quit(ERR_OK)
End If
For Each arg In oScriptHelper.Switches
Select Case arg
Case "server"
' Server information
strServer = oScriptHelper.GetSwitch(arg)
Case "user"
' User information
strUser = oScriptHelper.GetSwitch(arg)
Case "password"
' Password information
strPassword = oScriptHelper.GetSwitch(arg)
Case "targetserver"
' Server information
strTarServer = oScriptHelper.GetSwitch(arg)
Case "targetuser"
' User information
strTarUser = oScriptHelper.GetSwitch(arg)
Case "targetpassword"
' Password information
strTarPassword = oScriptHelper.GetSwitch(arg)
Case "import"
If (intOperation <> 0) Then
WScript.Echo L_OnlyOneOper_ErrorMessage
WScript.Echo L_SeeHelp_Message
WScript.Quit(ERR_GENERAL_FAILURE)
End If
intOperation = OPER_IMPORT
If oScriptHelper.IsHelpRequested(arg) Then
DisplayImportHelpMessage
WScript.Quit(ERR_OK)
End If
Case "export"
If (intOperation <> 0) Then
WScript.Echo L_OnlyOneOper_ErrorMessage
WScript.Echo L_SeeHelp_Message
WScript.Quit(ERR_GENERAL_FAILURE)
End If
intOperation = OPER_EXPORT
If oScriptHelper.IsHelpRequested(arg) Then
DisplayExportHelpMessage
WScript.Quit(ERR_OK)
End If
Case "copy"
If (intOperation <> 0) Then
WScript.Echo L_OnlyOneOper_ErrorMessage
WScript.Echo L_SeeHelp_Message
WScript.Quit(ERR_GENERAL_FAILURE)
End If
intOperation = OPER_COPY
If oScriptHelper.IsHelpRequested(arg) Then
DisplayCopyHelpMessage
WScript.Quit(ERR_OK)
End If
Case "save"
If (intOperation <> 0) Then
WScript.Echo L_OnlyOneOper_ErrorMessage
WScript.Echo L_SeeHelp_Message
WScript.Quit(ERR_GENERAL_FAILURE)
End If
intOperation = OPER_SAVE
If oScriptHelper.IsHelpRequested(arg) Then
DisplaySaveHelpMessage
WScript.Quit(ERR_OK)
End If
Case "file"
strFile = oScriptHelper.GetSwitch(arg)
Case "decpass"
strDecPass = oScriptHelper.GetSwitch(arg)
Case "sourcepath"
strSourcePath = oScriptHelper.GetSwitch(arg)
Case "destpath"
strDestPath = oScriptHelper.GetSwitch(arg)
Case "inherited"
intFlags = intFlags Or IMPORT_EXPORT_INHERITED
Case "children"
intFlags = intFlags And Not IMPORT_EXPORT_NODE_ONLY
Case "merge"
intFlags = intFlags Or IMPORT_EXPORT_MERGE
Case "enableaudit"
If (intOperation <> 0) Then
WScript.Echo L_OnlyOneOper_ErrorMessage
WScript.Echo L_SeeHelp_Message
WScript.Quit(ERR_GENERAL_FAILURE)
End If
intOperation = OPER_ENABLE_AUDIT
If oScriptHelper.IsHelpRequested(arg) Then
DisplayEnableAuditHelpMessage
WScript.Quit(ERR_OK)
End If
strMBPath = oScriptHelper.GetSwitch(arg)
Case "disableaudit"
If (intOperation <> 0) Then
WScript.Echo L_OnlyOneOper_ErrorMessage
WScript.Echo L_SeeHelp_Message
WScript.Quit(ERR_GENERAL_FAILURE)
End If
intOperation = OPER_DISABLE_AUDIT
If oScriptHelper.IsHelpRequested(arg) Then
DisplayDisableAuditHelpMessage
WScript.Quit(ERR_OK)
End If
strMBPath = oScriptHelper.GetSwitch(arg)
Case "recurse"
bRecurseAuditOperation = True
End Select
Next
' Check Parameters
If intOperation = 0 Then
WScript.Echo L_OperationRequired_ErrorMessage
WScript.Echo L_SeeHelp_Message
WScript.Quit(ERR_GENERAL_FAILURE)
End If
Select Case intOperation
Case OPER_COPY
If strTarServer = "" Or strTarUser = "" Or strTarPassword = "" Then
WScript.Echo L_RequiredArgsMissing_ErrorMessage
WScript.Quit(ERR_GENERAL_FAILURE)
End If
Case OPER_IMPORT
If strFile = "" Or strSourcePath = "" Or strDestPath = "" Then
WScript.Echo L_RequiredArgsMissing_ErrorMessage
WScript.Echo L_SeeImportHelp_Message
WScript.Quit(ERR_GENERAL_FAILURE)
End If
Case OPER_EXPORT
If strFile = "" Or strSourcePath = "" Then
WScript.Echo L_RequiredArgsMissing_ErrorMessage
WScript.Echo L_SeeExportHelp_Message
WScript.Quit(ERR_GENERAL_FAILURE)
End If
End Select
' Check if /p is specified but /u isn't. In this case, we should bail out with an error
If oScriptHelper.Switches.Exists("password") And Not oScriptHelper.Switches.Exists("user") Then
WScript.Echo L_PassWithoutUser_ErrorMessage
WScript.Quit(ERR_GENERAL_FAILURE)
End If
' Check if /u is specified but /p isn't. In this case, we should ask for a password
If oScriptHelper.Switches.Exists("user") And Not oScriptHelper.Switches.Exists("password") Then
strPassword = oCmdLib.GetPassword
End If
' Initializes authentication with remote machine
intResult = oScriptHelper.InitAuthentication(strServer, strUser, strPassword)
If intResult <> 0 Then
WScript.Quit(intResult)
End If
' Choose operation
Select Case intOperation
Case OPER_IMPORT
intResult = Import(strDecPass, strFile, strSourcePath, strDestPath, intFlags)
Case OPER_EXPORT
intResult = Export(strDecPass, strFile, strSourcePath, intFlags)
Case OPER_COPY
intResult = Repl(strServer, strUser, strPassword, strTarServer, strTarUser, strTarPassword)
Case OPER_SAVE
intResult = SaveMD()
Case OPER_ENABLE_AUDIT
intResult = EnableAudit(strMBPath)
Case OPER_DISABLE_AUDIT
intResult = DisableAudit(strMBPath)
End Select
' Return value to command processor
WScript.Quit(intResult)
'''''''''''''''''''''''''
' End Of Main Block
'''''''''''''''''''''
'''''''''''''''''''''''''''
' DisplayHelpMessage
'''''''''''''''''''''''''''
Sub DisplayHelpMessage()
WScript.Echo L_Help_HELP_General01_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_General02_Text
WScript.Echo L_Help_HELP_General03_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_General04_Text
WScript.Echo L_Help_HELP_General05_Text
WScript.Echo L_Help_HELP_General06_Text
WScript.Echo L_Help_HELP_General07_Text
WScript.Echo L_Help_HELP_General07p2_Text
WScript.Echo L_Help_HELP_General08_Text
WScript.Echo L_Help_HELP_General09_Text
WScript.Echo L_Help_HELP_General10_Text
WScript.Echo L_Help_HELP_General11_Text
WScript.Echo L_Help_HELP_General11p1_Text
WScript.Echo L_Help_HELP_General12_Text
WScript.Echo L_Help_HELP_General12p1_Text
WScript.Echo L_Help_HELP_General13_Text
WScript.Echo L_Help_HELP_General13p1_Text
WScript.Echo L_Help_HELP_General14_Text
WScript.Echo L_Help_HELP_General14p1_Text
WScript.Echo L_Help_HELP_General15_Text
WScript.Echo L_Help_HELP_General15p1_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_General22_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_General23_Text
WScript.Echo L_Help_HELP_General24_Text
WScript.Echo L_Help_HELP_General25_Text
WScript.Echo L_Help_HELP_General26_Text
WScript.Echo L_Help_HELP_General27_Text
WScript.Echo L_Help_HELP_General28_Text
End Sub
Sub DisplayImportHelpMessage()
WScript.Echo L_Help_HELP_Import01_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Import02_Text
WScript.Echo L_Help_HELP_Import02p1_Text
WScript.Echo L_Help_HELP_Import02p2_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_General06_Text
WScript.Echo L_Help_HELP_General07_Text
WScript.Echo L_Help_HELP_General07p2_Text
WScript.Echo L_Help_HELP_General08_Text
WScript.Echo L_Help_HELP_General09_Text
WScript.Echo L_Help_HELP_General10_Text
WScript.Echo L_Help_HELP_Common13_Text
WScript.Echo L_Help_HELP_Common13p1_Text
WScript.Echo L_Help_HELP_Common13p2_Text
WScript.Echo L_Help_HELP_Common14_Text
WScript.Echo L_Help_HELP_Common15_Text
WScript.Echo L_Help_HELP_Common15p1_Text
WScript.Echo L_Help_HELP_Import16_Text
WScript.Echo L_Help_HELP_Import16p1_Text
WScript.Echo L_Help_HELP_Import16p2_Text
WScript.Echo L_Help_HELP_Import16p3_Text
WScript.Echo L_Help_HELP_Import17_Text
WScript.Echo L_Help_HELP_Import18_Text
WScript.Echo L_Help_HELP_Import19_Text
WScript.Echo L_Help_HELP_Import19p1_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Common21_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Import22_Text
WScript.Echo L_Help_HELP_Import22p1_Text
End Sub
Sub DisplayCopyHelpMessage()
WScript.Echo L_Help_HELP_Copy1_Text
WScript.Echo L_Help_HELP_Copy1p2_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Copy2_Text
WScript.Echo L_Help_HELP_Copy2p2_Text
WScript.Echo L_Help_HELP_Copy2p3_Text
WScript.Echo L_Help_HELP_Copy3_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Copy4_Text
WScript.Echo L_Help_HELP_Copy5_Text
WScript.Echo L_Help_HELP_Copy5p2_Text
WScript.Echo L_Help_HELP_Copy6_Text
WScript.Echo L_Help_HELP_Copy7_Text
WScript.Echo L_Help_HELP_Copy8_Text
WScript.Echo L_Help_HELP_Copy9_Text
WScript.Echo L_Help_HELP_Copy10_Text
WScript.Echo L_Help_HELP_Copy10p2_Text
WScript.Echo L_Help_HELP_Copy11_Text
WScript.Echo L_Help_HELP_Copy11p2_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Copy12_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Copy13_Text
WScript.Echo L_Help_HELP_Copy14_Text
WScript.Echo L_Help_HELP_Copy14p2_Text
End Sub
Sub DisplayExportHelpMessage()
WScript.Echo L_Help_HELP_Export01_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Export02_Text
WScript.Echo L_Help_HELP_Export02p1_Text
WScript.Echo L_Help_HELP_Export02p2_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_General06_Text
WScript.Echo L_Help_HELP_General07_Text
WScript.Echo L_Help_HELP_General07p2_Text
WScript.Echo L_Help_HELP_General08_Text
WScript.Echo L_Help_HELP_General09_Text
WScript.Echo L_Help_HELP_General10_Text
WScript.Echo L_Help_HELP_Common13_Text
WScript.Echo L_Help_HELP_Common13p1_Text
WScript.Echo L_Help_HELP_Common13p2_Text
WScript.Echo L_Help_HELP_Common14_Text
WScript.Echo L_Help_HELP_Common15_Text
WScript.Echo L_Help_HELP_Common15p1_Text
WScript.Echo L_Help_HELP_Export17_Text
WScript.Echo L_Help_HELP_Export18_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Common21_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Export22_Text
End Sub
Sub DisplaySaveHelpMessage()
WScript.Echo L_Help_HELP_Save01_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Save02_Text
WScript.Echo L_Help_HELP_Save02p2_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_General06_Text
WScript.Echo L_Help_HELP_General07_Text
WScript.Echo L_Help_HELP_General07p2_Text
WScript.Echo L_Help_HELP_General08_Text
WScript.Echo L_Help_HELP_General09_Text
WScript.Echo L_Help_HELP_General10_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Common21_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Save22_Text
WScript.Echo L_Help_HELP_Save23_Text
End Sub
Sub DisplayEnableAuditHelpMessage()
WScript.Echo L_Help_HELP_EnableAudit01_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_EnableAudit02_Text
WScript.Echo L_Help_HELP_EnableAudit02p2_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_General06_Text
WScript.Echo L_Help_HELP_General07_Text
WScript.Echo L_Help_HELP_General07p2_Text
WScript.Echo L_Help_HELP_General08_Text
WScript.Echo L_Help_HELP_General09_Text
WScript.Echo L_Help_HELP_General10_Text
WScript.Echo L_Help_HELP_EnableAudit16_Text
WScript.Echo L_Help_HELP_EnableAudit16p1_Text
WScript.Echo L_Help_HELP_EnableAudit17_Text
WScript.Echo L_Help_HELP_EnableAudit17p1_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Common21_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_EnableAudit22_Text
WScript.Echo L_Help_HELP_EnableAudit23_Text
WScript.Echo L_Help_HELP_EnableAudit24_Text
End Sub
Sub DisplayDisableAuditHelpMessage()
WScript.Echo L_Help_HELP_DisableAudit01_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_DisableAudit02_Text
WScript.Echo L_Help_HELP_DisableAudit02p2_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_General06_Text
WScript.Echo L_Help_HELP_General07_Text
WScript.Echo L_Help_HELP_General07p2_Text
WScript.Echo L_Help_HELP_General08_Text
WScript.Echo L_Help_HELP_General09_Text
WScript.Echo L_Help_HELP_General10_Text
WScript.Echo L_Help_HELP_DisableAudit16_Text
WScript.Echo L_Help_HELP_DisableAudit16p1_Text
WScript.Echo L_Help_HELP_DisableAudit17_Text
WScript.Echo L_Help_HELP_DisableAudit17p1_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_Common21_Text
WScript.Echo L_Empty_Text
WScript.Echo L_Help_HELP_DisableAudit22_Text
WScript.Echo L_Help_HELP_DisableAudit23_Text
WScript.Echo L_Help_HELP_DisableAudit24_Text
End Sub
'''''''''''''''''''''''''''
' Copy Function
'''''''''''''''''''''''''''
Function Repl(strSourceServer, strSourceUser, strSourcePwd, strDestServer, strDestUser, strDestPwd)
If (strSourceServer = ".") Then
strSourceServer = ""
End If
' Do the first backup
Dim strBackupCommand
Dim strSourceDrive, strDrvLetter, strSourcePath
Dim oShell, oFS, oNetwork
Dim strDestDrive, strDestPath
Dim strCopyCommand, strDelCommand, strRestoreCommand
Set oShell = WScript.CreateObject("WScript.Shell")
If Err.Number <> 0 Then
WScript.Echo L_Shell_ErrorMessage
WScript.Echo L_Shellp2_ErrorMessage
WScript.Quit(ERR_GENERAL_FAILURE)
End If
Set oFS = WScript.CreateObject("Scripting.FileSystemObject")
If Err.Number <> 0 Then
WScript.Echo L_FS_ErrorMessage
WScript.Echo L_FSp2_ErrorMessage
WScript.Quit(ERR_GENERAL_FAILURE)
End If
Set oNetwork = WScript.CreateObject("WScript.Network")
If Err.Number <> 0 Then
WScript.Echo L_Network_ErrorMessage
WScript.Echo L_Networkp2_ErrorMessage
WScript.Quit(ERR_GENERAL_FAILURE)
End If
strBackupCommand = "cmd /c %SystemRoot%\system32\cscript.exe %SystemRoot%\system32\iisback.vbs /backup"
If strSourceServer <> "" Then
strBackupCommand = strBackupCommand & " /s " & strSourceServer
Else
strSourceServer = "127.0.0.1"
End If
If strSourceUser <> "" Then
strBackupCommand = strBackupCommand & " /u " & strSourceUser
End If
If strSourcePwd <> "" Then
strBackupCommand = strBackupCommand & " /p " & strSourcePwd
End If
' need overwrite in case a previous attempt failed
strBackupCommand = strBackupCommand & " /b iisreplback /overwrite"
' backup the source server
oCmdLib.vbPrintf L_BackingUp_Message, Array(strSourceServer)
intResult = oShell.Run(strBackupCommand, 1, TRUE)
WScript.Echo L_BackupComplete_Message
' Now map drive to source server
' Find a drive letter
strSourceDrive = "NO DRIVE"
For strDrvLetter = Asc("C") to Asc("Z")
If Not oFS.DriveExists(Chr(strDrvLetter)) Then
strSourceDrive = Chr(strDrvLetter)
Exit For
End If
Next
If strSourceDrive = "NO DRIVE" Then
' No drive letter available
WScript.Echo L_NoDrive_ErrorMessage
WScript.Quit(ERR_GENERAL_FAILURE)
End If
strSourceDrive = strSourceDrive & ":"
strSourcePath = "\\" & strSourceServer & "\ADMIN$"
' Map the drive
oCmdLib.vbPrintf L_DriveLetter_Message, Array(strSourceDrive, strSourceServer)
If strSourceUser <> "" Then
oNetwork.MapNetworkDrive strSourceDrive, strSourcePath, FALSE, strSourceUser, strSourcePwd
Else
oNetwork.MapNetworkDrive strSourceDrive, strSourcePath
End If
' Now map drive to destination server
' Find a drive letter
strDestDrive = "NO DRIVE"
For strDrvLetter = Asc("C") to Asc("Z")
If Not oFS.DriveExists(Chr(strDrvLetter)) Then
strDestDrive = Chr(strDrvLetter)
Exit For
End If
Next
If strDestDrive = "NO DRIVE" Then
' No drive letter available
WScript.Echo L_NoDrive_ErrorMessage
WScript.Quit(ERR_GENERAL_FAILURE)
End If
strDestDrive = strDestDrive & ":"
strDestPath = "\\" & strDestServer & "\ADMIN$"
' Map the drive
oCmdLib.vbPrintf L_DriveLetter_Message, Array(strDestDrive, strDestServer)
If strDestUser <> "" Then
oNetwork.MapNetworkDrive strDestDrive, strDestPath, FALSE, strDestUser, strDestPwd
Else
oNetwork.MapNetworkDrive strDestDrive, strDestPath
End If
strCopyCommand = "cmd /c copy /Y " & strSourceDrive & "\system32\inetsrv\metaback\iisreplback.* "
strCopyCommand = strCopyCommand & strDestDrive & "\system32\inetsrv\metaback"
' Copy the files
WScript.Echo L_Copy_Message
WScript.Echo strCopyCommand
intResult = oShell.Run(strCopyCommand, 1, TRUE)
If intResult <> 0 Then
oCmdLib.vbPrintf L_ReturnVal_ErrorMessage, Array(intResult)
WScript.Echo L_Copy_ErrorMessage
WScript.Quit(intResult)
End If
strDelCommand = "cmd /c del /f /q " & strSourceDrive & "\system32\inetsrv\metaback\iisreplback.*"
intResult = oShell.Run(strDelCommand, 1, TRUE)
' Unmap drive to source server
oCmdLib.vbPrintf L_UnMap_Message, Array(strSourceDrive)
oNetwork.RemoveNetworkDrive strSourceDrive
' Now do the restore on the destination server
strRestoreCommand = "cmd /c %SystemRoot%\system32\cscript.exe %SystemRoot%\system32\iisback.vbs /restore /s " & strDestServer
strRestoreCommand = strRestoreCommand & " /u " & strDestUser
strRestoreCommand = strRestoreCommand & " /p " & strDestPwd
strRestoreCommand = strRestoreCommand & " /b iisreplback"
oCmdLib.vbPrintf L_Restoring_Message, Array(strDestServer)
intResult = oShell.Run(strRestoreCommand, 1, TRUE)
If intResult <> 0 Then
oCmdLib.vbPrintf L_ReturnVal_ErrorMessage, Array(intResult)
WScript.Echo L_Restore_ErrorMessage
WScript.Quit(intResult)
End If
WScript.Echo L_RestoreComplete_Message
strDelCommand = "cmd /c del /f /q " & strDestDrive & "\system32\inetsrv\metaback\iisreplback.*"
intResult = oShell.Run(strDelCommand, 1, TRUE)
' Unmap drive to destination server
oCmdLib.vbPrintf L_UnMap_Message, Array(strDestDrive)
oNetwork.RemoveNetworkDrive strDestDrive
WScript.Echo L_CopyComplete_Message
End Function
'''''''''''''''''''''''''''
' Import Function
'''''''''''''''''''''''''''
Function Import(strDecPass, strFile, strSourcePath, strDestPath, intFlags)
Dim ComputerObj
Dim strFilePath
On Error Resume Next
' Normalize path first
strFilePath = oScriptHelper.NormalizeFilePath(strFile)
If Err Then
Select Case Err.Number
Case &H80070002
WScript.Echo L_FileExpected_ErrorMessage
WScript.Echo L_FileExpectedp2_ErrorMessage
Case &H80070003
WScript.Echo L_ParentFolderDoesntExist_ErrorMessage
End Select
Import = Err.Number
Exit Function
End If
oScriptHelper.WMIConnect
If Err.Number Then
WScript.Echo L_WMIConnect_ErrorMessage
oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
Import = Err.Number
Exit Function
End If
Set ComputerObj = oScriptHelper.ProviderObj.get("IIsComputer='LM'")
If Err.Number Then
Select Case Err.Number
Case &H80070005
WScript.Echo L_Admin_ErrorMessage
WScript.Echo L_Adminp2_ErrorMessage
Case Else
WScript.Echo L_GetComputerObj_ErrorMessage
oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
End Select
Import = Err.Number
Exit Function
End If
' Call Import method from the computer object
ComputerObj.Import strDecPass, strFilePath, strSourcePath, strDestPath, intFlags
If Err.Number Then
Select Case Err.Number
Case &H80070002
WScript.Echo L_FileDoesntExist_ErrorMessage
Case &H8007052B
WScript.Echo L_IncorrectPassword_ErrorMessage
Case &H800CC819
WScript.Echo L_InvalidXML_ErrorMessage
Case Else
WScript.Echo L_Import_ErrorMessage
WScript.Echo Err.Description
End Select
Import = Err.Number
Exit Function
End If
oCmdLib.vbPrintf L_ConfImported_Text, Array(strSourcePath)
oCmdLib.vbPrintf L_ConfImportedp2_Text, Array(strFile, strDestPath)
End Function
'''''''''''''''''''''''''''
' Export Function
'''''''''''''''''''''''''''
Function Export(strDecPass, strFile, strSourcePath, intFlags)
Dim ComputerObj
Dim strFilePath
On Error Resume Next
' Normalize path first
strFilePath = oScriptHelper.NormalizeFilePath(strFile)
If Err Then
Select Case Err.Number
Case &H80070002
WScript.Echo L_FileExpected_ErrorMessage
WScript.Echo L_FileExpectedp2_ErrorMessage
Case &H80070003
WScript.Echo L_ParentFolderDoesntExist_ErrorMessage
End Select
Export = Err.Number
Exit Function
End If
If oScriptHelper.FSObj.FileExists(strFilePath) Then
WScript.Echo L_FileAlreadyExist_ErrorMessage
Export = &H80070050
Exit Function
End If
oScriptHelper.WMIConnect
If Err.Number Then
WScript.Echo L_WMIConnect_ErrorMessage
oCmdLib.vbPrintf L_Error_ErrorMessage, Array(Hex(Err.Number), Err.Description)
Export = Err.Number
Exit Function
End If