Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pathOfWFBSHInstaller="msiexec /qn /i ""WFBS-SVC_Agent_Installer.msi"""
- strComputer = "."
- strOutput = ""
- serviceCount = 0
- totalServiceCountToCheck = 3
- On Error Resume Next
- Dim g_oSB : Set g_oSB = CreateObject("System.Text.StringBuilder")
- Dim g_logFolderPath
- Sub PrepareLogFolder()
- g_logFolderPath = ""
- Set objFileSysObject = CreateObject("Scripting.FileSystemObject")
- Const TemporaryFolder = 2
- Dim tempFolder: tempFolder = objFileSysObject.GetSpecialFolder(TemporaryFolder)
- g_logFolderPath = tempFolder & "\WFBS_Installer_Debug"
- If Not objFileSysObject.FolderExists(g_logFolderPath) Then
- objFileSysObject.CreateFolder(g_logFolderPath)
- End If
- If Not objFileSysObject.FolderExists(g_logFolderPath) Then
- g_logFolderPath = ""
- End If
- End Sub
- Function sprintf(sFormat, aData)
- g_oSB.AppendFormat_4 sFormat, (aData)
- sprintf = g_oSB.ToString()
- g_oSB.Length = 0
- End Function
- Sub WriteToLog(strMsg, truncateLog)
- If Len(g_logFolderPath) = 0 Then
- Exit Sub
- End If
- Dim objFileSysObject, objTextFile
- Dim openMode
- Const openForWriting = 2
- Const openForAppending = 8
- Dim dateTimeNow : dateTimeNow = now()
- Dim strDateTime : strDateTime = sprintf("{0:yyyy-MM-dd hh:mm:ss}", Array(dateTimeNow))
- Dim strNewMsg : strNewMsg = strDateTime & " [LoginScript] " & strMsg
- Set objFileSysObject = CreateObject("Scripting.FileSystemObject")
- If Not objFileSysObject.FolderExists(g_logFolderPath) Then
- objFileSysObject.CreateFolder(g_logFolderPath)
- End If
- If truncateLog = True Then
- openMode = openForWriting
- Else
- openMode = openForAppending
- End If
- Set objTextFile = objFileSysObject.OpenTextFile(g_logFolderPath & "\" & "LoginScript.log", openMode, True)
- objTextFile.WriteLine(strNewMsg)
- objTextFile.Close
- END Sub
- PrepareLogFolder
- WriteToLog "Begin >>>", True
- ' check if WFBS-SVR is installed by detecting service ntrtscan, tmlisten, svcGenericHost are exist or not
- Set objWMIService = GetObject("winmgmts:" _
- & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
- Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
- For Each objService in colItems
- strOutput = strOutput & objService.name & vbCr & vbLf
- If objService.name = "ntrtscan" Then
- serviceCount = serviceCount + 1
- WriteToLog "Found NtrtScan service.", False
- ' Wscript.Echo "Service " & objService.Caption & " is " & objService.Started
- ElseIf objService.name = "tmlisten" Then
- serviceCount = serviceCount + 1
- WriteToLog "Found Tmlisten service.", False
- ' Wscript.Echo "Service " & objService.Caption & " is " & objService.Started
- ElseIf objService.name = "svcGenericHost" Then
- serviceCount = serviceCount + 1
- WriteToLog "Found svcGenericHost service.", False
- ' Wscript.Echo "Service " & objService.Caption & " is " & objService.Started
- End If
- Next
- If serviceCount <> totalServiceCountToCheck Then
- WriteToLog "Only found " & CStr(serviceCount) & " services. Some services are missing!", False
- Dim WshShell
- Set WshShell = CreateObject("WScript.Shell")
- strCurDir = WshShell.CurrentDirectory
- WriteToLog "Current directory is [" & strCurDir & "]", False
- Dim strCmdLine
- If len(g_logFolderPath) > 0 Then
- Dim strMsiLogPath
- strMsiLogPath = g_logFolderPath & "\MSI_InstallerLog.log"
- strCmdLine = pathOfWFBSHInstaller & " /L*V """ & strMsiLogPath & """"
- Else
- strCmdLine = pathOfWFBSHInstaller
- End If
- WriteToLog "Run command-line :[" & strCmdLine & "]", False
- WshShell.Run strCmdLine
- Else
- WriteToLog "Already installed. No need to install Agent", False
- End if
- WriteToLog "Finish <<<", False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement