Solved

Convert small batch script to VBS

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

635 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