Link to home
Start Free TrialLog in
Avatar of janis101
janis101

asked on

How to convert batch file to vbscript

Guys,

Can anyone help me how to convert batch file to vbscript as we are using vbscript for automation.

attaching batch code

ovc -kill
cd C:\Program Files\HP OpenView\lbin\eaagt
ren opcmsgi.exe opcmsgiORIG.exe
ren opcmsga.exe opcmsgaORIG.exe
cd\
cd C:\Program Files\HP OpenView\bin
ren opcmsg.exe opcmsgORIG.exe
cd\
copy /Y " \c:\Hotfix\opcmsgi.exe"  "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgi.exe" 
copy /Y " \c:\Hotfix\opcmsga.exe"  "C:\Program Files\HP OpenView\lbin\eaagt\opcmsga.exe"
copy /Y "\c:\Hotfix\opcmsg.exe"   "C:\Program Files\HP OpenView\bin\opcmsg.exe"
ovc -start
ovc -kill
cd C:\Program Files\HP OpenView\bin
ovpacmd stop alarm
cd\
cd C:\Program Files\HP OpenView\support
ovtrcadm -srvshutdown
net stop HPOvTrcSvc
cd\
cd C:\Program Files\HP OpenView\bin
ren OvXpl.dll OvXpl.dllorig
ren ovbbccb.exe ovbbccborig1.exe
ren OvBbc.dll OvBbc.dll.orig
copy "\c:\Hotfix\OvXpl.dll"   "C:\Program Files\HP OpenView\bin\OvXpl.dll"
copy "\c:\Hotfix\ovbbccb.exe"   "C:\Program Files\HP OpenView\bin\ovbbccb.exe"
copy "\c:\ Hotfix\OvBbc.dll"   "C:\Program Files\HP OpenView\bin\OvBbc.dll"
ovpacmd start alarm
net start HPOvTrcSvc
ovc -start
ovc -status

Open in new window


Manual Steps:

1.      Stop the agent:

c:\> opcagt -stop
2.      Copy and rename original files:
•      C:\Program Files\HP OpenView\lbin\eaagt\opcmsgi.exe to opcmsgiORIG.exe
•      C:\Program Files\HP OpenView\lbin\eaagt\opcmsga.exe to opcmsgaORIG.exe
•      C:\Program Files\HP OpenView\bin\opcmsg.exe to opcmsgORIG.exe

3.      Copy hotfixes  to their correct locations:
•      opcmsgi.exe to C:\Program Files\HP OpenView\lbin\eaagt\opcmsgi.exe
•      opcmsga.exe to C:\Program Files\HP OpenView\lbin\eaagt\opcmsga.exe
•      opcmsg.exe to C:\Program Files\HP OpenView\bin\ \opcmsg.exe

4.      Start the agent:

c:\> opcagt –start

Stop the agent :
C:\> ovc –kill
1.      Stop the PA alarm components:
         C:\Program Files\HP OpenView\bin> ovpacmd stop alarm

2.        Stop the OV Trace service:

C:\Program Files\HP OpenView\support> ovtrcadm -srvshutdown
C:\ Program Files\HP OpenView\support> net stop HPOvTrcSvc

3.      Copy and rename original files in C:\Program Files\HP OpenView\bin\win64\ :
a.      OvXpl.dll  to OvXpl.dll.orig

b.      ovbbccb.exe to ovbbccb.exe.orig
c.      OvBbc.dll to OvBbc.dll.orig
Copy hotfix files to C:\Program Files\HP OpenView\bin\ win64\

a.  OvXpl.dll
b. ovbbccb.exe
c. OvBbc.dll
4.         Start the PA services:

  C:\> ovpacmd start alarm
5.         Start the OV Trace service:

                      C:\> net start HPOvTrcSvc

6.       Start the  agent
         C:\> ovc -start
7.       Check the agent status and make sure all the processes are running:
   C:\> ovc –status
Avatar of ashunnag
ashunnag
Flag of Saudi Arabia image

If you want to re-write all commands in VBSCRIPT language this can work, but for me I prefer to run the bat file from a vbscript:

Set oShell = CreateObject ("WScript.Shell")
Set oExec = oShell.Exec("CMD.EXE /C C:\filename.bat")
Avatar of Bill Prew
Bill Prew

I agree, you would end up with a VBS script that did a bunch of RUN calls, seems like the BAT script is a better choice for this.

~bp
Avatar of janis101

ASKER

Thanks for your reply bill...

Appreciate your help if you fully make it to vbscript as we have to implement our project work....
Anyone help me on this.

i want a vbscript that doesnt contain bat file..

i hope Rob and Bill can help me on this.
See if this works.

Regards,

Rob.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
objShell.Run "C:\Program Files\HP OpenView\ovc -kill", 1, True
If objFSO.FileExists("C:\Program Files\HP OpenView\lbin\eaagt\opcmsgiORIG.exe") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgiORIG.exe", True
objFSO.MoveFile "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgi.exe", "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgiORIG.exe"
If objFSO.FileExists("C:\Program Files\HP OpenView\lbin\eaagt\opcmsgaORIG.exe") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgaORIG.exe", True
objFSO.MoveFile "C:\Program Files\HP OpenView\lbin\eaagt\opcmsga.exe", "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgaORIG.exe"
If objFSO.FileExists("C:\Program Files\HP OpenView\bin\opcmsgORIG.exe") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\bin\opcmsgORIG.exe", True
objFSO.MoveFile "C:\Program Files\HP OpenView\bin\opcmsg.exe", "C:\Program Files\HP OpenView\bin\opcmsgORIG.exe"
objFSO.CopyFile "C:\Hotfix\opcmsgi.exe", "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgi.exe", True
objFSO.CopyFile "C:\Hotfix\opcmsga.exe", "C:\Program Files\HP OpenView\lbin\eaagt\opcmsga.exe", True
objFSO.CopyFile "C:\Hotfix\opcmsg.exe", "C:\Program Files\HP OpenView\bin\opcmsg.exe", True
objShell.Run "C:\Program Files\HP OpenView\ovc -start", 1, True
objShell.Run "C:\Program Files\HP OpenView\ovc -kill", 1, True
objShell.Run "C:\Program Files\HP OpenView\bin\ovpacmd stop alarm", 1, True
objShell.Run "C:\Program Files\HP OpenView\support\ovtrcadm -srvshutdown", 1, True
objShell.Run "net stop HPOvTrcSvc", 1, True
If objFSO.FileExists("C:\Program Files\HP OpenView\bin\OvXpl.dllorig") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\bin\OvXpl.dllorig", True
objFSO.MoveFile "C:\Program Files\HP OpenView\bin\OvXpl.dll", "C:\Program Files\HP OpenView\bin\OvXpl.dllorig"
If objFSO.FileExists("C:\Program Files\HP OpenView\bin\ovbbccborig1.exe") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\bin\ovbbccborig1.exe", True
objFSO.MoveFile "C:\Program Files\HP OpenView\bin\ovbbccb.exe", "C:\Program Files\HP OpenView\bin\ovbbccborig1.exe"
If objFSO.FileExists("C:\Program Files\HP OpenView\bin\OvBbc.dllorig") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\bin\OvBbc.dllorig", True
objFSO.MoveFile "C:\Program Files\HP OpenView\bin\OvBbc.dll", "C:\Program Files\HP OpenView\bin\OvBbc.dllorig"
objFSO.CopyFile "C:\Hotfix\OvXpl.dll", "C:\Program Files\HP OpenView\bin\OvXpl.dll", True
objFSO.CopyFile "C:\Hotfix\ovbbccb.exe", "C:\Program Files\HP OpenView\bin\ovbbccb.exe", True
objFSO.CopyFile "C:\Hotfix\OvBbc.dll", "C:\Program Files\HP OpenView\bin\OvBbc.dll", True
objShell.Run "C:\Program Files\HP OpenView\bin\ovpacmd start alarm", 1, True
objShell.Run "net start HPOvTrcSvc", 1, True
objShell.Run "C:\Program Files\HP OpenView\ovc -start", 1, True
objShell.Run "C:\Program Files\HP OpenView\ovc -status", 1, True

Open in new window

Hi Rob,

Thanks for creating script for me..i got only one error.

objShell.Run "C:\Program Files\HP OpenView\support\ovtrcadm -srvshutdown", 1, True

when i execute the above command, im getting error, the system cannot find the file specififed. if i manually execute the command, it is working

C:\Program Files\HP OpenView\support>ovtrcadm -srvshutdown

so please fix the error..

Note: first i got some error..then i modified the script and is working fine except the above error. pls refer the code.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
objShell.Run "ovc -kill", 1, True
If objFSO.FileExists("C:\Program Files\HP OpenView\lbin\eaagt\opcmsgiORIG.exe") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgiORIG.exe", True
objFSO.MoveFile "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgi.exe", "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgiORIG.exe"
If objFSO.FileExists("C:\Program Files\HP OpenView\lbin\eaagt\opcmsgaORIG.exe") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgaORIG.exe", True
objFSO.MoveFile "C:\Program Files\HP OpenView\lbin\eaagt\opcmsga.exe", "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgaORIG.exe"
If objFSO.FileExists("C:\Program Files\HP OpenView\bin\opcmsgORIG.exe") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\bin\opcmsgORIG.exe", True
objFSO.MoveFile "C:\Program Files\HP OpenView\bin\opcmsg.exe", "C:\Program Files\HP OpenView\bin\opcmsgORIG.exe"
objFSO.CopyFile "C:\Hotfix\opcmsgi.exe", "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgi.exe", True
objFSO.CopyFile "C:\Hotfix\opcmsga.exe", "C:\Program Files\HP OpenView\lbin\eaagt\opcmsga.exe", True
objFSO.CopyFile "C:\Hotfix\opcmsg.exe", "C:\Program Files\HP OpenView\bin\opcmsg.exe", True
objShell.Run "ovpacmd stop alarm", 1, True
objShell.Run "C:\Program Files\HP OpenView\support\ovtrcadm -srvshutdown", 1, True
objShell.Run "net stop HPOvTrcSvc", 1, True
If objFSO.FileExists("C:\Program Files\HP OpenView\bin\OvXpl.dllorig") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\bin\OvXpl.dllorig", True
objFSO.MoveFile "C:\Program Files\HP OpenView\bin\OvXpl.dll", "C:\Program Files\HP OpenView\bin\OvXpl.dll.orig"
If objFSO.FileExists("C:\Program Files\HP OpenView\bin\ovbbccborig1.exe") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\bin\ovbbccborig1.exe", True
objFSO.MoveFile "C:\Program Files\HP OpenView\bin\ovbbccb.exe", "C:\Program Files\HP OpenView\bin\ovbbccborig1.exe"
If objFSO.FileExists("C:\Program Files\HP OpenView\bin\OvBbc.dllorig") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\bin\OvBbc.dllorig", True
objFSO.MoveFile "C:\Program Files\HP OpenView\bin\OvBbc.dll", "C:\Program Files\HP OpenView\bin\OvBbc.dll.orig"
objFSO.CopyFile "C:\Hotfix\OvXpl.dll", "C:\Program Files\HP OpenView\bin\OvXpl.dll", True
objFSO.CopyFile "C:\Hotfix\ovbbccb.exe", "C:\Program Files\HP OpenView\bin\ovbbccb.exe", True
objFSO.CopyFile "C:\Hotfix\OvBbc.dll", "C:\Program Files\HP OpenView\bin\OvBbc.dll", True
objShell.Run "ovpacmd start alarm", 1, True
objShell.Run "net start HPOvTrcSvc", 1, True
objShell.Run "ovc -start", 1, True
objShell.Run "ovc -status", 1, True

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia 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
The script is 100% working..

Very much appreciated Rob..You are the only guy who is helping me on vbscript. You made me a star. God bless you!!

Is there any way to see the output in vbscript while executing the script?

If i executing the above batch i can see the output.

Appreciate your help as i want to see the output while executing the vb script.
Yep, if you run it using
cscript UpdateOpenView.vbs

then we can add a bunch of statements like
WScript.Echo "Executing ovc -kill"

but I don't think you'd see the output of *that* command, it would just be a progress dialog of sorts.  If you wanted to see the output of each command, we'd need to use objShell.Exec instead, and we could write the result of that with
WScript.Echo objExec.ReadAll

and hopefully that would give you enough.  Do you want to try that?

Rob.
I did it anyway, so you can see how it goes.  It's pretty quadrupled the code, but that's what you get in VBScript :-(

Regards,

Rob.

If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
    strPath = Wscript.ScriptFullName
    strCommand = "%comspec% /k cscript  """ & strPath & """"
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run(strCommand), 1, True
    Wscript.Quit
End If

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")

WScript.Echo "Running ovc -kill"
Set objExec = objShell.Exec("""C:\Program Files\HP OpenView\ovc"" -kill")
While objExec.Status = 0
	WScript.Sleep 100
Wend
WScript.Echo objExec.StdOut.ReadAll

If objFSO.FileExists("C:\Program Files\HP OpenView\lbin\eaagt\opcmsgiORIG.exe") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgiORIG.exe", True
WScript.Echo "Renaming C:\Program Files\HP OpenView\lbin\eaagt\opcmsgi.exe to C:\Program Files\HP OpenView\lbin\eaagt\opcmsgiORIG.exe"
objFSO.MoveFile "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgi.exe", "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgiORIG.exe"
If objFSO.FileExists("C:\Program Files\HP OpenView\lbin\eaagt\opcmsgaORIG.exe") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgaORIG.exe", True
WScript.Echo "Renaming C:\Program Files\HP OpenView\lbin\eaagt\opcmsga.exe to C:\Program Files\HP OpenView\lbin\eaagt\opcmsgaORIG.exe"
objFSO.MoveFile "C:\Program Files\HP OpenView\lbin\eaagt\opcmsga.exe", "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgaORIG.exe"
If objFSO.FileExists("C:\Program Files\HP OpenView\bin\opcmsgORIG.exe") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\bin\opcmsgORIG.exe", True
WScript.Echo "Renaming C:\Program Files\HP OpenView\bin\opcmsg.exe to C:\Program Files\HP OpenView\bin\opcmsgORIG.exe"
objFSO.MoveFile "C:\Program Files\HP OpenView\bin\opcmsg.exe", "C:\Program Files\HP OpenView\bin\opcmsgORIG.exe"

WScript.Echo "Copying C:\Hotfix\opcmsgi.exe to C:\Program Files\HP OpenView\lbin\eaagt\opcmsgi.exe"
objFSO.CopyFile "C:\Hotfix\opcmsgi.exe", "C:\Program Files\HP OpenView\lbin\eaagt\opcmsgi.exe", True
WScript.Echo "Copying C:\Hotfix\opcmsga.exe to C:\Program Files\HP OpenView\lbin\eaagt\opcmsga.exe"
objFSO.CopyFile "C:\Hotfix\opcmsga.exe", "C:\Program Files\HP OpenView\lbin\eaagt\opcmsga.exe", True
WScript.Echo "Copying C:\Hotfix\opcmsg.exe to C:\Program Files\HP OpenView\bin\opcmsg.exe"
objFSO.CopyFile "C:\Hotfix\opcmsg.exe", "C:\Program Files\HP OpenView\bin\opcmsg.exe", True

WScript.Echo "Running ovc -start"
Set objExec = objShell.Exec("""C:\Program Files\HP OpenView\ovc"" -start")
While objExec.Status = 0
	WScript.Sleep 100
Wend
WScript.Echo objExec.StdOut.ReadAll

WScript.Echo "Running ovc -kill"
Set objExec = objShell.Exec("""C:\Program Files\HP OpenView\ovc"" -kill")
While objExec.Status = 0
	WScript.Sleep 100
Wend
WScript.Echo objExec.StdOut.ReadAll

WScript.Echo "Running ovpacmd stop alarm"
Set objExec = objShell.Exec("""C:\Program Files\HP OpenView\bin\ovpacmd"" stop alarm")
While objExec.Status = 0
	WScript.Sleep 100
Wend
WScript.Echo objExec.StdOut.ReadAll

WScript.Echo "Running ovtrcadm -srvshutdown"
Set objExec = objShell.Exec("""C:\Program Files\HP OpenView\support\ovtracdm"" -srvshutdown")
While objExec.Status = 0
	WScript.Sleep 100
Wend
WScript.Echo objExec.StdOut.ReadAll

WScript.Echo "Running net stop HPOvTrcSvc"
Set objExec = objShell.Exec("net stop HPOvTrcSvc")
While objExec.Status = 0
	WScript.Sleep 100
Wend
WScript.Echo objExec.StdOut.ReadAll

If objFSO.FileExists("C:\Program Files\HP OpenView\bin\OvXpl.dll.orig") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\bin\OvXpl.dll.orig", True
WScript.Echo "Renaming C:\Program Files\HP OpenView\bin\OvXpl.dll to C:\Program Files\HP OpenView\bin\OvXpl.dll.orig"
objFSO.MoveFile "C:\Program Files\HP OpenView\bin\OvXpl.dll", "C:\Program Files\HP OpenView\bin\OvXpl.dll.orig"
If objFSO.FileExists("C:\Program Files\HP OpenView\bin\ovbbccborig1.exe") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\bin\ovbbccborig1.exe", True
WScript.Echo "Renaming C:\Program Files\HP OpenView\bin\ovbbccb.exe to C:\Program Files\HP OpenView\bin\ovbbccborig1.exe"
objFSO.MoveFile "C:\Program Files\HP OpenView\bin\ovbbccb.exe", "C:\Program Files\HP OpenView\bin\ovbbccborig1.exe"
If objFSO.FileExists("C:\Program Files\HP OpenView\bin\OvBbc.dll.orig") = True Then objFSO.DeleteFile "C:\Program Files\HP OpenView\bin\OvBbc.dll.orig", True
WScript.Echo "Renaming C:\Program Files\HP OpenView\bin\OvBbc.dll to C:\Program Files\HP OpenView\bin\OvBbc.dll.orig"
objFSO.MoveFile "C:\Program Files\HP OpenView\bin\OvBbc.dll", "C:\Program Files\HP OpenView\bin\OvBbc.dll.orig"

WScript.Echo "Copying C:\Hotfix\OvXpl.dll to C:\Program Files\HP OpenView\bin\OvXpl.dll"
objFSO.CopyFile "C:\Hotfix\OvXpl.dll", "C:\Program Files\HP OpenView\bin\OvXpl.dll", True
WScript.Echo "Copying C:\Hotfix\ovbbccb.exe to C:\Program Files\HP OpenView\bin\ovbbccb.exe"
objFSO.CopyFile "C:\Hotfix\ovbbccb.exe", "C:\Program Files\HP OpenView\bin\ovbbccb.exe", True
WScript.Echo "Copying C:\Hotfix\OvBbc.dll to C:\Program Files\HP OpenView\bin\OvBbc.dll"
objFSO.CopyFile "C:\Hotfix\OvBbc.dll", "C:\Program Files\HP OpenView\bin\OvBbc.dll", True

WScript.Echo "Running ovpacmd start alarm"
Set objExec = objShell.Exec("""C:\Program Files\HP OpenView\bin\ovpacmd"" start alarm")
While objExec.Status = 0
	WScript.Sleep 100
Wend
WScript.Echo objExec.StdOut.ReadAll

WScript.Echo "Running net start HPOvTrcSvc"
Set objExec = objShell.Exec("net start HPOvTrcSvc")
While objExec.Status = 0
	WScript.Sleep 100
Wend
WScript.Echo objExec.StdOut.ReadAll

WScript.Echo "Running ovc -start"
Set objExec = objShell.Exec("""C:\Program Files\HP OpenView\ovc"" -start")
While objExec.Status = 0
	WScript.Sleep 100
Wend
WScript.Echo objExec.StdOut.ReadAll

WScript.Echo "Running ovc -status"
Set objExec = objShell.Exec("""C:\Program Files\HP OpenView\ovc"" -status")
While objExec.Status = 0
	WScript.Sleep 100
Wend
WScript.Echo objExec.StdOut.ReadAll

WScript.Echo "Script complete."

Open in new window

Excellent Rob..The above script is working perfectly..you made me a star...This is what im looking for.

Superb Job..!!!
Great.  I'm glad it worked out.

Rob.