Link to home
Start Free TrialLog in
Avatar of detox1978
detox1978Flag for United Kingdom of Great Britain and Northern Ireland

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\prtbkp%computername%.cab

:: If the newly created printmig file doesn't exist log a sucess event
if not exist \\localhost\print_share\prtbkp%computername%.cab 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\prtbkp%computername%.cab Eventcreate /L APPLICATION /so "Scheduled Task" /t INFORMATION /id 1 /d "backup Success"

___________________________________________________________________



Many thanks
Avatar of sirbounty
sirbounty
Flag of United States of America image

This should do it...

'PrintBkup.vbs
Const WARNING = 3
Const INFO = 4

Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objShell:Set objShell=CreateObject("Wscript.Shell")
Dim objNet: Set objNet=CreateObject("Wscript.Network")
PC=objNet.ComputerName
strFile="\\localhost\print_share\prtbkp" & 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,"Backup Success", PC)
End If

Set objShell=Nothing
Set objFSO=Nothing
Set objNet=Nothing
Avatar of detox1978

ASKER

Cheers,

I also need to add this;

regedit /e \\localhost\print_share\shares.reg HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares


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("Scripting.FileSystemObject")
Dim objShell:Set objShell=CreateObject("Wscript.Shell")
Dim objNet: Set objNet=CreateObject("Wscript.Network")
PC=objNet.ComputerName
strFile="\\localhost\print_share\prtbkp" & 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,"Backup Success", PC)
End If
objShell.Run "regedit /e \\localhost\print_share\shares.reg HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares"

Set objShell=Nothing
Set objFSO=Nothing
Set objNet=Nothing
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)
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial