FileSystemObject Vs WshShell

General Macro Scheduler discussion

Moderators: JRL, Dorian (MJT support)

Post Reply
BlackWisdom
Pro Scripter
Posts: 58
Joined: Thu Oct 16, 2003 12:53 am

FileSystemObject Vs WshShell

Post by BlackWisdom » Fri Dec 31, 2004 7:08 pm

Im trying to start an exe file in a VBScript using WSHell but Macro Sceduler does not like it. I keep getting a "Object Required" error. It works fine when I run the vbs file from the desktop. I dont get the error when I use the FileSystemObject, unfortunatley I cant seem to find a command in fso that supports starting an external exe file. Basically Im detecting the CD drive from the list of drives in the system and then starting the exe file on the CD and then starting the exe file. everything works until I make the Set WshShell = WScript.CreateObject("WScript.Shell") command any suggestions?? Here is the script

VBSTART
'Beginning of script (RestoreCdData.vbs)
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

Dim CDDRIVE

If GenerateDriveInformation(FSO) Then
Call CopyFiles(DrivePath)
Else WshShell.Run("NoCDInDrive.exe")
End If

Function ShowDriveType(drvpath)
Dim fso, d, t
Set fso = CreateObject("Scripting.FileSystemObject")
Set d = fso.GetDrive(drvpath)
Select Case d.DriveType
Case 0: t = "Unknown"
Case 1: t = "Removable"
Case 2: t = "Fixed"
Case 3: t = "Network"
Case 4: t = "CD-ROM"
Case 5: t = "RAM Disk"
End Select
ShowDriveType = t
End Function

Function GenerateDriveInformation(FSO)
Dim Drives
Dim Drive
Dim S

Set Drives = FSO.Drives
For Each Drive In Drives
If ShowDriveType(Drive) = "CD-ROM" Then
S = "True"
CDDRIVE = Drive.Path
If Drive.IsReady Then
S = "True"
Else S = "False"
End If
End If
Next
GenerateDriveInformation = S
End Function

Function CopyFiles(DrivePath)
Set WshShell = WScript.CreateObject("WScript.Shell")
'echo Type the exe file that restores the files between the quotes.
WshShell.Run ("\CUI\EXE\test.exe")
End Function

'End of script (RestoreCdData.vbs)
VBEND
VBRun>ShowDriveType(drvpath)

BlackWisdom
Pro Scripter
Posts: 58
Joined: Thu Oct 16, 2003 12:53 am

I got it... <reolved>

Post by BlackWisdom » Fri Dec 31, 2004 7:49 pm

There is no need for the "WScript" object in front of the CreateObject method...

BlackWisdom
Pro Scripter
Posts: 58
Joined: Thu Oct 16, 2003 12:53 am

New problem

Post by BlackWisdom » Fri Dec 31, 2004 9:23 pm

I can get a .doc to run no problem - but I can t get a exe file to run I get path not found - or an error with a series of numbers

here is the script that throws the path not found error - its attempting to locate an exe file on the CD Drive (referened in above script)

Function CopyFiles(DrivePath)
Set WshShell = CreateObject("WScript.Shell")
'echo Type the exe file that restores the files between the quotes.
WshShell.Run "\GoldenHawk\aspi_471a2.exe"
End Function

again it works fine if I replace the exe file with a .doc file (also located on the CD) I have also tried the WshShell.Exec command - same results

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts