detox1978
asked on
Convert small batch script to VBS
Hi All,
I have a batch script (below) that backs up the printer divers using printmig, and logs the result into the event log. I need to convert this into VBS.
__________________________ __________ __________ __________ __________ _
:: backup print drivers using printmig utility
printmig -b \\localhost\print_share\pr tbkp%compu tername%.c ab
:: If the newly created printmig file doesn't exist log a sucess event
if not exist \\localhost\print_share\pr tbkp%compu tername%.c ab Eventcreate /L APPLICATION /so "Scheduled Task" /t ERROR /id 501 /d "backup Failed"
:: If the newly created printmig file does exist log a sucess event
if exist \\localhost\print_share\pr tbkp%compu tername%.c ab Eventcreate /L APPLICATION /so "Scheduled Task" /t INFORMATION /id 1 /d "backup Success"
__________________________ __________ __________ __________ __________ _
Many thanks
I have a batch script (below) that backs up the printer divers using printmig, and logs the result into the event log. I need to convert this into VBS.
__________________________
:: backup print drivers using printmig utility
printmig -b \\localhost\print_share\pr
:: If the newly created printmig file doesn't exist log a sucess event
if not exist \\localhost\print_share\pr
:: If the newly created printmig file does exist log a sucess event
if exist \\localhost\print_share\pr
__________________________
Many thanks
ASKER
Cheers,
I also need to add this;
regedit /e \\localhost\print_share\sh ares.reg HKEY_LOCAL_MACHINE\SYSTEM\ CurrentCon trolSet\Se rvices\lan manserver\ Shares
which exports a registry hive....
I also need to add this;
regedit /e \\localhost\print_share\sh
which exports a registry hive....
Easiest method with what you have here is:
'PrintBkup.vbs
Const WARNING = 3
Const INFO = 4
Dim objFSO:Set objFSO=CreateObject("Scrip ting.FileS ystemObjec t")
Dim objShell:Set objShell=CreateObject("Wsc ript.Shell ")
Dim objNet: Set objNet=CreateObject("Wscri pt.Network ")
PC=objNet.ComputerName
strFile="\\localhost\print _share\prt bkp" & PC & ".cab"
objShell.Run "printmig -b " & strFile
If Not objFSO.FileExists (strFile) Then
ret = objShell.LogEvent(WARNING, "Backup Failed", PC)
else
ret = objShell.LogEvent(INFO,"Ba ckup Success", PC)
End If
objShell.Run "regedit /e \\localhost\print_share\sh ares.reg HKEY_LOCAL_MACHINE\SYSTEM\ CurrentCon trolSet\Se rvices\lan manserver\ Shares"
Set objShell=Nothing
Set objFSO=Nothing
Set objNet=Nothing
'PrintBkup.vbs
Const WARNING = 3
Const INFO = 4
Dim objFSO:Set objFSO=CreateObject("Scrip
Dim objShell:Set objShell=CreateObject("Wsc
Dim objNet: Set objNet=CreateObject("Wscri
PC=objNet.ComputerName
strFile="\\localhost\print
objShell.Run "printmig -b " & strFile
If Not objFSO.FileExists (strFile) Then
ret = objShell.LogEvent(WARNING,
else
ret = objShell.LogEvent(INFO,"Ba
End If
objShell.Run "regedit /e \\localhost\print_share\sh
Set objShell=Nothing
Set objFSO=Nothing
Set objNet=Nothing
ASKER
Cheers,
I checked the first script and it works, but occationally it displays an error box saying "Microsoft VBScript runtime error '800a0005', line 13, char 3"
line 13 is;
ret = objShell.LogEvent(WARNING, "Backup Failed", PC)
I checked the first script and it works, but occationally it displays an error box saying "Microsoft VBScript runtime error '800a0005', line 13, char 3"
line 13 is;
ret = objShell.LogEvent(WARNING,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
'PrintBkup.vbs
Const WARNING = 3
Const INFO = 4
Dim objFSO:Set objFSO=CreateObject("Scrip
Dim objShell:Set objShell=CreateObject("Wsc
Dim objNet: Set objNet=CreateObject("Wscri
PC=objNet.ComputerName
strFile="\\localhost\print
objShell.Run "printmig -b " & strFile
If Not objFSO.FileExists (strFile) Then
ret = objShell.LogEvent(WARNING,
else
ret = objShell.LogEvent(INFO,"Ba
End If
Set objShell=Nothing
Set objFSO=Nothing
Set objNet=Nothing