glent Posted December 28, 2004 Posted December 28, 2004 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>SoftwareAll 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 exampleSet WshShell = WScript.CreateObject("WScript.Shell")WshShell.Run ("%systemdrive%\Install\applications\Burning\Alc\setup.exe /qn REBOOT=REALLYSUPPRESS")WScript.Sleep 19000WshShell.SendKeys "{TAB}"WScript.Sleep 1000WshShell.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 19000WshShell.SendKeys "{TAB}"WScript.Sleep 1000WshShell.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
durex Posted December 28, 2004 Posted December 28, 2004 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 CDROMFor Each objDrive In fso.Drives If objDrive.DriveType = "4" And objDrive.IsReady Then If fso.FileExists(objDrive & "\WIN51") Then cdrom = objDrive End IfNextIf Len(CDROM) = 0 Then MsgBox "Error: CD-ROM not found!",vbCritical,"Diskeeper" WScript.QuitEnd ifNOTE: The above example assumes you have a file called 'WIN51" in the root of your cd.
Radimus Posted December 28, 2004 Posted December 28, 2004 %cdrom% isn't a system variable, it doesn't exist until a value is set to it
Tsunami Posted December 28, 2004 Posted December 28, 2004 @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 = DriveNextIf Len(CDROM) = 0 Then MsgBox "Error: CD-ROM not found!", vbCritical WScript.QuitEnd IfAlso, 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")
durex Posted December 28, 2004 Posted December 28, 2004 @TsunamiActually.. 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
gunsmokingman Posted December 28, 2004 Posted December 28, 2004 This Will Get The First CD Drive Letter. Dim strDriveLetterDim intDriveLetterDim fs 'As Scripting.FileSystemObjectConst CDROM = 4On Error Resume NextSet fs = CreateObject("Scripting.FileSystemObject")strDriveLetter = ""For intDriveLetter = Asc("A") To Asc("Z")Err.ClearIf fs.GetDrive(Chr(intDriveLetter)).DriveType = CDROM ThenIf Err.Number = 0 ThenstrDriveLetter = Chr(intDriveLetter)Exit ForEnd IfEnd IfNextL=MsgBox ("Your Cd Is: " & strDriveLetter,vbokonly+48,"The Cd Is: " & strDriveLetter )wscript.quit
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now