We’d like to remind Forumites to please avoid political debate on the Forum.
This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
Open disk tray script.
A:I
Posts: 500 Forumite
in Techie Stuff
i have seen a website with a 'free cup holder' where the disk tray opens. I was wondering if anyone knows the script that opens it so i can do something simular. Thanks,
A:I:beer: :beer:
A:I:beer: :beer:
0
Comments
-
Copy code below into Notepad and save as a .vbs file.
'OpenCDdrive.vbs option explicit dim oShell, fso, drive, dl const unknowntype = 0 const removable = 1 const fixed = 2 const remote = 3 const cdrom = 4 const ramdisk = 5 const ssfDrives = 17 set fso = createobject("Scripting.FileSystemObject") Set oShell = CreateObject("Shell.Application") for each drive in fso.Drives if drive.DriveType = cdrom then dl = drive.DriveLetter + ":" oShell.NameSpace(ssfDrives).ParseName(dl).InvokeVerb "E&ject" end if next0 -
it says there is a problem with line 22 or something to do with the 'name space' thingy?
It says objects required?0 -
Ahh, sugar! How that bug creep in? :rolleyes:
change line:
dl = drive.DriveLetter + ":"
to:
dl = drive.DriveLetter + ":\"0 -
i'll try it..0
-
can you post the whole code, completed with the 'name space' etcc filled in. i don't get it lol
Thankyu0 -
Version 1.1 beta:
'OpenCDdrive.vbs Option Explicit Dim oShell, fso, drive, dl const unknowntype = 0 const removable = 1 const fixed = 2 const remote = 3 const cdrom = 4 const ramdisk = 5 const ssfDRIVES = &H11 set fso = createobject("Scripting.FileSystemObject") Set oShell = CreateObject("Shell.Application") for each drive in fso.Drives if drive.DriveType = cdrom then 'Open CD tray dl = drive.DriveLetter + ":\" oShell.NameSpace(ssfDRIVES).ParseName(dl).InvokeVerb "E&ject" end if next0 -
oooooo! i love you man!0
-
by the way, how would i embed this into a web age so it runs the script online on that page?0
-
hello?????0
-
It won't work as a HTML page on a web site because the line:
oShell.NameSpace(ssfDRIVES).ParseName(dl).InvokeVerb "E&ject"
accesses the local machine and security restrictions in browsers prevent this type of code from running.
The best you can do is save it as .hta file on your computer and open that in your browser. A .hta file is the same as a .htm file except it bypasses the browser's security restrictions when run on the local machine.
Save the following as OpenCDdrive.hta:<html> <head> <script for="OpenCDdrive" language="VBScript"> <!-- Sub OpenCDdrive_OnClick Dim oShell, fso, drive, dl const cdrom = 4 const ssfDRIVES = &H11 set fso = CreateObject("Scripting.FileSystemObject") Set oShell = CreateObject("Shell.Application") for each drive in fso.Drives if drive.DriveType = cdrom then 'Open CD tray dl = drive.DriveLetter + ":\" oShell.NameSpace(ssfDRIVES).ParseName(dl).InvokeVerb "E&ject" end if next End Sub --> </script> </head> <body> <p>Click the button to open the CD tray(s)</p> <input type="button" value="Open" name="OpenCDdrive" event="onClick"> </body> </html>0
This discussion has been closed.
Confirm your email address to Create Threads and Reply
Categories
- All Categories
- 352.1K Banking & Borrowing
- 253.5K Reduce Debt & Boost Income
- 454.2K Spending & Discounts
- 245.1K Work, Benefits & Business
- 600.7K Mortgages, Homes & Bills
- 177.5K Life & Family
- 258.9K Travel & Transport
- 1.5M Hobbies & Leisure
- 16.2K Discuss & Feedback
- 37.6K Read-Only Boards