Jump to content

Recommended Posts

Posted

Hi I have usiing WPI for a while now and decided to change the way i install my apps by using the %CDROM% command in WPI so now all my apps are In Root>Software

All the EXE and MSI file work just fine from CD but the few apps i have made.vbs file for say the cant find the file heres an example

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run ("%systemdrive%\Install\applications\Burning\Alc\setup.exe /qn REBOOT=REALLYSUPPRESS")
WScript.Sleep 19000
WshShell.SendKeys "{TAB}"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Sleep 10000
WshShell.SendKeys "{ENTER}"
WScript.Quit

Works fine but when i switch to

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run ("%CDROM%\software\applications\Burning\Alc\setup.exe /qn REBOOT=REALLYSUPPRESS")
WScript.Sleep 19000
WshShell.SendKeys "{TAB}"
WScript.Sleep 1000
WshShell.SendKeys "{ENTER}"
WScript.Sleep 10000
WshShell.SendKeys "{ENTER}"
WScript.Quit

I get erros saying it error on line 2 "cant find file" but all exe and MSI files lauch fine from WPI so what do i add to make them work? thnx for your time :)


Posted

Thats because CDROM isnt a native system variable, you need to add the following code to the beginning of your script...

Set FSO = CreateObject("Scripting.FileSystemObject")
Set AllDrives = FSO.Drives

' Check for CDROM
For Each objDrive In fso.Drives
If objDrive.DriveType = "4" And objDrive.IsReady Then
  If fso.FileExists(objDrive & "\WIN51") Then cdrom = objDrive
End If
Next

If Len(CDROM) = 0 Then
  MsgBox "Error: CD-ROM not found!",vbCritical,"Diskeeper"
  WScript.Quit
End if

NOTE: The above example assumes you have a file called 'WIN51" in the root of your cd.

Posted

@durex: Although your VBS file works, it has some errors. For example, it sets the AllDrives variable, but never uses it. Also, the message box has the title "Diskeeper" (which makes me believe you didn't write this yourself :)). Here's the right one (I also changed some things to make it a little shorter):

Set FSO = CreateObject("Scripting.FileSystemObject")

For Each Drive In FSO.Drives
  If Drive.DriveType = 4 And Drive.IsReady And FSO.FileExists(Drive & "\WIN51") Then CDROM = Drive
Next

If Len(CDROM) = 0 Then
  MsgBox "Error: CD-ROM not found!", vbCritical
  WScript.Quit
End If

Also, you can't use the variable as %CDROM% like you can in a batch file, but you'll have to use it like this:

WshShell.Run(CDROM & "\Software\Applications\Burning\Alc\setup.exe /qn REBOOT=REALLYSUPPRESS")

Posted

@Tsunami

Actually.. theyre not errors, its a cut and paste from a script which I was too lazy to edit... the variable is used later in my script and this was for a Diskeeper install, hence the msgbox title, as I customize my scripts for each program I write them for.... regardless, with or without these couple things it works.

thx for the cleaned up For Next statement

Posted

This Will Get The First CD Drive Letter.

Dim strDriveLetter
Dim intDriveLetter
Dim fs 'As Scripting.FileSystemObject
Const CDROM = 4
On Error Resume Next
Set fs = CreateObject("Scripting.FileSystemObject")
strDriveLetter = ""
For intDriveLetter = Asc("A") To Asc("Z")
Err.Clear
If fs.GetDrive(Chr(intDriveLetter)).DriveType = CDROM Then
If Err.Number = 0 Then
strDriveLetter = Chr(intDriveLetter)
Exit For
End If
End If
Next
L=MsgBox ("Your Cd Is: " & strDriveLetter,vbokonly+48,"The Cd Is: " & strDriveLetter )
wscript.quit

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...