Re: Error handling and event loggin for command line within script by ESP
ESP
Thu Nov 10 15:45:10 CST 2005
Naaa, the code looks great. Bottom line: You cant trap an error if an app
isn't coded to return an error code. There is nothing you can do that I know
of. Error codes are not specific to VBS in this sense. VBS is the wrapper,
and it watches the app to see if anything shoots out of it by way of an
error. If you're getting a 0, then the app is outputting a 0 no matter what.
It's simply the way some apps are written.
ESP
"xr7" wrote:
> I think the 0 is vbscript's error code saying "successfully initiated
> the command" It logs it as soon as the exe is launched.
> What I need is the exe's termination result. IE. failed because file
> is in use, or permission denied, or completed successfully.
> The app is vmware-vdiskmanager.exe, a utility to work with virtual
> disks for vmware virtual machines.
> Here is the code for the script that works. Please don't make fun of
> my sloppy code, it's my 2nd script ever :P
> varVMpath = "C:\Virtual Machine\"
> varMountPoint = "V:"
>
> 'Create collection of Virtual Machines by reading subfolder names below
> the varVMpath specified above
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFolder = objFSO.GetFolder(varVMpath)
> Set colSubfolders = objFolder.Subfolders
>
> 'Begin For Each loop
> For Each objSubfolder in colSubfolders
>
> 'Build path to Virtual disks
> strVMname = varVMpath & objSubfolder.Name & "\" & objSubfolder.Name
> strVolC = strVMname & ".vmdk"
> strVolE = strVMname & "e.vmdk"
> strVolF = strVMname & "f.vmdk"
>
> 'Defragment C
> Set objVMDK = CreateObject("Scripting.FileSystemObject")
> If objVMDK.FileExists(strVolC) Then
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMware
> Workstation\vmware-vdiskmanager.exe"" -d """ & strVolC & """",,True
> End If
> Set objWShell = nothing
> Set objVMDK = nothing
>
> 'Defragment E
> Set objVMDK = CreateObject("Scripting.FileSystemObject")
> If objVMDK.FileExists(strVolE) Then
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMware
> Workstation\vmware-vdiskmanager.exe"" -d """ & strVolE & """",, True
> End If
> Set objWShell = nothing
> Set objVMDK = nothing
>
> 'Defragment F
> Set objVMDK = CreateObject("Scripting.FileSystemObject")
> If objVMDK.FileExists(strVolF) Then
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMware
> Workstation\vmware-vdiskmanager.exe"" -d """ & strVolF & """",, True
> End If
> Set objWShell = nothing
> Set objVMDK = nothing
>
> 'Mount C
> Set objVMDK = CreateObject("Scripting.FileSystemObject")
> If objVMDK.FileExists(strVolC) Then
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMware DiskMount
> Utility\vmware-mount.exe""" & " " & varMountPoint & " """ & strVolC &
> """",,True
>
> 'Preshrink C
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMWare
> Workstation\vmware-vdiskmanager.exe"" -p " & " " & varMountPoint,,True
>
> 'Dismount C
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMware DiskMount
> Utility\vmware-mount.exe""" & " " & varMountPoint & " " & "/d",,True
> End if
> Set objWShell = nothing
> Set objVMDK = nothing
>
> 'Mount E
> Set objVMDK = CreateObject("Scripting.FileSystemObject")
> If objVMDK.FileExists(strVolC) Then
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMware DiskMount
> Utility\vmware-mount.exe""" & " " & varMountPoint & " """ & strVolE &
> """",,True
>
> 'Preshrink E
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMWare
> Workstation\vmware-vdiskmanager.exe"" -p " & " " & varMountPoint,,True
>
> 'Dismount E
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMware DiskMount
> Utility\vmware-mount.exe""" & " " & varMountPoint & " " & "/d",,True
> End if
> Set objWShell = nothing
> Set objVMDK = nothing
>
> 'Mount F
> Set objVMDK = CreateObject("Scripting.FileSystemObject")
> If objVMDK.FileExists(strVolC) Then
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMware DiskMount
> Utility\vmware-mount.exe""" & " " & varMountPoint & " """ & strVolF &
> """",,True
>
> 'Preshrink F
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMWare
> Workstation\vmware-vdiskmanager.exe"" -p " & " " & varMountPoint,,True
>
> 'Dismount F
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMware DiskMount
> Utility\vmware-mount.exe""" & " " & varMountPoint & " " & "/d",,True
> End if
> Set objWShell = nothing
> Set objVMDK = nothing
>
> 'Shrink C
> Set objVMDK = CreateObject("Scripting.FileSystemObject")
> If objVMDK.FileExists(strVolC) Then
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMware
> Workstation\vmware-vdiskmanager.exe"" -k """ & strVolC & """",,True
> End If
> Set objWShell = nothing
> Set objVMDK = nothing
>
> 'Srhink E
> Set objVMDK = CreateObject("Scripting.FileSystemObject")
> If objVMDK.FileExists(strVolE) Then
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMware
> Workstation\vmware-vdiskmanager.exe"" -k """ & strVolE & """",, True
> End If
> Set objWShell = nothing
> Set objVMDK = nothing
>
> 'Shrink F
> Set objVMDK = CreateObject("Scripting.FileSystemObject")
> If objVMDK.FileExists(strVolF) Then
> Set objWShell = CreateObject("WScript.Shell")
> objWshell.Run """C:\Program Files\VMware\VMware
> Workstation\vmware-vdiskmanager.exe"" -k """ & strVolF & """",, True
> End If
> Set objWShell = nothing
> Set objVMDK = nothing
>
> 'Return to the beginning of For Each loop
> Next
>
> wscript.echo "Shrinking complete"
>
>