-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconfUtils.vbs
979 lines (775 loc) · 37.5 KB
/
confUtils.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
' Èíèöèàëèçèðóåì íåîáõîäèìûå ïåðåìåííûå
on error goto 0
' ñëåäóþùèå äâå ñòðîêè äëÿ âûâîäà îòëàäî÷íûõ ñîîáùåíèé
' ýòè äâå ñòðîêè ìîæíî è óäàëèòü
Dim DebugFlag 'îáÿçàòåëüíî ãëîáàëüíàÿ ïåðåìåííàÿ
' DebugFlag = True 'Ðàçðåøàþ âûâîä îòëàäî÷íûõ ñîîáùåíèé
Dim wshShell
Dim fso 'as FileSystemObject
Dim LogFile 'as File
Dim sLogFile 'as string
Dim ResDict 'as Dictionary
Dim ConfDict 'as Dictionary
Dim strCOMConnector ' as string
Dim sFullClusterName ' as string
' Echo("WScript.ScriptFullName = " + WScript.ScriptFullName)
Wscript.Quit( main() )
'********************************************************************
' Âîçâðàùàåò 1 ïðè óñïåõå, 0 - ïðè íåóäà÷å
Function main( )
main = 1
'Make sure the host is csript, if not then abort
VerifyHostIsCscript()
' ïðîâåðèòü âåðñèþ Windows Script Host
if CDbl(replace(WScript.Version,".",","))<5.6 then
Echo "Äëÿ ðàáîòû ñöåíàðèÿ òðåáóåòñÿ Windows Script Host âåðñèè 5.6 è âûøå !"
Exit Function
end if
' Èíèöèàëèçàöèÿ ñöåíàðèÿ
if not Init() then
Exit Function
end if
'Exit Function
ServerName = ResDict.Item(LCase("ServerName")) ' "WorkServer" 'Èìÿ ñåðâåðà ÁÄ
KlasterPortNumber = ResDict.Item(LCase("KlasterPortNumber")) ' 1541 'Íîìåð ïîðà êëàñòåðà
InfoBaseName = ResDict.Item(LCase("InfoBaseName")) ' "IMOUT_User_01" 'Èìÿ ÈÁ
sFullServerName = ServerName
sFullClusterName = ServerName
if "" <> CStr(KlasterPortNumber) then
sFullServerName = ServerName + ":" + CStr(KlasterPortNumber)
sFullClusterName = ServerName + ":" + CStr(CInt(KlasterPortNumber)-1)
end if
ServerName83 = ResDict.Item(LCase("ServerName83"))
KlasterPortNumber83 = ResDict.Item(LCase("KlasterPortNumber83"))
InfoBaseName83 = ResDict.Item(LCase("InfoBaseName83"))
sFullServerName83 = ServerName83
if "" <> CStr(KlasterPortNumber83) then
sFullServerName83 = sFullServerName83 + ":" + CStr(KlasterPortNumber83)
end if
RepositoryPath = ResDict.Item(LCase("RepositoryPath")) ' "E:\Repository\test" ' ïóòü ê õðàíèëèùó
' ÂÀÆÍÎ - áàçà äîëæíà áûòü ðàíåå çàðåãèñòðèðîâàíà êàê server:port\baseName - íàïðèìåð, WorkServer:1541\IMOUT_User_01
' åñëè áàçà áûëà çàðåãèñòðèðîâàíà êàê server\baseName (áåç óêàçàíèÿ ïîðòà) - ïðè ðàáîòå ñ õðàíèëèùåì áóäåò îøèáêà èç-çà èçìåíåíåíèÿ ìåñòîíàõîæäåíèÿ èíôîðìàöèîííîé áàçû
' åñëè òàêîé ðåãèñòðàöèè íå áûëî, íå óäàåòñÿ çàãðóçèòü èçìåíåíèÿ èç õðàíèëèùà
' ÂÀÆÍÎ íå äîëæåí áûòü çàïóùåí ïðîöåññ Êîíôèãóðàòîðà ñ ïîäêëþ÷åíèåì ê õðàíèëèùó ñ òàêèì ïîëüçîâàòåëåì !
' áóäåò îøèáêà - (Ïîëüçîâàòåëü óæå àóòåíòèôèöèðîâàí â õðàíèëèùå.)
ClasterAdminName = ResDict.Item(LCase("ClasterAdminName")) ' "" 'Èìÿ àäìèíèñòðàòîðà êëàñòåðà
ClasterAdminPass = ResDict.Item(LCase("ClasterAdminPass")) ' "" 'Ïàðîëü àäìèíèñòðàòîðà êëàñòåðà
InfoBasesAdminName = ResDict.Item(LCase("InfoBasesAdminName")) ' "Àäìèíèñòðàòîð1" 'Èìÿ àäìèíèñòðàòîðà ÈÁ
InfoBasesAdminPass = ResDict.Item(LCase("InfoBasesAdminPass")) ' "" 'Ïàðîëü àäìèíèñòðàòîðà ÈÁ
RepositoryAdminName = ResDict.Item(LCase("RepositoryAdminName")) ' "Àäìèíèñòðàòîð" ' Èìÿ àäìèíèñòðàòîðà õðàíèëèùà
RepositoryAdminPass = ResDict.Item(LCase("RepositoryAdminPass")) ' "" ' Ïàðîëü àäìèíèñòðàòîðà õðàíèëèùà
'FilePath = ResDict.Item(LCase("FilePath")) ' "\\WorkServer\Share\Admin1C\confupdate.vbs" 'Ïóòü ê òåêóùåìó ôàéëó
NetFile = ResDict.Item(LCase("NetFile")) ' "\\WorkServer\Share\Admin1C\confupdate_base.txt" 'Ïóòü ê log-ôàéëó â ñåòè - èñïîëüçóåòñÿ òîëüêî äëÿ NeedCopyFiles = True
Folder = ResDict.Item(LCase("Folder")) ' "\\WorkServer\Share\Admin1C\" 'Êàòàëîã äëÿ âûãðóçêè áàçû
CountDB = CInt(ResDict.Item(LCase("CountDB"))) ' 7 'Çà ñêîëüêî äíåé õðàíèòü êîïèè
Prefix = ResDict.Item(LCase("Prefix")) ' "base" 'Ïðåôèêñ ôàéëà âûãðóçêè
Out = ResDict.Item(LCase(LCase("LogFile"))) ' "\\WorkServer\Share\Admin1C\confupdate.txt" 'Ïóòü ê log-ôàéëó
sLogFile = Out
Debug "Out", Out
'UpdateFromStorage = ResDict.Item(LCase("UpdateFromStorage")) ' " /ConfigurationRepositoryUpdateCfg -v -force -revised " ' îáíîâëÿåì èç õðàíèëèùà
NeedUpdateFromStorage = UCase(ResDict.Item(LCase("NeedUpdateFromStorage"))) = "TRUE" ' Íåîáõîäèìîñòü îáíîâëåíèÿ êîíôèãóðàöèè èç õðàíèëèùà êîíôèãóðàöèè
NeedDumpIB = UCase(ResDict.Item(LCase("NeedDumpIB"))) = "TRUE" ' True ' Íåîáõîäèìîñòü âûãðóçêè áàçû
NeedCopyFiles = UCase(ResDict.Item(LCase("NeedCopyFiles"))) = "TRUE" ' True ' Íåîáõîäèìîñòü âûãðóçêè áàçû
NeedTestIB = UCase(ResDict.Item(LCase("NeedTestIB"))) = "TRUE" ' False ' Íåîáõîäèìîñòü òåñòèðîâàíèÿ áàçû
NeedRestartAgent = UCase(ResDict.Item(LCase("NeedRestartAgent"))) = "TRUE" ' False ' Íåîáõîäèìîñòü ðåñòàðòà àãåíòà ñåðâåðà
NeedRestoreIB = UCase(ResDict.Item(LCase("NeedRestoreIB"))) = "TRUE" ' Íåîáõîäèìîñòü âîññòàíîâëåíèÿ êîíôèãóðàöèè èç ôàéëà
NeedRestoreIB83 = UCase(ResDict.Item(LCase("NeedRestoreIB83"))) = "TRUE" ' Íåîáõîäèìîñòü âîññòàíîâëåíèÿ êîíôèãóðàöèè èç ôàéëà ïëàòôîðìîé 8.3
NeedStartIB = UCase(ResDict.Item(LCase("NeedStartIB"))) = "TRUE" ' Íåîáõîäèìîñòü çàïóñêà 1Ñ ïîñëå îáíîâëåíèÿ èç õðàíèëèùà äëÿ îáíîâëåíèÿ â ðåæèìå Ïðåäïðèÿòèÿ
IBFile = ResDict.Item(LCase("IBFile")) ' "" 'Ïóòü ê ôàéëó ñ âûãðóçêîé áàçû
LockMessageText = ResDict.Item(LCase("LockMessageText")) ' "Èäåò ðåãëàìåíò. Ïîäîæäèòå..." 'Òåêñò ñîîáùåíèÿ î áëîêèðîâêè ïîäêëþ÷åíèé ê ÈÁ
LockPermissionCode = ResDict.Item(LCase("LockPermissionCode")) ' "Àðòóð" 'Êëþ÷ äëÿ çàïóñêà çàáëîêèðîâàííîé ÈÁ
AuthStr = ResDict.Item(LCase("AuthStr")) ' "/WA+"
TimeSleep = ResDict.Item(LCase("TimeSleep")) ' 10000 '600000 '10 ñåêóíä 600 ñåêóíä
TimeSleepShort = ResDict.Item(LCase("TimeSleepShort")) ' 2000 '60000 '2 ñåêóíä 60 ñåêóíä
Cfg = ResDict.Item(LCase("Cfg")) ' "" 'Ïóòü ê ôàéëó ñ èçìåíåííîé êîíôèãóðàöèåé
InfoCfgFile = ResDict.Item(LCase("InfoCfgFile")) ' "" 'Èíôîðìàöèÿ î ôàéëå îáíîâëåíèÿ êîíôèãóðàöèè
v8exe = ResDict.Item(LCase("v8exe")) ' "C:\Program Files (x86)\1cv82\8.2.18.96\bin\1cv8.exe" 'Ïóòü ê èñïîëíÿåìîìó ôàéëó 1Ñ:Ïðåäïðèÿòèÿ 8.2
v83exe = ResDict.Item(LCase("v83exe"))
'rem NewPass = "" 'Íîâûé ïàðîëü àäìèíèñòðàòîðà, îáíîâëÿþùåãî ÈÁ
strCOMConnector = ResDict.Item(LCase("COMConnector"))
bSuccess = OpenLogFile
if not bSuccess then
Echo(CStr(Now) + " Íå óäàëîñü èçìåíèòü ëîã-ôàéë. ëîã-ôàéë çàáëîêèðîâàí äðóãîé ïðîãðàììîé")
Exit Function
end if
TimeBeginLock = Now ' Âðåìÿ íà÷àëà áëîêèðîâêè ÈÁ
TimeEndLock = DateAdd("h", 2, TimeBeginLock) ' Âðåìÿ îêîí÷àíèÿ áëîêèðîâêè ÈÁ
Debug "ServerName", ServerName
Echo(CStr(Now) + " ÍÀ×ÀËÎ ÎÁÍÎÂËÅÍÈß ÊÎÍÔÈÃÓÐÀÖÈÈ")
'Echo(CStr(Now) + " Ñîçäàíèå COM-êîííåêòîðà")
Set ComConnector = CreateCOMConnector() ' CreateObject("v82.COMConnector")
Echo(CStr(Now) + " Ïîäêëþ÷åíèå ê àãåíòó ñåðâåðà")
Set ServerAgent = ComConnector.ConnectAgent(sFullClusterName) ' ComConnector.ConnectAgent(ServerName)
Echo(CStr(Now) + " Ïîëó÷åíèå ìàññèâà êëàñòåðîâ ñåðâåðà ó àãåíòà ñåðâåðà")
Clasters = ServerAgent.GetClusters()
Echo(CStr(Now) + " Íà÷àëî çàâåðøåíèÿ ðàáîòû ïîëüçîâàòåëåé")
Echo(CStr(Now) + " Íà÷àëî öèêëà íàõîæäåíèÿ íåîáõîäèìîãî êëàñòåðà ïî èìåíè")
findClaster = false
For i = LBound(Clasters) To UBound(Clasters)
'If Claster.MainPort = KlasterPortNumber Then
Set Claster = Clasters(i)
'Debug "UCase(Claster.HostName)", UCase(Claster.HostName)
if (UCase(Claster.HostName) = UCase(ServerName)) then
findClaster = true
Exit for
End if
Next
if findClaster = false then
Echo(CStr(Now) + " Îøèáêà - íå íàøëè êëàñòåð <"+sFullClusterName+">") 'ServerName
Exit Function
end if
Echo(CStr(Now) + " Àóòåíòèêàöèÿ ê íàéäåííîìó êëàñòåðó: " + Claster.ClusterName + ", "+Claster.HostName)
'Echo(CStr(Now) + " Àóòåíòèêàöèÿ ê íàéäåííîìó êëàñòåðó: " + Claster.Name + ", "+Claster.HostName)
ServerAgent.Authenticate Claster, ClasterAdminName, ClasterAdminPass
Echo(CStr(Now) + " Ïîëó÷åíèå ñïèñêà ðàáîòàþùèõ ðàáî÷èõ ïðîöåññîâ è îáõîä â öèêëå")
FindInfoBase = False
WorkServers = ServerAgent.GetWorkingServers(Claster)
For i = LBound(WorkServers) To UBound(WorkServers)
Set WorkServer = WorkServers(i)
Echo(CStr(Now) + " Îáðàáàòûâàþ ðàáî÷èé ñåðâåð "+WorkServer.Name+": " + WorkServer.HostName)
WorkingProcesses = ServerAgent.GetServerWorkingProcesses(Claster, WorkServer)
'set WorkingProcesses = ServerAgent.GetWorkingProcesses(Claster, WorkServer)
'Åñëè Ðàáî÷èåÏðîöåññû <> ÍÅÎÏÐÅÄÅËÅÍÎ Òîãäà
For j = LBound(WorkingProcesses) To UBound(WorkingProcesses)
If WorkingProcesses(j).Running = 1 Then
Echo(CStr(Now) + " Ñîçäàíèå ñîåäèíåíèÿ ñ ðàáî÷èì ïðîöåññîì " + WorkingProcesses(j).HostName + ":" + CStr(WorkingProcesses(j).MainPort))
Set ConnectToWorkProcess = ComConnector.ConnectWorkingProcess("tcp://" + WorkingProcesses(j).HostName + ":" + CStr(WorkingProcesses(j).MainPort))
ConnectToWorkProcess.AuthenticateAdmin ClasterAdminName, ClasterAdminPass
ConnectToWorkProcess.AddAuthentication InfoBasesAdminName, InfoBasesAdminPass
If Not FindInfoBase Then
Echo(CStr(Now) + " Ïîëó÷åíèå ñïèñêà ÈÁ ðàáî÷åãî ïðîöåññà")
InfoBases = ConnectToWorkProcess.GetInfoBases()
Echo(CStr(Now) + " Ïîèñê íóæíîé ÈÁ")
For h = LBound(InfoBases) To UBound(InfoBases)
Echo(CStr(Now) + " Îáðàáàòûâàåòñÿ ÈÁ: " + InfoBases(h).Name)
If LCase(InfoBases(h).Name) = LCase(InfoBaseName) Then
Set InfoBase = InfoBases(h)
FindInfoBase = True
Echo(CStr(Now) + " Íàøëè íóæíóþ ÈÁ")
Exit For
End If
Next
If Not FindInfoBase Then
Echo(CStr(Now) + " Íå íàøëè íóæíóþ ÈÁ <"+InfoBaseName+">")
Exit Function
End If
Echo(CStr(Now) + " Óñòàíîâêà çàïðåòà íà ïîäêëþ÷åíèÿ ê ÈÁ: " + InfoBase.Name)
InfoBase.ConnectDenied = True
InfoBase.ScheduledJobsDenied = True
InfoBase.DeniedFrom = TimeBeginLock
InfoBase.DeniedTo = TimeEndLock
InfoBase.DeniedMessage = LockMessageText
InfoBase.PermissionCode = LockPermissionCode
ConnectToWorkProcess.UpdateInfoBase(InfoBase)
InfoBases = ServerAgent.GetInfoBases(Claster)
Echo(CStr(Now) + " Ïîèñê íóæíîé ÈÁ äëÿ ñåññèè")
For h = LBound(InfoBases) To UBound(InfoBases)
Echo(CStr(Now) + " Îáðàáàòûâàåòñÿ ÈÁ: " + InfoBases(h).Name)
If LCase(InfoBases(h).Name) = LCase(InfoBaseName) Then
Set InfoBaseSession = InfoBases(h)
'FindInfoBase = True
Echo(CStr(Now) + " Íàøëè íóæíóþ ÈÁ äëÿ ñåññèè")
Exit For
End If
Next
' Óñòàíàâëèâàåì çàäåðæêó âûïîëíåíèÿ
Echo(CStr(Now) + " Çàäåðæêà ïåðåä íà÷àëîì çàâåðøåíèÿ ðàáîòû ïîëüçîâàòåëåé")
'Echo(CStr(Now) + " Çàäåðæêà ïåðåä íà÷àëîì çàâåðøåíèÿ ðàáîòû ïîëüçîâàòåëåé")
'set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep TimeSleep
End If
Echo(CStr(Now) + " Íà÷àëî çàâåðøåíèå ðàáîòû ïîëüçîâàòåëåé ñ ÈÁ " + InfoBase.Name)
If FindInfoBase Then
Echo(CStr(Now) + " Îáðàáîòêà ñïèñêà ñåàíñîâ")
Sessions = ServerAgent.GetInfoBaseSessions(Claster, InfoBaseSession)
For k = LBound(Sessions) To UBound(Sessions)
Set Session = Sessions(k)
UserName = Session.UserName
'ConnID = Session.ConnID;
AppID = UCase(Session.AppID)
'Åñëè ÍÅ îòêëþ÷àåìÊîíôèãóðàòîð È íÐåã(AppID) = "designer" Òîãäà
'//Åñëè íÐåã(AppID) = "backgroundjob" ÈËÈ íÐåã(AppID) = "designer" Òîãäà
' // åñëè ýòî ñåàíñû êîíôèãóðàòîðà èëè ôîíîâîãî çàäàíèÿ, òî íå îòêëþ÷àåì
' Ïðîäîëæèòü;
'ÊîíåöÅñëè;
'//Åñëè UserName = ÈìÿÏîëüçîâàòåëÿ() Òîãäà
'// // ýòî òåêóùèé ïîëüçîâàòåëü
'// Ïðîäîëæèòü;
'//ÊîíåöÅñëè;
Echo(CStr(Now) + " Îòêëþ÷åíî ñîåäèíåíèå: " + "User=["+UserName+"] ConnID=["+""+"] AppID=["+AppID+"]")
ServerAgent.TerminateSession Claster, Session
next
if false then
Echo(CStr(Now) + " Îáðàáîòêà ñïèñêà ñîåäèíåíèé")
Connections = ConnectToWorkProcess.GetInfoBaseConnections(InfoBase)
For k = LBound(Connections) To UBound(Connections)
Echo(CStr(Now) + " Ðàçðûâàåì ñîåäèíåíèå: Ïîëüçîâàòåëü " + Connections(k).UserName + ", êîìïüþòåð " + Connections(k).HostName + ", óñòàíîâëåíî " + CStr(Connections(k).ConnectedAt) + ", ðåæèì " + Connections(k).AppID)
If Connections(k).AppID = "SrvrConsole" Then
' Íå òðîãàåì ñîåäèíåíèÿ êîíñîëè, îíî íèêîìó íå ìåøàåò
ElseIf Connections(k).AppID = "COMConsole" Then
' Íå òðîãàåì ñîåäèíåíèÿ êîíñîëè, îíî íèêîìó íå ìåøàåò
Else
ConnectToWorkProcess.Disconnect(Connections(k))
Echo(CStr(Now) + " Îòêëþ÷åíî ñîåäèíåíèå: Ïîëüçîâàòåëü " + Connections(k).UserName + ", êîìïüþòåð " + Connections(k).HostName + ", óñòàíîâëåíî " + CStr(Connections(k).ConnectedAt) + ", ðåæèì " + Connections(k).AppID)
End If
Next
End If
End If
Echo(CStr(Now) + " Îêîí÷àíèå çàâåðøåíèÿ ðàáîòû ïîëüçîâàòåëåé")
End If
Next
next
ComConnector = Null
ServerAgent = Null
Clasters = Null
WorkingProcesses = Null
ConnectToWorkProcess = Null
InfoBases = Null
InfoBase = Null
Connections = Null
If NeedRestartAgent Then
RestartAgent TimeSleepShort
End If
If FindInfoBase Then
'Ïîêàæåì ñâîáîäíîå ìåñòî íà äèñêå ñ èñïîëíÿåìûì ôàéëîì 1Ñ
Echo(CStr(Now) + " " + ShowFreeSpace(v8exe))
'Ïîêàæåì ñâîáîäíîå ìåñòî íà äèñêå ñ àðõèâàìè
Echo(CStr(Now) + " " + ShowFreeSpace(Folder))
If NeedRestoreIB Then
Echo(CStr(Now) + " Âîññòàíîâëåíèå ýòàëîííîé áàçû")
strCommLine = " /RestoreIB """ + IBFile + """"
sTempFile = FSO.GetSpecialFolder(2) + "\" +FSO.GetTempName()
LineExe = """" + v8exe + """ DESIGNER /S""" + sFullServerName + "\" + InfoBaseName + """ /UC""" + LockPermissionCode + """ /DisableStartupMessages " + AuthStr + " " + strCommLine + " /Out""" + sTempFile +""""
Echo(CStr(Now) + " êîì.ñòðîêà çàïóñêà: " + LineExe)
wshShell.Run LineExe, 5, True
Show1CConfigLog sTempFile, " Îøèáêà ïðè çàãðóçêå áàçû èç ôàéëà"
End If
if NeedUpdateFromStorage then
Echo(CStr(Now) + " Îáíîâëåíèå êîíôèãóðàöèè èç õðàíèëèùà")
strRepository = " /ConfigurationRepositoryF"""+RepositoryPath+""""
strRepository = strRepository + " /ConfigurationRepositoryN"""+RepositoryAdminName + """ /ConfigurationRepositoryP"""+RepositoryAdminPass+""""
UpdateFromStorage = " /ConfigurationRepositoryUpdateCfg -v -force -revised " ' îáíîâëÿåì èç õðàíèëèùà
' /LoadCfg çàãðóçêà êîíôèãóðàöèè èç ôàéëà;
' /UpdateCfg îáíîâëåíèå êîíôèãóðàöèè, íàõîäÿùåéñÿ íà ïîääåðæêå;
' /ConfigurationRepositoryUpdateCfg îáíîâëåíèå êîíôèãóðàöèè èç õðàíèëèùà;
' /LoadConfigFiles çàãðóçèòü ôàéëû êîíôèãóðàöèè.
sTempFile = FSO.GetSpecialFolder(2) + "\" +FSO.GetTempName()
LineExe = """" + v8exe + """ DESIGNER /S""" + sFullServerName + "\" + InfoBaseName + """ /UC""" + LockPermissionCode + """ /DisableStartupMessages " + AuthStr + " " +UpdateFromStorage + strRepository + " /Out""" + sTempFile +""""
Echo(CStr(Now) + " êîì.ñòðîêà çàïóñêà: "+LineExe)
'LogFile.Close()
'LogFile = ""
' Îáíîâèì êîíôèãóðàöèþ èç õðàíèëèùà
wshShell.Run LineExe, 5, True
' àíàëèçèðóþ ëîã ðàáîòû êîíôèãóðàòîðà, ò.ê ìîãóò áûòü îøèáêè, íàïðèìåð, Îøèáêà ïðè âûïîëíåíèè îïåðàöèè ñ èíôîðìàöèîííîé áàçîé èëè Îøèáêà îáíîâëåíèÿ êîíôèãóðàöèè èç õðàíèëèùà
'èëè Äëÿ âûïîëíåíèÿ îïåðàöèè òðåáóåòñÿ ïîëó÷åíèå îáúåêòîâ:
'èëè Îïåðàöèÿ ñ õðàíèëèùåì êîíôèãóðàöèè îòìåíåíà
' òàêæå ëîã êîíôèãóðàòîðà ïîêàçûâàþ â ñâîåì ëîãå
Show1CConfigLog sTempFile, " Îøèáêà ïðè îáíîâëåíèè êîíôèãóðàöèè èç õðàíèëèùà"
end if ' NeedUpdateFromStorage
Echo(CStr(Now) + " Îáíîâëåíèå êîíôèãóðàöèè ÈÁ") 'EchoWithOpenAndCloseLog
sTempFile = FSO.GetSpecialFolder(2) + "\" +FSO.GetTempName()
LineExe = """" + v8exe + """ DESIGNER /S""" + sFullServerName + "\" + InfoBaseName + """ /UC""" + LockPermissionCode + """ /DisableStartupMessages " + AuthStr + " " + " /UpdateDBCfg -Server /Out""" + sTempFile + """ -NoTruncate"
Echo(CStr(Now) + " êîì.ñòðîêà çàïóñêà: "+LineExe) ' EchoWithOpenAndCloseLog
' Îáíîâèì êîíôèãóðàöèþ ÁÄ
wshShell.Run LineExe, 5, True
' àíàëèçèðóþ ëîã ðàáîòû êîíôèãóðàòîðà, ò.ê ìîãóò áûòü îøèáêè è áàçà íå îáíîâèòñÿ
' òàêæå ëîã êîíôèãóðàòîðà ïîêàçûâàþ â ñâîåì ëîãå
Show1CConfigLog sTempFile, " Îøèáêà ïðè îáíîâëåíèè áàçû äàííûõ"
If FSO.FolderExists(Folder) = False Then
FSO.CreateFolder Folder
End if
If NeedDumpIB = True Then
Echo(CStr(Now) + " âûãðóæàåì áàçó äàííûõ â àðõèâ") ' EchoWithOpenAndCloseLog
formatDate = GetFormatDay
sTempFile = FSO.GetSpecialFolder(2) + "\" +FSO.GetTempName()
LineExe = """" + v8exe + """ DESIGNER /S""" + sFullServerName + "\" + InfoBaseName + """ /UC""" + LockPermissionCode + """ /DisableStartupMessages " + AuthStr + " /DumpIB""" + Folder + Prefix + formatDate + ".dt"" /Out""" + sTempFile + """ -NoTruncate"
Echo(CStr(Now) + " êîì.ñòðîêà: " + LineExe) ' EchoWithOpenAndCloseLog
wshShell.Run LineExe, 5, True
haveProblem = Show1CConfigLog(sTempFile, " Îøèáêà ïðè âûãðóçêå áàçû äàííûõ")
If Not haveProblem And NeedRestoreIB83 Then
Echo(CStr(Now) + " Âîññòàíîâëåíèå áàçû â 8.3")
strCommLine = " /RestoreIB """ + Folder + Prefix + formatDate + ".dt"""
sTempFile = FSO.GetSpecialFolder(2) + "\" +FSO.GetTempName()
LineExe = """" + v83exe + """ DESIGNER /S """ + sFullServerName83 + "\" + InfoBaseName83 + """ /UC """ + LockPermissionCode + """ /DisableStartupMessages " + AuthStr + " " + strCommLine + " /Out """ + sTempFile +""""
Echo(CStr(Now) + " êîì.ñòðîêà çàïóñêà: " + LineExe)
wshShell.Run LineExe, 5, True
Show1CConfigLog sTempFile, " Îøèáêà ïðè çàãðóçêå áàçû èç ôàéëà"
End If
End if
If NeedTestIB = True Then
Echo(CStr(Now) + " òåñòèðóåì áàçó è ïåðåñ÷èòûâàåì èòîãè.") ' EchoWithOpenAndCloseLog
sTempFile = FSO.GetSpecialFolder(2) + "\" +FSO.GetTempName()
LineExe = """" + v8exe + """ DESIGNER /S""" + sFullServerName + "\" + InfoBaseName + """ /UC""" + LockPermissionCode + """ /DisableStartupMessages " + AuthStr + " /IBCheckAndRepair -LogIntegrity -RecalcTotals /Out""" + sTempFile + """ -NoTruncate"
Echo(CStr(Now) + " êîì.ñòðîêà: " + LineExe) ' EchoWithOpenAndCloseLog
wshShell.Run LineExe, 5, True
Show1CConfigLog sTempFile, " Îøèáêà ïðè âûãðóçêå áàçû äàííûõ"
End if
if NeedStartIB then
Echo(CStr(Now) + " îáíîâëÿåì áàçó â ðåæèìå Ïðåäïðèÿòèÿ.") ' EchoWithOpenAndCloseLog
sTempFile = FSO.GetSpecialFolder(2) + "\" +FSO.GetTempName()
LineExe = """" + v8exe + """ ENTERPRISE /CCLOSE /S""" + sFullServerName + "\" + InfoBaseName + """ /UC""" + LockPermissionCode + """ /DisableStartupMessages " + AuthStr + " /Out""" + sTempFile + """ -NoTruncate"
Echo(CStr(Now) + " êîì.ñòðîêà: " + LineExe) ' EchoWithOpenAndCloseLog
wshShell.Run LineExe, 5, True
Show1CConfigLog sTempFile, " Îøèáêà ïðè îáíîâëåíèè áàçû â ðåæèìå Ïðåäïðèÿòèÿ"
end if
'OpenLogFile
Echo(CStr(Now) + " Óñòàíîâêà ðàçðåøåíèÿ ïîäêëþ÷åíèÿ ê ÈÁ")
FindInfoBase = False
EnableConnections ServerName, ClasterAdminName, ClasterAdminPass, InfoBasesAdminName, InfoBasesAdminPass, InfoBaseName
End If ' FindInfoBase
WriteLogIntoIBEventLog sFullServerName, InfoBaseName, sLogFile
If NeedCopyFiles = True Then
If fso.FileExists(NetFile) Then
fso.DeleteFile(NetFile)
End If
Debug "Out", Out
Debug "NetFile", NetFile
fso.MoveFile Out, NetFile
Debug "NetFile", NetFile
End if
If NeedDumpIB = True Then
CALL DelOldFiles(Folder, CountDB)
End if
main = 0
End Function
Function Show1CConfigLog(sTempFile, errorMessage)
Set configLogFile = fso.OpenTextFile(sTempFile, 1)
haveProblem = false
Do While configLogFile.AtEndOfStream <> True
errorString = configLogFile.ReadLine
Echo errorString
errorPos = InStr(1, errorString, "Îøèáêà", 1)
If errorPos > 0 Then
haveProblem = true
end if
Loop
if haveProblem = true then
Echo(CStr(Now) + errorMessage) ' EchoWithOpenAndCloseLog '" Îøèáêà ïðè îáíîâëåíèè êîíôèãóðàöèè èç õðàíèëèùà")
end if
configLogFile.Close()
Show1CConfigLog = haveProblem
End Function
Sub WriteLogIntoIBEventLog(sFullServerName, InfoBaseName, sLogFile)
'Sub WriteLogIntoIBEventLog(ServerName, KlasterPortNumber, InfoBaseName, sLogFile)
Echo(CStr(Now) + " Ñîõðàíåíèå ëîãà â æóðíàë ðåãèñòðàöèè ÈÁ")
Set ComConnector = CreateCOMConnector() ' CreateObject("v82.COMConnector")
'Set connection = ComConnector.Connect("Srvr=" + ServerName + ":" + CStr(KlasterPortNumber) + ";Ref=" + InfoBaseName + ";Usr=" + InfoBasesAdminName + ";Pwd=" + InfoBasesAdminPass)
Set connection = ComConnector.Connect("Srvr=" + sFullServerName + ";Ref=" + InfoBaseName)
Echo(CStr(Now) + " ÇÀÂÅÐØÅÍÈÅ ÎÁÍÎÂËÅÍÈß ÊÎÍÔÈÃÓÐÀÖÈÈ")
'LogFile.Close()
'LogFile = ""
Set f = fso.OpenTextFile(sLogFile, 1, False, -2) 'Out
Text = f.ReadAll
'Çàïèøåì âñþ èíôîðìàöèþ èç log-ôàéëà â æóðíàë ðåãèñòðàöèè
connection.WriteLogEvent "Ðåãëàìåíòíîå îáíîâëåíèå ÈÁ", connection.EventLogLevel.Information,,, Text
connection = Null
ComConnector = Null
f = Null
End Sub
Function CreateCOMConnector()
Echo(CStr(Now) + " Ñîçäàíèå COM-êîííåêòîðà <"+ strCOMConnector + ">")
Set ComConnector = CreateObject(strCOMConnector) ' CreateObject("v82.COMConnector")
set CreateCOMConnector = ComConnector
End Function
Function EnableConnections(ServerName, ClasterAdminName, ClasterAdminPass, InfoBasesAdminName, InfoBasesAdminPass, InfoBaseName)
EnableConnections = false
Set ComConnector = CreateCOMConnector() ' CreateObject("v82.COMConnector")
Set ServerAgent = ComConnector.ConnectAgent(sFullClusterName) 'ServerName)
Clasters = ServerAgent.GetClusters()
findClaster = false
For i = LBound(Clasters) To UBound(Clasters)
'If Claster.MainPort = KlasterPortNumber Then
Set Claster = Clasters(i)
if (UCase(Claster.HostName) = UCase(ServerName)) then
findClaster = true
Exit for
End if
Next
if findClaster = false then
Echo(CStr(Now) + " Îøèáêà - íå íàøëè êëàñòåð "+sFullClusterName) 'ServerName
Exit Function
end if
ServerAgent.Authenticate Claster, ClasterAdminName, ClasterAdminPass
'WorkingProcesses = ServerAgent.GetWorkingProcesses(Claster)
WorkServers = ServerAgent.GetWorkingServers(Claster)
For i = LBound(WorkServers) To UBound(WorkServers)
Set WorkServer = WorkServers(i)
Echo(CStr(Now) + " Îáðàáàòûâàþ ðàáî÷èé ñåðâåð "+WorkServer.Name+": " + WorkServer.HostName)
WorkingProcesses = ServerAgent.GetServerWorkingProcesses(Claster, WorkServer)
For j = LBound(WorkingProcesses) To UBound(WorkingProcesses)
If WorkingProcesses(j).Running = 1 Then
Set ConnectToWorkProcess = ComConnector.ConnectWorkingProcess("tcp://" + WorkingProcesses(j).HostName + ":" + CStr(WorkingProcesses(j).MainPort))
ConnectToWorkProcess.AuthenticateAdmin ClasterAdminName, ClasterAdminPass
ConnectToWorkProcess.AddAuthentication InfoBasesAdminName, InfoBasesAdminPass
' Ïîëó÷àåì ñïèñîê ÈÁ ðàáî÷åãî ïðîöåññà
InfoBases = ConnectToWorkProcess.GetInfoBases()
For h = LBound(InfoBases) To UBound(InfoBases)
If LCase(InfoBases(h).Name) = LCase(InfoBaseName) Then
Set InfoBase = InfoBases(h)
FindInfoBase = True
Exit For
End If
Next
If FindInfoBase Then
' Óñòàíàâëèâàåì ðàçðåøåíèå íà ïîäêëþ÷åíèå ñîåäèíåíèé
InfoBase.ConnectDenied = False
InfoBase.ScheduledJobsDenied = false
InfoBase.DeniedMessage = ""
InfoBase.PermissionCode = ""
ConnectToWorkProcess.UpdateInfoBase(InfoBase)
Exit For
End If
if not FindInfoBase then
Echo(CStr(Now) + " Îøèáêà - íå íàøëè áàçó äëÿ ñíÿòèÿ çàïðåòà íà ïîäêëþ÷åíèå ñîåäèíåíèé <"+InfoBaseName+">")
Exit Function
end if
End If
Next
Next
EnableConnections = true
End Function
Sub RestartAgent(TimeSleepShort)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
'Stop Service
strServiceName = "1C:Enterprise 8.2 Server Agent" ' "1C:Enterprise 8.1 Server Agent"
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StopService()
Echo(CStr(Now) + " " + CStr(objService.Name) + " Îñòàíîâêà ñëóæáû ñåðâåðà 1Ñ Ïðåäïðèÿòèÿ")
Next
WScript.Sleep TimeSleep
TerminateProcess "ragent.exe"
TerminateProcess "rmngr.exe"
TerminateProcess "rphost.exe"
WScript.Sleep TimeSleepShort
'Start Service
strServiceName = "1C:Enterprise 8.2 Server Agent" ' "1C:Enterprise 8.1 Server Agent"
'Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StartService()
Echo(CStr(Now) + " " + CStr(objService.Name) + " Çàïóñê ñëóæáû ñåðâåðà 1Ñ Ïðåäïðèÿòèÿ")
Next
WScript.Sleep TimeSleepShort
End Sub
Sub TerminateProcess(strProcessName)
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = '" & strProcessName & "'")
For Each objProcess in colProcess
objProcess.Terminate()
Echo(CStr(Now) + " " + CStr(objProcess.Name) + " Çàâåðøåíèå ïðîöåññà àãåíòà ñåðâåðà 1Ñ Ïðåäïðèÿòèÿ")
Next
End Sub
' Èíèöèàëèçàöèÿ ñöåíàðèÿ
Function Init( )
Init = false
set wshShell = wScript.createObject("wScript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")
' çàäàòü èìÿ ini-ôàéëà
Dim IniFileName
intOpMode = intParseCmdLine(IniFileName)
' âñåãäà îäèí ini-ôàéë â êàòàëîãå ïðîãðàììû
' IniFileName = Replace(LCase(WScript.ScriptFullName),".vbs",".ini")
Debug "IniFileName", IniFileName
if not GetDataFromIniFile(IniFileName, ResDict) then
Exit Function
end if
On Error Resume Next
Dim sDebugFlag
sDebugFlag = ResDict.Item(LCase("DebugFlag"))
Debug "sDebugFlag",sDebugFlag
if sDebugFlag<>"" then
DebugFlag = CBool(sDebugFlag)
end if
Debug "DebugFlag",DebugFlag
On Error Goto 0
'' ïîëó÷èòü ëîã-ôàéë
' LogFile = Null 'íå âûâîäèòü â ëîã-ôàéë, åñëè íå çàäàí ïóòü ê íåìó
' Dim sLogFile
' sLogFile = ResDict.Item(LCase("LogFile"))
' if sLogFile<>"" then
' If (NOT blnOpenFile(sLogFile, LogFile)) Then
' Call Wscript.Echo ("Íå ìîãó îòêðûòü ëîã-ôàéë <"+sLogFile+"> .")
' Exit Function
' End If
' End If
Init = true
End Function 'Init
Function GetFormatDay()
iDay = Day(Now)
mDay = CStr(Day(Now))
iMonth = Month(Now)
mMonth = CStr(Month(Now))
mYear = CStr(Year(Now))
nCDay = "_" + mYear + "_"
If iMonth < 10 Then
nCDay = nCDay + "0"
End If
nCDay = nCDay + mMonth + "_"
If iDay < 10 Then
nCDay = nCDay + "0"
End If
nCDay = nCDay + mDay
GetFormatDay = nCDay
End Function
' Ôóíêöèÿ äëÿ îïðåäåëåíèÿ ñâîáîäíîãî ìåñòà íà äèñêå
Function ShowFreeSpace(drvPath)
Dim d, s
on error Resume next
Set d = fso.GetDrive(fso.GetDriveName(drvPath))
s = "Drive " & UCase(drvPath) & " - "
s = s & d.VolumeName & " "
s = s & "Free Space: " & FormatNumber(d.FreeSpace/1024/1024, 0)
s = s & " Mbytes"
on error goto 0
ShowFreeSpace = s
End Function
' Ñêðèïò äëÿ çàòèðàíèÿ óñòàðåâøèõ ôàéëîâ:
' Óäàëÿåò òîëüêî ôàéëû ó êîòîðûõ ñõîäÿòñÿ ïðåôèêñû
Sub DelOldFiles(Folder_Name, Stack_Depth)
Set folder = fso.GetFolder(Folder_Name)
Set files = folder.Files
For Each f in files
fdate = f.DateCreated
fPrefix = Left(f.Name,Len(Prefix))
If ((Date - fdate) > Stack_Depth) And fPrefix = Prefix Then
f.Delete
End If
Next
End Sub
' ïîëó÷èòü äàííûå èç INI-ôàéëà
' ResDict - îáúåêò Dictionary, ãäå õðàíÿòñÿ ïàðû êëþ÷/çíà÷åíèå
Function GetDataFromIniFile(ByVal IniFileName, ByRef ResDict)
GetDataFromIniFile = false
' äàëåå àâòîìàòè÷åñêè
Dim IniFile 'As TextStream
On Error Resume Next
Dim ForRead
ForRead =1
Set IniFile = fso.OpenTextFile(IniFileName,ForRead)
if err.Number<>0 then
Err.Clear()
echo "Ini-ôàéë "& IniFileName &" íå óäàëîñü îòêðûòü!"
Exit Function
end if
on error goto 0
Set ResDict = CreateObject("Scripting.Dictionary")
Dim s, Matches, Match
Dim reg 'As RegExp
Set reg = new RegExp
reg.Pattern="^\s*([^=]+)\s*=\s*([^;']+)[;']?"
reg.IgnoreCase = True
Dim elem, index
Do While IniFile.AtEndOfStream <> True
s = IniFile.ReadLine
' åñëè íå ñòðîêà-êîììåíòàðèé
if not RegExpTest("^\s*[;']",s) then
' For index=0 To IniDict.Count-1
' reg.Pattern="\s*"+elem(index)+"\s*=\s*(.+)"
' âûäåëèòü êëþ÷ è çíà÷åíèå â Ini-ôàéëå, óáðàâ âîçìîæíûå êîììåíòàðèè
Set Matches = reg.Execute(s)
if Matches.Count>0 then
' äîáàâèòü íîâóþ ïàðó, èñêëþ÷èâ èç çíà÷åíèÿ òàáóëÿöèþ è ëåâûå(è ïðàâûå) ïðîáåëû
'ResDict.Add elem(index),Trim(replace(Matches(0).SubMatches(0),vbTab," "))
lkey = LCase(Trim(replace(Matches(0).SubMatches(0),vbTab," ")))
lvalue = replace(Matches(0).SubMatches(1), vbTab, " ")
lvalue = Trim(replace(lvalue, chr(34), "")) 'óáèðàþ êàâû÷êè
ResDict.Add lkey, lvalue
'ResDict.Add LCase(Trim(replace(Matches(0).SubMatches(0),vbTab," "))),Trim(replace(Matches(0).SubMatches(1),vbTab," "))
Debug "lkey=lvalue", lkey + " = [" + lvalue + "]"
end if
end if
Loop
IniFile.Close()
if ResDict.Count=0 then
echo "Íå óäàëîñü ïðî÷åñòü äàííûå èç Ini-ôàéëà " & IniFileName
GetDataFromIniFile = false
else
GetDataFromIniFile = true
end if
End Function 'GetDataFromIniFile
' ïðîâåðèòü íà ñîîòâåòñòâèå øàáëîíó
' ðåãèñòð ñèìâîëîâ íå âàæåí
Dim regExTest ' Create variable.
Function RegExpTest(ByVal patrn, ByVal strng)
if IsEmpty(regExTest) then
Set regExTest = New RegExp ' Create regular expression.
end if
regExTest.Pattern = patrn ' Set pattern.
regExTest.IgnoreCase = true ' disable case sensitivity.
RegExpTest = regExTest.Test(strng) ' Execute the search test.
' regEx = null
End Function
Function OpenLogFile()
Echo sLogFile
on error resume next
Set LogFile = fso.OpenTextFile(sLogFile, 8, True)
if err.Number<>0 then
err.Clear()
LogFile = nothing
OpenLogFile = false
on error goto 0
Exit Function
end if
on error goto 0
OpenLogFile = true 'set OpenLogFile = LogFile
End Function
Sub Echo(text)
WScript.Echo(text)
on error resume next
If IsObject(LogFile) then 'LogFile should be a file object
LogFile.WriteLine text
end if
on error goto 0
End Sub'Echo
Sub EchoWithOpenAndCloseLog(text)
OpenLogFile
Echo(text)
LogFile.Close()
LogFile = ""
End Sub'Echo
Sub Debug(ByVal title, ByVal msg)
'exit sub
on error resume next
DebugFlag = DebugFlag
if err.Number<>0 then
err.Clear()
on error goto 0
Exit Sub
end if
if DebugFlag then
if not (IsEmpty(msg) or IsNull(msg)) then
msg = CStr(msg)
end if
if not (IsEmpty(title) or IsNull(title)) then
title = CStr(title)
end if
If msg="" Then
Echo(title)
else
Echo(title+" - <"+msg+">")
End If
End If
on error goto 0
End Sub'Debug
Private Function intParseCmdLine( ByRef strFileName)
Dim strFlag 'intParseCmdLine
' ON ERROR RESUME NEXT
If Wscript.Arguments.Count > 0 Then
strFlag = Wscript.arguments.Item(0)
End If
If IsEmpty(strFlag) Then 'No arguments have been received
ShowUsage 'intParseCmdLine = CONST_SHOW_USAGE
Exit Function
End If
'Check if the user is asking for help or is just confused
If (strFlag="help") OR (strFlag="/h") OR (strFlag="\h") OR (strFlag="-h") _
OR (strFlag = "\?") OR (strFlag = "/?") OR (strFlag = "?") _
OR (strFlag="h") Then
ShowUsage 'intParseCmdLine = CONST_SHOW_USAGE
Exit Function
End If
intParseCmdLine = 0 'CONST_LIST
strFilename = strFlag
End Function
Sub ShowUsage ()
Wscript.Echo ""
' Wscript.Echo "Êîïèðóåò ôàéë íà äèñê A:. Òàì æå ñîçäàåòñÿ êîïèÿ ôàéëà."
Wscript.Echo "Âûïîëíÿåò àäìèíèñòðàòèâíûå äåéñòâèÿ ñ áàçîé 1Ñ 8.2"
Wscript.Echo ""
Wscript.Echo "ÏÀÐÀÌÅÒÐÛ ÂÛÇÎÂÀ:"
Wscript.Echo " "+ WScript.ScriptName +" [ôàéë-íàñòðîåê | /? | /h]"
Wscript.Echo ""
Wscript.Echo "ÏÐÈÌÅÐ:"
Wscript.Echo "1. cscript "+ WScript.ScriptName +" Ôàéë.ini"
Wscript.Echo "2. cscript "+ WScript.ScriptName
Wscript.Echo " Ïîêàçûâàåò ýòîò ýêðàí."
End Sub
'********************************************************************
'*
'* Function blnOpenFile
'*
'* Purpose: Opens a file.
'*
'* Input: strFileName A string with the name of the file.
'*
'* Output: Sets objOpenFile to a FileSystemObject and setis it to
'* Nothing upon Failure.
'*
'********************************************************************
Private Function blnOpenFile(ByVal strFileName, ByRef objOpenFile)
ON ERROR RESUME NEXT
If IsEmpty(strFileName) OR strFileName = "" Then
blnOpenFile = False
Set objOpenFile = Nothing
Exit Function
End If
'fso.DeleteFile(strFileName)
'Open the file for output
Set objOpenFile = fso.CreateTextFile(strFileName, True)
If blnErrorOccurred("Íåâîçìîæíî ñîçäàòü") Then
blnOpenFile = False
Set objOpenFile = Nothing
Exit Function
End If
blnOpenFile = True
End Function
'********************************************************************
'*
'* Sub VerifyHostIsCscript()
'*
'* Purpose: Determines which program is used to run this script.
'*
'* Input: None
'*
'* Output: If host is not cscript, then an error message is printed
'* and the script is aborted.
'*
'********************************************************************
Sub VerifyHostIsCscript()
ON ERROR RESUME NEXT
'Define constants
CONST CONST_ERROR = 0
CONST CONST_WSCRIPT = 1
CONST CONST_CSCRIPT = 2
Dim strFullName, strCommand, i, j, intStatus
strFullName = WScript.FullName
If Err.Number then
Call Echo( "Error 0x" & CStr(Hex(Err.Number)) & " occurred." )
If Err.Description <> "" Then
Call Echo( "Error description: " & Err.Description & "." )
End If
intStatus = CONST_ERROR
End If
i = InStr(1, strFullName, ".exe", 1)
If i = 0 Then
intStatus = CONST_ERROR
Else
j = InStrRev(strFullName, "\", i, 1)
If j = 0 Then
intStatus = CONST_ERROR
Else
strCommand = Mid(strFullName, j+1, i-j-1)
Select Case LCase(strCommand)
Case "cscript"
intStatus = CONST_CSCRIPT
Case "wscript"
intStatus = CONST_WSCRIPT
Case Else 'should never happen
Call Echo( "An unexpected program was used to " _
& "run this script." )
Call Echo( "Only CScript.Exe or WScript.Exe can " _
& "be used to run this script." )
intStatus = CONST_ERROR
End Select
End If
End If
If intStatus <> CONST_CSCRIPT Then
Call Echo( "Please run this script using CScript." & vbCRLF & _
"This can be achieved by" & vbCRLF & _
"1. Using ""CScript SystemAccount.vbs arguments"" for Windows 95/98 or" _
& vbCRLF & "2. Changing the default Windows Scripting Host " _
& "setting to CScript" & vbCRLF & " using ""CScript " _
& "//H:CScript //S"" and running the script using" & vbCRLF & _
" ""SystemAccount.vbs arguments"" for Windows NT/2000/XP." )
WScript.Quit(0)
End If
End Sub 'VerifyHostIsCscript