| 1 | ' Const |
|---|
| 2 | Const ForAppending = 8 |
|---|
| 3 | Const TristateMixed = -2 |
|---|
| 4 | Const TristateTrue = -1 |
|---|
| 5 | Const TristateFalse = 0 |
|---|
| 6 | Const ForReading = 1 |
|---|
| 7 | Const ForWriting = 2 |
|---|
| 8 | ' EndConst |
|---|
| 9 | |
|---|
| 10 | ' Region Description |
|---|
| 11 | ' |
|---|
| 12 | ' License: GPL |
|---|
| 13 | ' Copyright: (c) 2008 - 2020 Thomas Borger ESG |
|---|
| 14 | ' Name: NSClientUpdate |
|---|
| 15 | ' Author: Thomas Borger |
|---|
| 16 | ' Version: 0.4.0 |
|---|
| 17 | ' Description: deploy new Versions of NSClient to all Windows Servers |
|---|
| 18 | ' |
|---|
| 19 | ' - check if exists and running a prior version of NSClient on the system |
|---|
| 20 | ' - stop the service |
|---|
| 21 | ' - rename the folder which hostes the old version |
|---|
| 22 | ' - get alle files and folder of new version from network share |
|---|
| 23 | ' - install the new version |
|---|
| 24 | ' - copy nsclient.ini from prior version folder to new version folder |
|---|
| 25 | ' - start the new version service |
|---|
| 26 | ' - print all actions and results to a logfile on server share |
|---|
| 27 | |
|---|
| 28 | ' REQUIREMENTS: |
|---|
| 29 | ' The script needs on the remote server share which stored the new NSClient++ Versions the following |
|---|
| 30 | ' structure: |
|---|
| 31 | ' ..\NSClient++ |
|---|
| 32 | ' ..\NSClient++\32 --> Win32 Version from NSClient++ (unpacked ZIP archive) |
|---|
| 33 | ' ..\NSClient++\64 --> X64 Versiob from NSClient++ (unpacked ZIP archive) |
|---|
| 34 | ' ..\NSClient++\log --> folder where the installation logfiles from each server is stored. |
|---|
| 35 | |
|---|
| 36 | ' SYNTAX: nsclient_update.vbs /S:[ServerShare] /c:[config file] |
|---|
| 37 | ' nsclient_update.vbs /S:\\server6\download\Nagios /c:\\server6\download\Nagios\servers.txt |
|---|
| 38 | |
|---|
| 39 | ' with psexec: |
|---|
| 40 | ' psexec \\[server] -u DOMAIN\admin -p ***** cscript //nologo /S:\\downloadserver\Nagios\NSClient++ /c:\\downloadserver\Nagios\NSClient++\servers.txt |
|---|
| 41 | |
|---|
| 42 | ' with psexec and more than one server |
|---|
| 43 | ' psexec @c:\tmp\serverlist.txt -u DOMAIN\admin -p ***** cscript //nologo /S:\\downloadserver\Nagios\NSClient++ /c:\\downloadserver\Nagios\NSClient++\servers.txt |
|---|
| 44 | |
|---|
| 45 | ' complete description see: http://www.nsclient.org/nscp/wiki/RemoteVBS |
|---|
| 46 | |
|---|
| 47 | ' WHERE OPTION: |
|---|
| 48 | ' /S: server share wich stores the new NSClient version unpacked zip archiv |
|---|
| 49 | ' /c: full path and name of configuration file which is used to handle client requirements |
|---|
| 50 | ' |
|---|
| 51 | ' The Options are case sensitive |
|---|
| 52 | ' EndRegion |
|---|
| 53 | |
|---|
| 54 | 'Initialize |
|---|
| 55 | Set wshshell = CreateObject("WScript.Shell") |
|---|
| 56 | Set WshNetwork = WScript.CreateObject("WScript.Network") |
|---|
| 57 | Set fso = CreateObject("Scripting.FileSystemObject") |
|---|
| 58 | Dim strProgramFiles, strServerLogFile, strHostName, strServerShare, strToDo |
|---|
| 59 | Dim hostNameMatch, zline |
|---|
| 60 | hostNameMatch = False |
|---|
| 61 | Dim cfHOST(), cfINI(), cfSCRIPT(), cfLW(), cfmyFOLDER() |
|---|
| 62 | strToDo = "new" |
|---|
| 63 | |
|---|
| 64 | On Error Resume Next |
|---|
| 65 | '############# PRE Checking ################ |
|---|
| 66 | 'check all Arguments |
|---|
| 67 | Set argsNamed = WScript.Arguments.Named |
|---|
| 68 | If Err.number <> 0 Then |
|---|
| 69 | WScript.Echo "* ERROR: could not get arguments " & Err.Description |
|---|
| 70 | wshshell.LogEvent 2, "ERROR: could not get arguments" & vbNewLine & Err.Description |
|---|
| 71 | WScript.Quit 1 |
|---|
| 72 | End If |
|---|
| 73 | If argsNamed.Count <= 1 Then |
|---|
| 74 | WScript.Echo "* ERROR: insufficient arguments" |
|---|
| 75 | wshshell.LogEvent 2, "insufficient arguments!" |
|---|
| 76 | WScript.Quit 2 |
|---|
| 77 | End If |
|---|
| 78 | |
|---|
| 79 | For i = 0 To argsNamed.Count - 1 |
|---|
| 80 | If argsNamed.Exists ("c") = vbFalse Then |
|---|
| 81 | WScript.Echo "* ERROR: argument /c: is missing - ConfigFile" |
|---|
| 82 | wshshell.LogEvent 2, "ERROR: argument /c: is missing - ConfigFile" |
|---|
| 83 | WScript.Quit 3 |
|---|
| 84 | Else |
|---|
| 85 | configFile = argsNamed.Item("c") |
|---|
| 86 | End If |
|---|
| 87 | If argsNamed.Exists ("S") = vbFalse Then |
|---|
| 88 | WScript.Echo "* ERROR: argument /S: is missing - Server share where can find the new NSClient++ version" |
|---|
| 89 | wshshell.LogEvent 2, "ERROR: argument /S: is missing - Server share where can find the new NSClient++ version" |
|---|
| 90 | WScript.Quit 4 |
|---|
| 91 | Else |
|---|
| 92 | strServerShare = argsNamed.Item("S") |
|---|
| 93 | End If |
|---|
| 94 | Next |
|---|
| 95 | |
|---|
| 96 | 'check if NSClient folder and config file are valid |
|---|
| 97 | If fso.FolderExists(strServerShare) = vbFalse Then |
|---|
| 98 | WScript.Echo "* ERROR: " & strServerShare & " is not a valid folder" & vbNewLine & Err.Description |
|---|
| 99 | wshshell.LogEvent 2, "ERROR: " & strServerShare & " is not a valid folder" & vbNewLine & Err.Description |
|---|
| 100 | WScript.Quit 5 |
|---|
| 101 | End If |
|---|
| 102 | If fso.FileExists(configFile) = vbFalse Then |
|---|
| 103 | WScript.Echo "* ERROR: " & configFile & " is not a valid file" & vbNewLine & Err.Description |
|---|
| 104 | wshshell.LogEvent 2, "ERROR: " & configFile & " is not a valid file" & vbNewLine & Err.Description |
|---|
| 105 | WScript.Quit 6 |
|---|
| 106 | End If |
|---|
| 107 | |
|---|
| 108 | 'get hostname |
|---|
| 109 | strHostName = UCase(WshNetwork.ComputerName) |
|---|
| 110 | If Len(strHostName) = 0 Then |
|---|
| 111 | WScript.Quit "* ERROR: could not get hostname " & Err.Description |
|---|
| 112 | wshshell.LogEvent 2, "could not get HostName" & Err.Description |
|---|
| 113 | WScript.Quit 7 |
|---|
| 114 | Else |
|---|
| 115 | WScript.Echo "* hostname is: " & strHostName |
|---|
| 116 | End If |
|---|
| 117 | |
|---|
| 118 | Err.Clear |
|---|
| 119 | 'initialize the service state within windows wmi |
|---|
| 120 | Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strHostName & "\root\cimv2") |
|---|
| 121 | If Err.number <> 0 Then |
|---|
| 122 | WScript.Echo "* ERROR: could not initialize WMIObject " & Err.Description |
|---|
| 123 | wshshell.LogEvent 2, "ERROR: could not initialize WMIObject " & Err.Description |
|---|
| 124 | WScript.Quit 8 |
|---|
| 125 | End If |
|---|
| 126 | |
|---|
| 127 | 'define TEMP folder and file for writing version information and create the still empty file |
|---|
| 128 | Err.Clear |
|---|
| 129 | Set objPROCESS = wshshell.Environment ("PROCESS") |
|---|
| 130 | myTEMP = objPROCESS("TEMP") |
|---|
| 131 | If Err.number <> 0 Then |
|---|
| 132 | WScript.Echo "* ERROR: couldn't get TEMP environment for this system" |
|---|
| 133 | WScript.Quit 9 |
|---|
| 134 | Else |
|---|
| 135 | myTEMPVersion = myTEMP & "\NSClientVersionen.txt" |
|---|
| 136 | myTEMPNSClientOutP = myTEMP & "\NSClient_install.log" |
|---|
| 137 | End If |
|---|
| 138 | myCPUType = objPROCESS("PROCESSOR_ARCHITECTURE") |
|---|
| 139 | If InStr(1, myCPUType, "x86") > 0 Then |
|---|
| 140 | myCPUSubFolder = "32" |
|---|
| 141 | WScript.Echo "* CPU-Type: " & myCPUType |
|---|
| 142 | ElseIf InStr(1, myCPUType, "64") > 0 Then |
|---|
| 143 | myCPUSubFolder = "64" |
|---|
| 144 | WScript.Echo "* CPU-Type: " & myCPUType |
|---|
| 145 | Else |
|---|
| 146 | WScript.Echo "* ERROR: unknown CPU Type: " & myCPUType |
|---|
| 147 | wshshell.LogEvent 2, "* ERROR: unknown CPU Type: " & myCPUType |
|---|
| 148 | WScript.Quit 10 |
|---|
| 149 | End If |
|---|
| 150 | |
|---|
| 151 | 'get the folder name from %ProgramFiles% |
|---|
| 152 | strProgramFiles = wshshell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\ProgramFilesDir") |
|---|
| 153 | If Len(strProgramFiles) = 0 Or Err.number <> 0 Then |
|---|
| 154 | WScript.Echo "* ERROR: could not get current ProgramFiles " & Err.Description |
|---|
| 155 | wshshell.LogEvent 2, " - ERROR: could not get current ProgramFiles " & Err.Description |
|---|
| 156 | WScript.Quit 11 |
|---|
| 157 | Else |
|---|
| 158 | strProgramFiles = strProgramFiles & "\NSClient++" |
|---|
| 159 | End If |
|---|
| 160 | |
|---|
| 161 | ' Date for Logfile Name |
|---|
| 162 | y = CStr(Year(Now())) |
|---|
| 163 | mo = CStr(Month(Now())) |
|---|
| 164 | if len(mo) = 1 then mo = "0" + mo |
|---|
| 165 | d = CStr(Day(Now())) |
|---|
| 166 | if len(d) = 1 then d = "0" + d |
|---|
| 167 | h = CStr(Hour(Now())) |
|---|
| 168 | if len(h) = 1 then h = "0" + h |
|---|
| 169 | m = CStr(Minute(Now())) |
|---|
| 170 | if len(m) = 1 then m = "0" + m |
|---|
| 171 | |
|---|
| 172 | 'get Registry Keys for a installed NSClient++ |
|---|
| 173 | Err.Clear |
|---|
| 174 | ImagePath = wshshell.RegRead ("HKLM\SYSTEM\CurrentControlSet\Services\NSClientpp\ImagePath") |
|---|
| 175 | If Err.number <> 0 Then |
|---|
| 176 | WScript.Echo "* " & Err.Description |
|---|
| 177 | WScript.Echo "* perhaps a new installation?" |
|---|
| 178 | Else |
|---|
| 179 | Set objInstalledDir = fso.GetFile(ImagePath) |
|---|
| 180 | InstalledDir = objInstalledDir.ParentFolder |
|---|
| 181 | WScript.Echo "* NSClient++ is installed on: " & InstalledDir |
|---|
| 182 | |
|---|
| 183 | Err.Clear |
|---|
| 184 | DisplayName = wshshell.RegRead ("HKLM\SYSTEM\CurrentControlSet\Services\NSClientpp\DisplayName") |
|---|
| 185 | If Err.number <> 0 Then |
|---|
| 186 | If Len(DisplayName) = 0 Then |
|---|
| 187 | WScript.Echo "* HKLM\SYSTEM\CurrentControlSet\Services\NSClientpp\DisplayName is empty" |
|---|
| 188 | End If |
|---|
| 189 | Else |
|---|
| 190 | oldVersions = Split(DisplayName, " ") |
|---|
| 191 | oldVersion = oldVersions(2) |
|---|
| 192 | oldReleaseDate = oldVersions(3) |
|---|
| 193 | oldPlattform = oldVersions(4) |
|---|
| 194 | End If |
|---|
| 195 | End If |
|---|
| 196 | |
|---|
| 197 | 'folder definition |
|---|
| 198 | strServerRepo = strServerShare & "\log" |
|---|
| 199 | strServerInstDir = strServerShare & "\" & myCPUSubFolder |
|---|
| 200 | |
|---|
| 201 | 'get the version string from NSClient++ version which to be installed. |
|---|
| 202 | fso.CopyFile strServerInstDir & "\NSClient++.exe", myTEMP & "\" |
|---|
| 203 | If fso.FileExists (myTEMP & "\NSClient++.exe") = vbFalse Then |
|---|
| 204 | WScript.Echo "* ERROR: couldn't copy remote NSClient++.exe to " & myTEMP & " " & Err.Description |
|---|
| 205 | WScript.Quit 12 |
|---|
| 206 | Else |
|---|
| 207 | rcCMD = wshshell.Run("cmd /c " & myTEMP & "\nsclient++.exe -version > " & myTEMPVersion, 0, 1) |
|---|
| 208 | If fso.FileExists (myTEMPVersion) = vbFalse Then |
|---|
| 209 | WScript.Echo "* ERROR: could not get version information from: " & strServerInstDir & "\nsclient++.exe" |
|---|
| 210 | wshshell.LogEvent 2, "ERROR: " & "could not get version information from: " & strServerInstDir & "\nsclient++.exe" |
|---|
| 211 | WScript.Quit 13 |
|---|
| 212 | Else |
|---|
| 213 | 'open version file and read one line |
|---|
| 214 | WScript.Sleep 500 |
|---|
| 215 | Err.Clear |
|---|
| 216 | Set vFile = fso.OpenTextFile (myTEMPVersion, ForReading , vbFalse , TristateMixed ) |
|---|
| 217 | If Err.number <> 0 Then |
|---|
| 218 | WScript.Echo "* ERROR: could not open: " & myTEMPVersion & " for reading " & Err.Description |
|---|
| 219 | wshshell.LogEvent 2, "ERROR: could not open: " & myTEMPVersion & " for reading " & Err.Description |
|---|
| 220 | WScript.Quit 14 |
|---|
| 221 | Else |
|---|
| 222 | newVersions = Split(vFile.ReadLine, " ") |
|---|
| 223 | newVersion = newVersions(4) |
|---|
| 224 | newReleaseDate = Mid(newVersions(5),1,Len(newVersions(5)) - 1) |
|---|
| 225 | newPlattform = newVersions(7) |
|---|
| 226 | End If |
|---|
| 227 | vFile.Close |
|---|
| 228 | 'delete tmp file |
|---|
| 229 | fso.DeleteFile myTEMPVersion, vbTrue |
|---|
| 230 | If Err.number <> 0 Then |
|---|
| 231 | WScript.Echo "* ERROR: could not delete file: " & myTEMPVersion & " " & Err.Description |
|---|
| 232 | End If |
|---|
| 233 | Set vFile = Nothing |
|---|
| 234 | 'delete tmp nsclient file |
|---|
| 235 | Err.Clear |
|---|
| 236 | fso.DeleteFile myTEMP & "\NSClient++.exe", vbTrue |
|---|
| 237 | If Err.number <> 0 Then |
|---|
| 238 | WScript.Echo "* ERROR: couldn't delete " & myTEMP & "\NSClient++.exe" |
|---|
| 239 | End If |
|---|
| 240 | End If |
|---|
| 241 | End If |
|---|
| 242 | |
|---|
| 243 | 'open the Logfile for each client on the server |
|---|
| 244 | strServerLogFile = strServerRepo & "\" & y & "_" & mo & "_" & d & "_" & h & m & "-" & strHostName & ".log" |
|---|
| 245 | Set LogFile = fso.CreateTextFile(strServerLogFile, vbTrue, vbTrue) |
|---|
| 246 | If Err.number <> 0 Then |
|---|
| 247 | WScript.Echo "* ERROR: could not write to server logfile: " & strServerLogFile & vbNewLine & Err.Description |
|---|
| 248 | wshshell.LogEvent 1, "ERROR: could not write to server logfile: " & strServerLogFile & vbNewLine & Err.Description |
|---|
| 249 | WScript.Quit 15 |
|---|
| 250 | End If |
|---|
| 251 | |
|---|
| 252 | 'start writing the client logfile on server |
|---|
| 253 | LogFile.WriteLine String(20, "*") & " START NSClient Update Version " & version & " " & String(20, "*") & vbNewLine |
|---|
| 254 | |
|---|
| 255 | 'parse the configFile for independent settings |
|---|
| 256 | Err.Clear |
|---|
| 257 | Set cF = fso.OpenTextFile(configFile, ForReading, vbFalse, TristateMixed) |
|---|
| 258 | If Err.number <> 0 Then |
|---|
| 259 | WScript.Echo "* ERROR: could not open config file: " & configFile |
|---|
| 260 | LogFile.WriteLine Now & " - ERROR: could not open config file: " & configFile |
|---|
| 261 | LogFile.Close |
|---|
| 262 | WScript.Quit 16 |
|---|
| 263 | Else |
|---|
| 264 | 'skip the first 16 lines in config file |
|---|
| 265 | For i = 0 To 17 |
|---|
| 266 | cF.SkipLine |
|---|
| 267 | Next |
|---|
| 268 | zline = 0 |
|---|
| 269 | Do Until cF.AtEndOfStream |
|---|
| 270 | ReDim Preserve cfHOST(zline) |
|---|
| 271 | ReDim Preserve cfSCRIPT(zline) |
|---|
| 272 | ReDim Preserve cfINI(zline) |
|---|
| 273 | ReDim Preserve cfmyFOLDER(zline) |
|---|
| 274 | line = cF.ReadLine |
|---|
| 275 | |
|---|
| 276 | if len(line) = 0 then Exit Do |
|---|
| 277 | |
|---|
| 278 | cfParams = Split(line,"|") |
|---|
| 279 | cfHOST(zline) = UCase(cfParams(0)) |
|---|
| 280 | cfINI(zline) = cfParams(1) |
|---|
| 281 | cfSCRIPT(zline) = cfParams(2) |
|---|
| 282 | cfmyFOLDER(zline) = cfParams(3) |
|---|
| 283 | 'check if hostname in config file matches this host? |
|---|
| 284 | If strHostName = UCase(cfParams(0)) then hostNameMatch = True |
|---|
| 285 | zline = zline + 1 |
|---|
| 286 | Loop |
|---|
| 287 | cF.Close |
|---|
| 288 | Set cF = Nothing |
|---|
| 289 | End If |
|---|
| 290 | |
|---|
| 291 | 'if client hostname does not match one of config file --> cancel installation |
|---|
| 292 | If hostNameMatch = False Then |
|---|
| 293 | WScript.Echo "* ERROR: hostname does not match any line in config file" |
|---|
| 294 | LogFile.WriteLine Now & " - ERROR: hostname does not match any line in config file" |
|---|
| 295 | LogFile.Close |
|---|
| 296 | WScript.Quit 17 |
|---|
| 297 | End If |
|---|
| 298 | |
|---|
| 299 | 'set the client specific values for NSC.ini and script folder |
|---|
| 300 | For i = LBound(cfHOST) To UBound(cfHOST) |
|---|
| 301 | If cfHOST(i) = strHostName Then |
|---|
| 302 | myINI = cfINI(i) |
|---|
| 303 | mySCRIPT = cfSCRIPT(i) |
|---|
| 304 | myInstFolder = cfmyFOLDER(i) |
|---|
| 305 | End If |
|---|
| 306 | Next |
|---|
| 307 | |
|---|
| 308 | ' check if NSClient in prior version is installed |
|---|
| 309 | If fso.FileExists(ImagePath) = vbTrue Then |
|---|
| 310 | strToDo = "update" |
|---|
| 311 | |
|---|
| 312 | 'see if InstalledDir <> myInstFolder |
|---|
| 313 | If Not IsEmpty(myInstFolder) Then |
|---|
| 314 | myLW = Mid(myInstFolder,1,1) |
|---|
| 315 | If fso.DriveExists(myLW) = vbFalse Then |
|---|
| 316 | WScript.Echo "* ERROR: Drive " & myLW & " doesn't exists!" |
|---|
| 317 | LogFile.WriteLine Now & " - ERROR: Drive " & myLW & " doesn't exists!" |
|---|
| 318 | LogFile.Close |
|---|
| 319 | WScript.Quit 18 |
|---|
| 320 | End If |
|---|
| 321 | strProgramFiles = myInstFolder 'overwrite strProgramFiles |
|---|
| 322 | End If |
|---|
| 323 | |
|---|
| 324 | 'plattform check |
|---|
| 325 | If IsEmpty(oldPlattform) Then |
|---|
| 326 | WScript.Echo "* WARNING: could not get Plattform information. Perhaps very old NSClient version?" |
|---|
| 327 | LogFile.WriteLine Now & " - WARNING: could not get Plattform information. Perhaps very old NSClient version?" |
|---|
| 328 | Else |
|---|
| 329 | If oldPlattform <> newPlattform Then |
|---|
| 330 | WScript.Echo "* ERROR: " & oldPlattform & " is not equal " & newPlattform |
|---|
| 331 | LogFile.WriteLine Now & " - ERROR: " & oldPlattform & " Is Not equal " & newPlattform |
|---|
| 332 | LogFile.Close |
|---|
| 333 | WScript.Quit 19 |
|---|
| 334 | End If |
|---|
| 335 | End If |
|---|
| 336 | |
|---|
| 337 | 'Version check |
|---|
| 338 | If newVersion = oldVersion And oldReleaseDate = newReleaseDate Then |
|---|
| 339 | strToDo = "up2date" |
|---|
| 340 | Else |
|---|
| 341 | strToDo = "update" |
|---|
| 342 | End If |
|---|
| 343 | |
|---|
| 344 | Else |
|---|
| 345 | |
|---|
| 346 | strToDo = "new" |
|---|
| 347 | 'check if the target install folder is other than %programfiles% |
|---|
| 348 | If Not IsEmpty(myInstFolder) Then |
|---|
| 349 | myLW = Mid(myInstFolder,1,1) |
|---|
| 350 | If fso.DriveExists(myLW) = vbFalse Then |
|---|
| 351 | WScript.Echo "* ERROR: Drive " & myLW & " doesn't exists!" |
|---|
| 352 | LogFile.WriteLine Now & " - ERROR: Drive " & myLW & " doesn't exists!" |
|---|
| 353 | LogFile.Close |
|---|
| 354 | WScript.Quit 20 |
|---|
| 355 | End If |
|---|
| 356 | strProgramFiles = myInstFolder 'overwrite strProgramFiles |
|---|
| 357 | End If |
|---|
| 358 | |
|---|
| 359 | End If |
|---|
| 360 | |
|---|
| 361 | ' ################################################# |
|---|
| 362 | |
|---|
| 363 | ' ############# Install/Remove/Rename/Copy SECTION ######## |
|---|
| 364 | Select Case strToDo |
|---|
| 365 | |
|---|
| 366 | Case "update" |
|---|
| 367 | |
|---|
| 368 | 'print out Info |
|---|
| 369 | WScript.Echo "* GOAL is update NSClient++ from " & InstalledDir & " to: " & strProgramFiles |
|---|
| 370 | LogFile.WriteLine Now & " - GOAL is update NSClient++ from " & InstalledDir & " to: " & strProgramFiles |
|---|
| 371 | |
|---|
| 372 | 'stop Service |
|---|
| 373 | Set svc_nsclientpp = objWMIService.Get("Win32_Service.Name='NSClientpp'") |
|---|
| 374 | svc_state = svc_nsclientpp.State |
|---|
| 375 | If Err.number <> 0 Then |
|---|
| 376 | svc_error_nr = Err.number |
|---|
| 377 | WScript.Echo "* ERROR: couldn't get WMI service state from NSClient++ " & Err.Description |
|---|
| 378 | LogFile.WriteLine Now & " - ERROR: could not get WMI service state from NSClient++ " & Err.Description |
|---|
| 379 | |
|---|
| 380 | 'try to stop service with "net stop" |
|---|
| 381 | rcCMD = wshshell.Run("cmd /c net stop nsclientpp", 0, 1) |
|---|
| 382 | If rcCMD = 0 Then |
|---|
| 383 | WScript.Echo "* service state from NSClientpp is UNKNOWN, but stopped successfully with 'net stop'" |
|---|
| 384 | LogFile.WriteLine Now & " - service state from NSClientpp is UNKNOWN, but stopped successfully with 'net stop'" |
|---|
| 385 | Else |
|---|
| 386 | WScript.Echo "* couldn't stop nsclientpp through 'net stop'" |
|---|
| 387 | LogFile.WriteLine Now & "* couldn't stop nsclientpp through 'net stop'" |
|---|
| 388 | WScript.Quit 20 |
|---|
| 389 | End If |
|---|
| 390 | Else |
|---|
| 391 | WScript.Echo "* service NSClientpp is in state: " & svc_state |
|---|
| 392 | LogFile.WriteLine Now & " - service: NSClientpp is in state: " & svc_state |
|---|
| 393 | End If |
|---|
| 394 | |
|---|
| 395 | If svc_state = "Running" Then |
|---|
| 396 | svc_nsclientpp.Stopservice() |
|---|
| 397 | WScript.Sleep 3000 |
|---|
| 398 | |
|---|
| 399 | Set svc_nsclientpp = objWMIService.Get("Win32_Service.Name='NSClientpp'") |
|---|
| 400 | svc_state = svc_nsclientpp.State |
|---|
| 401 | If svc_state = "Stopped" Then |
|---|
| 402 | WScript.Echo "* service: NSClientpp successfully stopped" |
|---|
| 403 | LogFile.WriteLine Now & " - Service nsclientpp successfully stoped" |
|---|
| 404 | Else |
|---|
| 405 | WScript.Echo "* ERROR: service NSClientpp couldn't stop" |
|---|
| 406 | LogFile.WriteLine Now & " - ERROR: Service nsclientpp could not stopped" |
|---|
| 407 | LogFile.Close |
|---|
| 408 | WScript.Quit 21 |
|---|
| 409 | End If |
|---|
| 410 | End If |
|---|
| 411 | |
|---|
| 412 | 'uninstall old version |
|---|
| 413 | rcCMD = wshshell.Run("cmd /c " & Chr(34) & ImagePath & Chr(34) & " /uninstall", 0, 1) |
|---|
| 414 | WScript.Sleep 500 |
|---|
| 415 | RegNSClientpp = wshshell.RegRead ("HKLM\SYSTEM\CurrentControlSet\Services\NSClientpp\") |
|---|
| 416 | If IsEmpty(RegNSClientpp) Then |
|---|
| 417 | WScript.Echo "* NSClient++ successfully uninstalled" |
|---|
| 418 | LogFile.WriteLine Now & " - NSClient++ successfully uninstalled" |
|---|
| 419 | Else |
|---|
| 420 | WScript.Echo "* ERROR: couldn't uninstall NSClient++" |
|---|
| 421 | LogFile.WriteLine Now & " - ERROR: could not uninstall NSClient++" |
|---|
| 422 | If svc_error_nr = -2147217406 Then |
|---|
| 423 | WScript.Echo "* ERROR: NSClient++ isn't installed here" |
|---|
| 424 | LogFile.WriteLine Now & " - ERROR: service NSClientpp is not installed here" |
|---|
| 425 | End If |
|---|
| 426 | LogFile.Close |
|---|
| 427 | WScript.Quit 22 |
|---|
| 428 | End If |
|---|
| 429 | |
|---|
| 430 | 'rename the current folder where NSClient++ was installed |
|---|
| 431 | Err.Clear |
|---|
| 432 | fso.MoveFolder InstalledDir, InstalledDir & "_" & oldVersion |
|---|
| 433 | If Err.number <> 0 Then |
|---|
| 434 | WScript.Echo "* ERROR: couldn't rename folder: " & InstalledDir & " " & Err.Description |
|---|
| 435 | LogFile.WriteLine Now & " - ERROR: could not rename folder: " & InstalledDir & " " & Err.Description |
|---|
| 436 | LogFile.Close |
|---|
| 437 | WScript.Quit 23 |
|---|
| 438 | Else |
|---|
| 439 | WScript.Echo "* folder: " & InstalledDir & " renamed to: " & InstalledDir & "_" & oldVersion |
|---|
| 440 | LogFile.WriteLine Now & " - folder: " & InstalledDir & " successfully renamend to " & InstalledDir & "_" & oldVersion |
|---|
| 441 | End If |
|---|
| 442 | |
|---|
| 443 | 'copy new version to target folder |
|---|
| 444 | WScript.Echo "* copy new NSClient++ Version from remote share . . . - " & Now |
|---|
| 445 | Err.Clear |
|---|
| 446 | fso.CopyFolder strServerInstDir, strProgramFiles |
|---|
| 447 | WScript.Sleep 500 |
|---|
| 448 | If fso.FolderExists (strProgramFiles) = vbTrue Then |
|---|
| 449 | WScript.Echo "* copying files from " & strServerInstDir & " to " & strProgramFiles & " was successfully " & Now |
|---|
| 450 | LogFile.WriteLine Now & " - copy new NSClient++ version was successfully" |
|---|
| 451 | Else |
|---|
| 452 | WScript.Echo "* ERROR: couldn't copy files from server share to local disk" |
|---|
| 453 | LogFile.WriteLine Now & " - ERROR: could not copy the new version " & Err.Description |
|---|
| 454 | LogFile.Close |
|---|
| 455 | WScript.Quit 24 |
|---|
| 456 | End If |
|---|
| 457 | |
|---|
| 458 | 'install the new version |
|---|
| 459 | rcCMD = wshshell.Run("cmd /c" & Chr(34) & strProgramFiles & "\nsclient++.exe" & Chr(34) & " /install > " & myTEMPNSClientOutP, 0, 1) |
|---|
| 460 | WScript.Sleep 500 |
|---|
| 461 | |
|---|
| 462 | 'check if installation was successfully |
|---|
| 463 | If fso.FileExists (myTEMPNSClientOutP) = vbFalse Then |
|---|
| 464 | WScript.Echo "* ERROR: while installing NSClient++ as daemon" |
|---|
| 465 | LogFile.WriteLine Now & " - ERROR: while installing NSClient++ as daemon" |
|---|
| 466 | LogFile.Close |
|---|
| 467 | WScript.Quit 25 |
|---|
| 468 | Else |
|---|
| 469 | Err.Clear |
|---|
| 470 | Set InstLog = fso.OpenTextFile(myTEMPNSClientOutP, ForReading, vbFalse, TristateMixed ) |
|---|
| 471 | If Err.number <> 0 Then |
|---|
| 472 | WScript.Echo "* ERROR: couldn't open for reading: " & myTEMPNSClientOutP |
|---|
| 473 | LogFile.WriteLine Now & " - ERROR: couldn't open for reading: " & myTEMPNSClientOutP |
|---|
| 474 | LogFile.Close |
|---|
| 475 | WScript.Quit 26 |
|---|
| 476 | Else |
|---|
| 477 | line = InstLog.ReadLine |
|---|
| 478 | If InStr(1, line, "failed:") > 0 Then |
|---|
| 479 | WScript.Echo "* ERROR: " & line |
|---|
| 480 | LogFile.WriteLine Now & " - ERROR: " & line |
|---|
| 481 | Else |
|---|
| 482 | WScript.Echo "* " & line |
|---|
| 483 | LogFile.WriteLine Now & " - " & line |
|---|
| 484 | End If |
|---|
| 485 | InstLog.Close |
|---|
| 486 | fso.DeleteFile myTEMPNSClientOutP, vbTrue |
|---|
| 487 | Set InstLog = Nothing |
|---|
| 488 | End If |
|---|
| 489 | End If |
|---|
| 490 | |
|---|
| 491 | RegNSClientpp = wshshell.RegRead ("HKLM\SYSTEM\CurrentControlSet\Services\NSClientpp\ImagePath") |
|---|
| 492 | If Len(RegNSClientpp) > 5 Then |
|---|
| 493 | WScript.Echo "* NSClientpp daemon was successfully installed" |
|---|
| 494 | LogFile.WriteLine Now & " - NSClientpp daemon was successfully installed" |
|---|
| 495 | Else |
|---|
| 496 | WScript.Echo "* ERROR: couldn't install NSClientpp daemon" |
|---|
| 497 | LogFile.WriteLine Now & " - ERROR: couldn't install NSClientpp daemon" |
|---|
| 498 | LogFile.Close |
|---|
| 499 | WScript.Quit 27 |
|---|
| 500 | End If |
|---|
| 501 | |
|---|
| 502 | 'use independent settings if specified in config file |
|---|
| 503 | If myINI = "Y" Then |
|---|
| 504 | Err.clear |
|---|
| 505 | fso.CopyFile InstalledDir & "_" & oldVersion & "\NSC.ini", strProgramFiles & "\NSC.ini", vbTrue |
|---|
| 506 | If Err.number <> 0 Then |
|---|
| 507 | WScript.Echo "* ERROR: could not copy NSC.ini from prior version! " & Err.Description |
|---|
| 508 | LogFile.WriteLine Now & " - ERROR: could not copy NSC.ini from prior version! " & Err.Description |
|---|
| 509 | Else |
|---|
| 510 | WScript.Echo "* restore NSC.ini from prior version was successfully" |
|---|
| 511 | LogFile.WriteLine Now & " - restore NSC.ini from prior version" |
|---|
| 512 | End If |
|---|
| 513 | End If |
|---|
| 514 | If mySCRIPT = "Y" Then |
|---|
| 515 | Err.Clear |
|---|
| 516 | fso.CopyFolder InstalledDir & "_" & oldVersion & "\scripts", strProgramFiles & "\scripts", vbTrue |
|---|
| 517 | If Err.number <> 0 Then |
|---|
| 518 | WScript.Echo "* ERROR: could not copy script folder in new version script folder! " & Err.Description |
|---|
| 519 | LogFile.WriteLine Now & " - ERROR: could not copy script folder in new version script folder! " & Err.Description |
|---|
| 520 | Else |
|---|
| 521 | WScript.Echo "* restore script folder from prior version was successfully" |
|---|
| 522 | LogFile.WriteLine Now & " - restore script folder from prior version" |
|---|
| 523 | End If |
|---|
| 524 | End If |
|---|
| 525 | |
|---|
| 526 | 'start the NSClient daemon |
|---|
| 527 | rcCMD = wshshell.Run("cmd /c net start nsclientpp", 0, 1) |
|---|
| 528 | If rcCMD = 0 Then |
|---|
| 529 | WScript.Echo "* NSClientpp daemon was successfully started" |
|---|
| 530 | LogFile.WriteLine Now & " - NSClientpp daemon was successfully started" |
|---|
| 531 | Else |
|---|
| 532 | WScript.Echo "* ERROR: couldn't start NSClientpp daemon!" |
|---|
| 533 | LogFile.WriteLine Now & " - ERROR: couldn't start NSClientpp daemon!" |
|---|
| 534 | LogFile.Close |
|---|
| 535 | WScript.Quit 28 |
|---|
| 536 | End If |
|---|
| 537 | |
|---|
| 538 | 'finish |
|---|
| 539 | WScript.Echo vbNewLine |
|---|
| 540 | LogFile.WriteBlankLines(1) |
|---|
| 541 | LogFile.WriteLine String(20, "*") & " F I N I S H " & String(20,"*") |
|---|
| 542 | LogFile.Close |
|---|
| 543 | WScript.Quit |
|---|
| 544 | |
|---|
| 545 | 'NSClient++ is not installed yet |
|---|
| 546 | Case "new" |
|---|
| 547 | |
|---|
| 548 | 'print out Info |
|---|
| 549 | WScript.Echo "* TASK is install NSClient++ in: " & strProgramFiles |
|---|
| 550 | LogFile.WriteLine Now & " - TASK is install NSClient++ in: " & strProgramFiles |
|---|
| 551 | |
|---|
| 552 | WScript.Echo "* copy new NSClient++ Version from remote share . . . - " & Now |
|---|
| 553 | Err.clear |
|---|
| 554 | fso.CopyFolder strServerInstDir, strProgramFiles |
|---|
| 555 | WScript.Sleep 500 |
|---|
| 556 | If fso.FolderExists(strProgramFiles) = vbTrue Then |
|---|
| 557 | WScript.Echo "* copying files from " & strServerInstDir & " to " & strProgramFiles & " was successfully " & Now |
|---|
| 558 | LogFile.WriteLine Now & " - copying files from " & strServerInstDir & " to " & strProgramFiles & " was successfully" |
|---|
| 559 | Else |
|---|
| 560 | WScript.Quit "* ERROR: couldn't copy the new version " & Err.Description |
|---|
| 561 | LogFile.WriteLine Now & " - ERROR: could not copy the new version " & Err.Description |
|---|
| 562 | LogFile.Close |
|---|
| 563 | WScript.Quit 29 |
|---|
| 564 | End If |
|---|
| 565 | |
|---|
| 566 | 'install the new version |
|---|
| 567 | rcCMD = wshshell.Run("cmd /c" & Chr(34) & strProgramFiles & "\nsclient++.exe" & Chr(34) & " /install > " & myTEMPNSClientOutP, 0, 1) |
|---|
| 568 | WScript.Sleep 500 |
|---|
| 569 | |
|---|
| 570 | 'check if installation was successfully |
|---|
| 571 | If fso.FileExists (myTEMPNSClientOutP) = vbFalse Then |
|---|
| 572 | WScript.Echo "* ERROR: while installing NSClient++ as daemon" |
|---|
| 573 | LogFile.WriteLine Now & " - ERROR: while installing NSClient++ as daemon" |
|---|
| 574 | LogFile.Close |
|---|
| 575 | WScript.Quit 30 |
|---|
| 576 | Else |
|---|
| 577 | Err.Clear |
|---|
| 578 | Set InstLog = fso.OpenTextFile(myTEMPNSClientOutP, ForReading, vbFalse, TristateMixed ) |
|---|
| 579 | If Err.number <> 0 Then |
|---|
| 580 | WScript.Echo "* ERROR: couldn't open for reading: " & myTEMPNSClientOutP |
|---|
| 581 | LogFile.WriteLine Now & " - ERROR: couldn't open for reading: " & myTEMPNSClientOutP |
|---|
| 582 | WScript.Quit 31 |
|---|
| 583 | Else |
|---|
| 584 | line = InstLog.ReadLine |
|---|
| 585 | If InStr(1, line, "failed:") > 0 Then |
|---|
| 586 | WScript.Echo "* ERROR: " & line |
|---|
| 587 | LogFile.WriteLine Now & " - ERROR: " & line |
|---|
| 588 | Else |
|---|
| 589 | WScript.Echo "* " & line |
|---|
| 590 | LogFile.WriteLine Now & " - " & line |
|---|
| 591 | End If |
|---|
| 592 | InstLog.Close |
|---|
| 593 | fso.DeleteFile myTEMPNSClientOutP, vbTrue |
|---|
| 594 | Set InstLog = Nothing |
|---|
| 595 | End If |
|---|
| 596 | End If |
|---|
| 597 | |
|---|
| 598 | RegNSClientpp = wshshell.RegRead ("HKLM\SYSTEM\CurrentControlSet\Services\NSClientpp\ImagePath") |
|---|
| 599 | If Len(RegNSClientpp) > 5 Then |
|---|
| 600 | WScript.Echo "* NSClientpp daemon was successfully installed" |
|---|
| 601 | LogFile.WriteLine Now & " - NSClientpp daemon was successfully installed in" |
|---|
| 602 | Else |
|---|
| 603 | WScript.Echo "* ERROR: couldn't install NSClientpp daemon" |
|---|
| 604 | LogFile.WriteLine Now & " - ERROR: couldn't install NSClientpp daemon" |
|---|
| 605 | LogFile.Close |
|---|
| 606 | WScript.Quit 32 |
|---|
| 607 | End If |
|---|
| 608 | |
|---|
| 609 | 'start the NSClient daemon |
|---|
| 610 | rcCMD = wshshell.Run("cmd /c net start nsclientpp", 0, 1) |
|---|
| 611 | If rcCMD = 0 Then |
|---|
| 612 | WScript.Echo "* NSClientpp daemon was successfully started" |
|---|
| 613 | LogFile.WriteLine Now & " - NSClientpp daemon was successfully started" |
|---|
| 614 | Else |
|---|
| 615 | WScript.Echo "* ERROR: could not start NSClientpp daemon!" |
|---|
| 616 | LogFile.WriteLine Now & " - ERROR: could not start NSClientpp daemon!" |
|---|
| 617 | LogFile.Close |
|---|
| 618 | WScript.Quit 33 |
|---|
| 619 | End If |
|---|
| 620 | |
|---|
| 621 | 'finish |
|---|
| 622 | WScript.Echo vbNewLine |
|---|
| 623 | LogFile.WriteBlankLines(1) |
|---|
| 624 | LogFile.WriteLine String(20, "*") & " F I N I S H " & String(20,"*") |
|---|
| 625 | LogFile.Close |
|---|
| 626 | WScript.Quit 0 |
|---|
| 627 | |
|---|
| 628 | 'NSClient++ is already up to date |
|---|
| 629 | Case "up2date" |
|---|
| 630 | |
|---|
| 631 | WScript.Echo "* NSClient++ is up to date: Version " & oldVersion |
|---|
| 632 | LogFile.WriteLine Now & " - NSClient++ is up to date: Version " & oldVersion |
|---|
| 633 | |
|---|
| 634 | 'finish |
|---|
| 635 | WScript.Echo vbNewLine |
|---|
| 636 | LogFile.WriteBlankLines(1) |
|---|
| 637 | LogFile.WriteLine String(20, "*") & " F I N I S H " & String(20,"*") |
|---|
| 638 | LogFile.Close |
|---|
| 639 | Set LogFile = Nothing |
|---|
| 640 | WScript.Quit 0 |
|---|
| 641 | |
|---|
| 642 | End Select |
|---|