Link to home
Start Free TrialLog in
Avatar of Singnetsvc
Singnetsvc

asked on

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

Avatar of sr75
sr75
Flag of United States of America image

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

Avatar of Singnetsvc
Singnetsvc

ASKER

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

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

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
ASKER CERTIFIED SOLUTION
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