neutec
Technical User
- Apr 26, 2003
- 343
Hello Guys,
Im attemping to use a VB script to backup some file. I got that working but now I wanted to stop and start a service "mnwatchdog". I cant get it to work once I add the code. Any advice?
'Stop Service
strServiceName = "mnwatchdog"
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
Option Explicit
Const start = "c:\test\"
Const dest = "c:\test2\"
Const logName = "c:\test2\log.txt"
Dim fso,Logg
Set fso = CreateObject("Scripting.FileSystemObject")
Set logg = fspenTextFile(logName, 8, True)
logg.WriteLine vbNewLine & "Backup started @ " & Now()
DoWork start, dest, Now()
logg.WriteLine "Backup ended @ " & Now()
Sub DoWork(dir, dest, modDate)
Dim objFile, objDir
logg.WriteLine "DIR: " & dir
If Not fso.FolderExists(dir) Then
logg.WriteLine "Can't find the " & dir & " folder"
Exit Sub
End If
With fso.GetFolder(dir)
For Each objFile in.Files
if DateDiff("d", objFile.DateLastModified, modDate) = 0 Then
fso.CopyFile objfile,dest, True
'objFile.CopyFile dest, True
logg.WriteLine objFile.Name & ", Mod-Date: " & objFile.DateLastModified & ", copied to " & dest
End If
Next
For Each objDir in.SubFolders
DoWork objDir.Path, dest, modDate
Next
End With
End Sub
'Start Service
strServiceName = "mnwatchdog"
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
Im attemping to use a VB script to backup some file. I got that working but now I wanted to stop and start a service "mnwatchdog". I cant get it to work once I add the code. Any advice?
'Stop Service
strServiceName = "mnwatchdog"
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
Option Explicit
Const start = "c:\test\"
Const dest = "c:\test2\"
Const logName = "c:\test2\log.txt"
Dim fso,Logg
Set fso = CreateObject("Scripting.FileSystemObject")
Set logg = fspenTextFile(logName, 8, True)
logg.WriteLine vbNewLine & "Backup started @ " & Now()
DoWork start, dest, Now()
logg.WriteLine "Backup ended @ " & Now()
Sub DoWork(dir, dest, modDate)
Dim objFile, objDir
logg.WriteLine "DIR: " & dir
If Not fso.FolderExists(dir) Then
logg.WriteLine "Can't find the " & dir & " folder"
Exit Sub
End If
With fso.GetFolder(dir)
For Each objFile in.Files
if DateDiff("d", objFile.DateLastModified, modDate) = 0 Then
fso.CopyFile objfile,dest, True
'objFile.CopyFile dest, True
logg.WriteLine objFile.Name & ", Mod-Date: " & objFile.DateLastModified & ", copied to " & dest
End If
Next
For Each objDir in.SubFolders
DoWork objDir.Path, dest, modDate
Next
End With
End Sub
'Start Service
strServiceName = "mnwatchdog"
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