Solved

Convert small batch script to VBS

Posted on 2007-03-29
5
598 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now