Hello,
I am not that savvy in vb script but I have below script. What I want is it writes the log info in the txt file with append mode. I would like to have Date, Time and How much numbers was it if it restarted the service. If it did not restart the service, it does not need to write in the same text file but different text file with date, time, and numbers. Also can the TermService stop the UmRdpService service. I have to do it separate below but if it can stop dependency, it would be great.
'Local C Drive Test
Set fs = CreateObject("Scripting.FileSystemObject")
folderName = "C:\test\Test\"
numbers = fs.GetFolder(folderName).Files.Count
if (numbers > 5) Then
Const EVENT_WARNING = 2
Set objShell = CreateObject("Wscript.Shell")
objShell.LogEvent 2, "There are more than 5 files in the directory. The directory is " & folderName & ". Number of files are " & numbers
msgbox "There are more than 5 files in the directory. " & vbcrlf & "The directory is " & folderName & "." & vbcrlf & "Number of files are " & numbers & vbcrlf & "RESTART SEPM SERVICES ON C DRIVE ",,"C DRIVE: Total SEPM Files: " & numbers
'Stop Service
strServiceName = "UmRdpService"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StopService()
Next
'Stop Service
strServiceName = "TermService"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StopService()
Next
'Start Service
strServiceName = "UmRdpService"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StartService()
Next
'Start Service
strServiceName = "TermService"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StartService()
Next
else
msgbox ("There is no concern of the files in the directory. " & vbcrlf & "The directory is " & folderName & "." & vbcrlf & "Number of files are " & numbers)
End If
I am not that savvy in vb script but I have below script. What I want is it writes the log info in the txt file with append mode. I would like to have Date, Time and How much numbers was it if it restarted the service. If it did not restart the service, it does not need to write in the same text file but different text file with date, time, and numbers. Also can the TermService stop the UmRdpService service. I have to do it separate below but if it can stop dependency, it would be great.
'Local C Drive Test
Set fs = CreateObject("Scripting.FileSystemObject")
folderName = "C:\test\Test\"
numbers = fs.GetFolder(folderName).Files.Count
if (numbers > 5) Then
Const EVENT_WARNING = 2
Set objShell = CreateObject("Wscript.Shell")
objShell.LogEvent 2, "There are more than 5 files in the directory. The directory is " & folderName & ". Number of files are " & numbers
msgbox "There are more than 5 files in the directory. " & vbcrlf & "The directory is " & folderName & "." & vbcrlf & "Number of files are " & numbers & vbcrlf & "RESTART SEPM SERVICES ON C DRIVE ",,"C DRIVE: Total SEPM Files: " & numbers
'Stop Service
strServiceName = "UmRdpService"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StopService()
Next
'Stop Service
strServiceName = "TermService"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StopService()
Next
'Start Service
strServiceName = "UmRdpService"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StartService()
Next
'Start Service
strServiceName = "TermService"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StartService()
Next
else
msgbox ("There is no concern of the files in the directory. " & vbcrlf & "The directory is " & folderName & "." & vbcrlf & "Number of files are " & numbers)
End If