Advertisement
adamchilcott

WFBS-SVC Example Deployment Script.vbs

Oct 22nd, 2018
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pathOfWFBSHInstaller="msiexec /qn /i ""WFBS-SVC_Agent_Installer.msi"""
  2. strComputer = "."
  3. strOutput = ""
  4. serviceCount = 0
  5. totalServiceCountToCheck = 3
  6.  
  7. On Error Resume Next
  8.  
  9. Dim g_oSB : Set g_oSB = CreateObject("System.Text.StringBuilder")
  10. Dim g_logFolderPath
  11.  
  12. Sub PrepareLogFolder()
  13.     g_logFolderPath = ""
  14.     Set objFileSysObject = CreateObject("Scripting.FileSystemObject")
  15.     Const TemporaryFolder = 2
  16.     Dim tempFolder: tempFolder = objFileSysObject.GetSpecialFolder(TemporaryFolder)
  17.     g_logFolderPath = tempFolder & "\WFBS_Installer_Debug"
  18.  
  19.     If Not objFileSysObject.FolderExists(g_logFolderPath) Then
  20.         objFileSysObject.CreateFolder(g_logFolderPath)
  21.     End If
  22.     If Not objFileSysObject.FolderExists(g_logFolderPath) Then
  23.         g_logFolderPath = ""
  24.     End If
  25. End Sub
  26.  
  27. Function sprintf(sFormat, aData)
  28.    g_oSB.AppendFormat_4 sFormat, (aData)
  29.    sprintf = g_oSB.ToString()
  30.    g_oSB.Length = 0
  31. End Function
  32.  
  33. Sub WriteToLog(strMsg, truncateLog)
  34.     If Len(g_logFolderPath) = 0 Then
  35.         Exit Sub
  36.     End If
  37.     Dim objFileSysObject, objTextFile    
  38.     Dim openMode
  39.     Const openForWriting = 2
  40.     Const openForAppending = 8
  41.     Dim dateTimeNow : dateTimeNow = now()
  42.     Dim strDateTime : strDateTime = sprintf("{0:yyyy-MM-dd hh:mm:ss}", Array(dateTimeNow))
  43.     Dim strNewMsg : strNewMsg = strDateTime & " [LoginScript] " & strMsg    
  44.     Set objFileSysObject = CreateObject("Scripting.FileSystemObject")
  45.     If Not objFileSysObject.FolderExists(g_logFolderPath) Then
  46.         objFileSysObject.CreateFolder(g_logFolderPath)
  47.     End If
  48.     If truncateLog = True Then
  49.         openMode = openForWriting
  50.     Else
  51.         openMode = openForAppending
  52.     End If
  53.     Set objTextFile = objFileSysObject.OpenTextFile(g_logFolderPath & "\" & "LoginScript.log", openMode, True)
  54.     objTextFile.WriteLine(strNewMsg)
  55.     objTextFile.Close
  56. END Sub
  57.  
  58. PrepareLogFolder
  59. WriteToLog "Begin >>>", True
  60.  
  61. ' check if WFBS-SVR is installed by detecting service ntrtscan, tmlisten, svcGenericHost are exist or not
  62. Set objWMIService = GetObject("winmgmts:" _
  63.     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  64. Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
  65. For Each objService in colItems
  66.     strOutput = strOutput & objService.name & vbCr & vbLf
  67.     If objService.name = "ntrtscan" Then
  68.         serviceCount = serviceCount + 1    
  69.         WriteToLog "Found NtrtScan service.", False
  70. '       Wscript.Echo "Service " & objService.Caption & " is " & objService.Started
  71.     ElseIf objService.name = "tmlisten" Then
  72.         serviceCount = serviceCount + 1
  73.         WriteToLog "Found Tmlisten service.", False
  74. '       Wscript.Echo "Service " & objService.Caption & " is " & objService.Started
  75.     ElseIf objService.name = "svcGenericHost" Then
  76.         serviceCount = serviceCount + 1
  77.         WriteToLog "Found svcGenericHost service.", False
  78. '       Wscript.Echo "Service " & objService.Caption & " is " & objService.Started
  79.     End If
  80. Next
  81.  
  82. If serviceCount <> totalServiceCountToCheck Then
  83.     WriteToLog "Only found " & CStr(serviceCount) & " services. Some services are missing!", False
  84.     Dim WshShell
  85.     Set WshShell = CreateObject("WScript.Shell")
  86.     strCurDir = WshShell.CurrentDirectory
  87.     WriteToLog "Current directory is [" & strCurDir & "]", False   
  88.     Dim strCmdLine
  89.     If len(g_logFolderPath) > 0 Then
  90.         Dim strMsiLogPath
  91.         strMsiLogPath = g_logFolderPath & "\MSI_InstallerLog.log"  
  92.         strCmdLine = pathOfWFBSHInstaller & " /L*V """ & strMsiLogPath & """"      
  93.     Else
  94.         strCmdLine = pathOfWFBSHInstaller
  95.     End If
  96.     WriteToLog "Run command-line :[" & strCmdLine & "]", False
  97.     WshShell.Run strCmdLine
  98. Else
  99.     WriteToLog "Already installed. No need to install Agent", False
  100. End if
  101.  
  102. WriteToLog "Finish <<<", False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement