Jump to content

Problem with getting a .vbs to run cdrom at startup


Recommended Posts

Hi!

I have created following:

Dim Reg

Set Reg = CreateObject("wscript.shell")

Reg.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUNONCE\" & "NAME", "PATH" & "\" & "NAME" & ".vbs"

With that .vbs file I want to run a .bat on a cdrom at startup in windows, is that possible? The problem is that I can not be sure that the CDrom drives "path" is the same all the time so I need a loop untill the script finds the right path, please help me!! :)

And if its possible to do that, how can the script understand that the cd drive is mounted at the startup, if the cdrom drive is not "mounted" then the script wont run. I know I can use Wscipt.sleep but will that work?

I have tried

Set objShell = CreateObject("WScript.Shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.DriveExists("D:\") Then

objShell.Run("D:\Name.bat")

ElseIf objFSO.DriveExists("E:\") Then

objShell.Run("E:\Name.bat")

'and so on and so on

End If

But it wont go, please help me :(

Link to comment
Share on other sites


Try this VBS script

Save as RunFrom_CDDVD.vbs

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Act : Set Act = CreateObject("Wscript.Shell")
Dim Drv, StrD
Set Drv = Fso.Drives
For Each StrD In Drv
If StrD.DriveType = 4 Then
If StrD.IsReady = True Then
'/-> PLACE THE FILE NAME THAT YOU WANT TO CHECK FOR HERE
If Fso.FileExists(StrD & "\SETUP.EXE") Then
WScript.Echo "Confirm " & StrD & "\SETUP.EXE"
'/-> RUNS THE FILE FROM THE CD OR DVD DRIVE UNCOMMENT TO MAKE ACTIVE
' Act.Run("%Comspec% /C " & StrD & "\Name.bat"), 1, True
End If
End If
End If
Next

Link to comment
Share on other sites

Hi..

I manage to complete the script and this is it.

This installation is either to a laptop or a desktop thats why i use temp1.txt or temp2.txt to locate witch installation that needs to be installed..

All scripts exists on a CD at the begining, and the user only needs to puch one buttom :)

And the first script is for desktop users.. bind with a buttom on the cd_startmenu

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("WScript.Shell")
Set Reg = CreateObject("wscript.shell")

Dim objFSO
Dim objShell
Dim Reg

If objFSO.FolderExists("C:\Program Files\F-Secure")Then
Reg.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUNONCE\" & "cd", "C:\" & "runcd" & ".vbs"
objShell.Run("uninstall.exe /S")
objFSO.CreateTextFile("C:\Temp1.txt")
Set objFileCopy = objFSO.GetFile("runcd.vbs")
objFileCopy.Copy ("C:\runcd.vbs")
Else
objShell.Run("ILAUNCHR.EXE jar\install_desktop.jar /U /C")
End If

This is the script that the erlier script puts out to C:\..

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Act : Set Act = WScript.CreateObject("Wscript.Shell")
Dim Drv, StrD, Drive

Set Drv = Fso.Drives
For Each StrD In Drv
If StrD.DriveType = 4 Then
If StrD.IsReady = True Then
If Fso.FileExists(StrD & "\runcd.vbs") Then
Set Drive = StrD
If Fso.FileExists("C:\Temp1.txt") Then
Act.Run(StrD & "\ILAUNCHR.EXE " & StrD & "\jar\install_desktop.jar /C /U")
Fso.DeleteFile("C:\Temp1.txt")
End If
If Fso.FileExists("C:\Temp2.txt") Then
Act.run(StrD & "\ILAUNCHR.EXE´" & StrD & "\jar\install_laptop.jar /C /U")
Fso.DeleteFile("C:\Temp2.txt")
End If
End If
End If
End If
Next
Set Drv = Fso.Drives
For Each StrD In Drv
If StrD.DriveType = 4 Then
If StrD.IsReady = True Then
Set Drive = StrD
Act.Run(StrD & "\cleanup.vbs")
End If
End If
Next

And this script is the cleanup.vbs :)

Dim Fso
Set Fso = CreateObject("Scripting.FileSystemObject")
Do Until i = IsReady
i = ("C:\runcd.vbs")
Loop
Fso.DeleteFile("C:\runcd.vbs"), True

Well thats it folks.. thx for the help gunsmokingman B)

And yes im not the perfect man on this job but i did it, and there is some lines that i dont need at all.. but i will keep it there :) Its working and Im happy B)

Link to comment
Share on other sites

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...