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)
FileSystemObject Vs WshShell
Moderators: JRL, Dorian (MJT support)
-
- Pro Scripter
- Posts: 58
- Joined: Thu Oct 16, 2003 12:53 am
-
- Pro Scripter
- Posts: 58
- Joined: Thu Oct 16, 2003 12:53 am
I got it... <reolved>
There is no need for the "WScript" object in front of the CreateObject method...
-
- Pro Scripter
- Posts: 58
- Joined: Thu Oct 16, 2003 12:53 am
New problem
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
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