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
| '==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1
'
' NAME: Install Patches
'
' AUTHOR: Erik Kruijswijk
' DATE : 11-5-2004
'
'==========================================================================
Option Explicit
'On Error Resume Next
Dim wshShell, strAcc, strPass, strLogFile, strStatus, strLNC, strLNT, wshFSO, strCommand
strLogFile = "C:\installpatch.log"
Set wshShell = CreateObject("Wscript.Shell")
Set wshFSO = CreateObject("Scripting.FileSystemObject")
If wshFSO.FileExists(strLogFile) = False Then
WriteLog "Logfile was not found"
WriteLog "Creating StatusCounter in registry"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\StatusNummer", "0", "REG_SZ"
If Err.Number = 0 Then
WriteLog "StatusCounter created sucessfully"
Else
WriteLog "Error --: " & Err.Description
End If
strStatus = "0"
Else
WriteLog "Logfile was found. Resuming script."
strStatus = wshShell.RegRead ("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\StatusNummer")
End If
Select Case strStatus
Case "0"
WriteLog "---"
WriteLog "Starting FASE 0"
WriteLog "---"
WriteLog "Starting FASE 0 from script on " & Now()
' Definieer het installer account dat wordt gebruikt
strAcc = InputBox ("Account","What's the account?")
WriteLog "Account Used: " & strAcc
strPass = InputBox ("Password","What's the password?")
WriteLog "Password given end's with: " & right(strPass,3)
' Zet deze gegevens in het register
' LegalNotice wordt tijdenlijk uitgezet, voor de admin logon
WriteLog "Gegevens worden in het register geplaatst"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon", "1", "REG_SZ"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName", strAcc, "REG_SZ"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword", strPass, "REG_SZ"
wshShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\LegalNoticeCaption"
wshShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\LegalNoticeText"
wshShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeCaption"
wshShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeText"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\InstallPatches", "C:\InstallPatches.vbs", "REG_SZ"
If Err.Number = 0 Then
WriteLog "Gegevens zijn succesvol in het register geplaatst"
Else
WriteLog "Error --: " & Err.Description
End If
' Installing Service Pack 4 for Windows 2000
WriteLog "Installing Service Pack 4"
'strCommand = "C:\W2KSP4_EN.exe -z -q"
'wshShell.Run strCommand, 3, True
MsgBox "Hier komt een patch te draaien", 64
If Err.Number = 0 Then
WriteLog "Done installing Service Pack 4"
Else
WriteLog "Error --: " & Err.Description
End If
WriteLog "Going to status 1"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\StatusNummer", "1", "REG_SZ"
WriteLog "End FASE 0"
WriteLog "Rebooting"
Opsys "REBOOT", True, True
Case "1"
WriteLog "---"
WriteLog "Starting FASE 1"
WriteLog "---"
MsgBox "Hier komt een patch te draaien", 64
WriteLog "Going to status 2"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\StatusNummer", "2", "REG_SZ"
WriteLog "Rebooting"
Opsys "REBOOT", True, True
Case "2"
WriteLog "---"
WriteLog "Starting FASE 2"
WriteLog "---"
strLNC = "Warning !! - Waarschuwing !!"
strLNT = "Unauthorized Access is prohibited !! - Ongeautoriseerde toegang is verboden !!"
strAcc = ""
strPass = ""
' Zet deze gegevens in het register
WriteLog "Gegevens worden in het register geplaatst"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon", "0", "REG_SZ"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName", "", "REG_SZ"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword", "", "REG_SZ"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\LegalNoticeCaption", strLNC, "REG_SZ"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\LegalNoticeText", strLNT, "REG_SZ"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DontDisplayLastUsername", "1", "REG_DWORD"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeCaption", strLNC, "REG_SZ"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeText", strLNT, "REG_SZ"
wshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\DontDisplayLastUsername", "1", "REG_DWORD"
wshShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\InstallPatches"
wshShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\StatusNummer"
If Err.Number = 0 Then
WriteLog "Gegevens zijn succesvol in het register geplaatst"
Else
WriteLog "Error--: " & Err.Description
End If
MsgBox "Ready",64,"All patches installed"
End Select
' End script
Function WriteLog(ByVal strLog)
Dim Logging
Set wshFSO = CreateObject("Scripting.FileSystemObject")
If Not wshFSO.FileExists(strLogFile) Then
wshFSO.CreateTextFile (strLogFile)
End If
Set Logging = wshFSO.OpenTextFile (strLogFile,8)
Logging.Write (strLog & vbCrLf)
Logging.Close
Set wshFSO = Nothing
End Function
Function OpSys(ByVal strControl, _
ByVal blnForce, _
ByVal blnForceIfHung)
'** This function offers a way to shut the computer down. The following
'** options for strControl are supported:
'** Logoff: Logs off the current user (0x0).
'** Shutdown: Shuts down the machine (0x1).
'** Reboot: Reboots the machine (0x2).
'** PowerOff: Powers down the machine (0x8).
'**
'** blnForce
'** Force: Forces a logoff, shutdown, or reboot, even if the user has
'** unsaved work (0x4).
'**
'** blnForceIfHung
'** Force If Hung: Forces a logoff, shutdown, or reboot, even if the
'** software currently running has hung and does not support to an End Task
'** request (0x10).
WriteLog "Function OpSys(""" & strControl & """, " & blnForce & ", " & blnForceIfHung & ")"
Dim objLocator
Dim objService
Dim objEnumerator
Dim objInstance
Dim strMachine
Dim intControl
strMachine = "localhost"
'** Check to see if both blnForce and blnForceIfHung are set to True.
If blnForce = True And blnForceIfHung = True Then
WriteLog "Both blnForce and blnForceIfHung are set to True. Because blnForceIfung overrules blnForce, blnForce will be set to False."
'** blnForceIfHung overrules blnForce, so it will be disabled.
blnForce = False
End If
Select Case UCase(strControl)
Case "LOGOFF"
intControl = 0
Case "SHUTDOWN"
intControl = 1
Case "REBOOT"
intControl = 2
Case "POWEROFF"
intControl = 8
Case Else
WriteLog "Error: Invalid option '" & strControl & "' specified. Option must be one of: LogOff, ShutDown, Reboot, or PowerOff."
Exit Function
End Select
If blnForce = True Then intControl = intControl + 4
If blnForceIfHung = True Then intControl = intControl + 16
On Error Resume Next
Set objLocator = WScript.CreateObject("WbemScripting.SWbemLocator")
Set objService = objLocator.ConnectServer(strMachine, "root\cimv2")
objService.Security_.impersonationlevel = Impersonate
objService.Security_.Privileges.AddAsString("SeShutdownPrivilege")
WriteLog "Attempting to reboot computer '" & strMachine & "' with control code (" & CStr(intControl) & ")."
Set objEnumerator = objService.ExecQuery("Select * From Win32_OperatingSystem")
For Each objInstance In objEnumerator
objInstance.Win32Shutdown(intControl)
Next
On Error GoTo 0
OpSys = True
Set objLocator = Nothing
Set objService = Nothing
Set objEnumerator = Nothing
WriteLog "End Function OpSys. Returning: '" & OpSys & "'."
End Function |