VB Script - Fails full execution first run, prompts empty box seconond rum

Hi All

I am currently working on a online avaliable script which takes a shadow backup of virtual images attached to virtual server. My Issue is that the script does not run full function first attempt, but displays an empty box with an OK botton on second attempt.

The script creates two windows command line files, if they dont exist on first run, the second half of the script fail to run. If they do exist, a bocx with an OK button appears whcih must be pressed in order to have the script continue and complete.  My issue is that i need to identify what is causing the empty box and how do i get rid of it so that teh script can complete.

The code that i believe is having the issue is below

Regards, Alan




Set objVM = Nothing
 
' Create Shadow copy of VM drive
oExCmd.WriteLine "vshadow.exe -script=setvar1.cmd -p d:"
oExCmd.WriteLine "call setvar1.cmd"
oExCmd.WriteLine "vshadow.exe -el=%SHADOW_ID_1%,x:"
oExCmd.Close
Result = objShell.run(sExCmd,vbMinimized, TRUE)
 
'BOX APPEARS HERE'
 
' Start VM machine up from saved state
For each objVM in virtualServer.VirtualMachines
    'See if vm machine is Saved. If so then resume
    If objVM.State = 2 then
        'Start virtual machine
            objVM.Startup
    End If
Next
Set objVM = Nothing
WScript.Sleep 10000
 
 
If Result = 0 then
'Loop through all vm machines
    For each objVM in virtualServer.VirtualMachines
        'See if vm machine is running. If so copy shadow backup of vm disk drives
        If objVM.State = 5 then
 
            'Copy virtual hard disks and undo disks
            For each vhd in objVM.HardDiskConnections
                MyArray = Split(vhd.undoHardDisk.file,"\")
                Filename = MyArray(Ubound(MyArray))
                SourceName = "x" & Right(vhd.undoHardDisk.file,Len(vhd.undoHardDisk.file)-1)
                wscript.echo vhd.undoHardDisk.file
                wscript.echo SourceName
                objFSO.CopyFile SourceName,DestBackupDir & Filename
                MyArray = Split(vhd.HardDisk.file,"\")
                Filename = MyArray(Ubound(MyArray))
                SourceName = "x" & Right(vhd.HardDisk.file,Len(vhd.HardDisk.file)-1)
                objFSO.CopyFile SourceName,DestBackupDir & Filename
            Next
 
        End If

Open in new window

LVL 3
SingnetsvcAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sr75Commented:
It may be due to the fact that the VBScript isn't waiting to finish the shadow copy before moving on.  Try using a different method of running dos commands.  here is what I do for Ping.  I do that so that I can have much more informative data then a simple succeed or fail.
Function ping(Server)
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	'
	'  This function will Ping a computer and output a TRUE 
	'  for a successful ping, or FALSE for after two failures.
	'
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
	DIM WShell,objExec,strPingResults
 
 
	set WShell = CreateObject("WScript.Shell")
	set objExec = WShell.Exec("ping -n 2 -w 1000 " & Server)
	strPingResults = LCase(objExec.StdOut.ReadAll)
	If InStr(strPingResults, "reply from") then
		ping = TRUE
	else
		wscript.sleep 15000
	
		set objExec = WShell.Exec("ping -n 2 -w 1000 " & Server)
		strPingResults = LCase(objExec.StdOut.ReadAll)
		If InStr(strPingResults, "reply from") then
			ping = TRUE
		else
			
			ping = FALSE
		End If
	End If
	
	set WShell = Nothing
	set objExec = Nothing
	set strPingResults = Nothing
 
End Function

Open in new window

0
SingnetsvcAuthor Commented:
I dont know if this wil help, but i have observered the following behaviour

The x drive is created
The script waits for the creation copy of the VSV and VMC file to be coped. After a delay, the prompt appears with no text. Once the OK option is selected immediatly the VHD file shows up in teh backup  

I have a huncht that the attached code is the issue. How do i stop prompts from appearing.

Regards, Alan



Result = objShell.run(sExCmd,vbMinimized, TRUE)

Open in new window

0
SingnetsvcAuthor Commented:
Actually i retract that. The images start up then the prompt appears  after the following delay


WScript.Sleep 10000
 
 
If Result = 0 then
'Loop through all vm machines
    For each objVM in virtualServer.VirtualMachines
        'See if vm machine is running. If so copy shadow backup of vm disk drives
        If objVM.State = 5 then
 
            'Copy virtual hard disks and undo disks
            For each vhd in objVM.HardDiskConnections
                MyArray = Split(vhd.undoHardDisk.file,"\")
                Filename = MyArray(Ubound(MyArray))
                SourceName = "x" & Right(vhd.undoHardDisk.file,Len(vhd.undoHardDisk.file)-1)
                wscript.echo vhd.undoHardDisk.file
                wscript.echo SourceName
                objFSO.CopyFile SourceName,DestBackupDir & Filename
                MyArray = Split(vhd.HardDisk.file,"\")
                Filename = MyArray(Ubound(MyArray))
                SourceName = "x" & Right(vhd.HardDisk.file,Len(vhd.HardDisk.file)-1)
                objFSO.CopyFile SourceName,DestBackupDir & Filename
            Next
 
        End If

Open in new window

0
RobSampsonCommented:
Hi, this section does not look quite right to me:

' Create Shadow copy of VM drive
oExCmd.WriteLine "vshadow.exe -script=setvar1.cmd -p d:"
oExCmd.WriteLine "call setvar1.cmd"
oExCmd.WriteLine "vshadow.exe -el=%SHADOW_ID_1%,x:"
oExCmd.Close
Result = objShell.run(sExCmd,vbMinimized, TRUE)

I can't see the part where you actually create oExCmd, but I'm guessing it's something like
Set oExCmd = objFSO.CreateTextFile("somefile.bat",  True)

Or it may be:
Set oExCmd = objShell.Exec("cmd")

I would go with the first option. Rather that try to output commands directly to a command prompt, I would output the commands to a batch file, and Run that.

' Create Shadow copy of VM drive
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("somefile.bat",  True)
' Get the path to the new batch file
strFilePath = objFile.ShortPath
objFile.WriteLine "vshadow.exe -script=setvar1.cmd -p d:"
objFile.WriteLine "call setvar1.cmd"
objFile.WriteLine "vshadow.exe -el=%SHADOW_ID_1%,x:"
objFile.Close
Result = objShell.Run("cmd /k " & strFilePath,vbMinimized, TRUE)
objFSO.DeleteFile strFilePath, True


And, with cmd /k, the command prompt will stay open, so you can see output.  When finished testing, change that to cmd /c.

Regards,

Rob.
0
SingnetsvcAuthor Commented:
HI Rob. You are correct. the oExCmd is created earlier in the script. I should have posted the whole script

My issue was simply that there was an echo with no value to output. As i have never dealth mwith VB before i  had taken me a while to determine this command.

The Issues was in the code belowe
The full script for future reference is here  http://cwashington.netreach.net/depo/view.asp?Index=1049

Although there was no correct answers provided, Rob wil be given teh points for most descriptive answer
 wscript.echo vhd.undoHardDisk.file
                wscript.echo SourceName

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.