Solved

Convert small batch script to VBS

Posted on 2007-03-29
5
621 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:detox1978
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18816204
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
0
 
LVL 2

Author Comment

by:detox1978
ID: 18816405
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....


0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18816580
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
0
 
LVL 2

Author Comment

by:detox1978
ID: 18816991
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)
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18817081
Try this version...

'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
On Error Resume Next
If Not objFSO.FileExists (strFile) Then
  ret = objShell.LogEvent(WARNING, "Backup Failed", PC)
else
  ret = objShell.LogEvent(INFO,"Backup Success", PC)
End If
wscript.echo err.Description
On Error Goto 0
objShell.Run "regedit /e \\localhost\print_share\shares.reg HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares"

Set objShell=Nothing
Set objFSO=Nothing
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question