473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Close CD Tray with VBScript

118 100+
Hey, hey.

I have written a script in VB to open the CD Tray

Expand|Select|Wrap|Line Numbers
  1. <script language="VBScript">
  2. <!--
  3. Sub Eject()
  4. Set oWMP = CreateObject("WMPlayer.OCX.7" )
  5. Set colCDROMs = oWMP.cdromCollection
  6.  
  7. if colCDROMs.Count >= 1 then
  8.         For i = 0 to colCDROMs.Count - 1
  9.                 colCDROMs.Item(i).Eject
  10.         Next ' cdrom
  11. End If
  12.  End Sub
  13. -->
  14. </script>
  15.  
and have got it to run on the click of a button.

Any ideas on how, using the same Idea (or a completely different one) I would get the VBScript to close the CD Tray again?

Sam
Apr 27 '07 #1
4 15911
Sadly, I'm not sure that it's actually possible using the same way as you specified. However, you could always write your own .ocx file and load that the same way as you did the other. :)
Apr 28 '07 #2
helraizer1
118 100+
I managed to do it. Using the same code;

Expand|Select|Wrap|Line Numbers
  1. <script language="VBScript">
  2. <!--
  3. Sub Close()
  4. Set oWMP = CreateObject("WMPlayer.OCX.7" )
  5. Set colCDROMs = oWMP.cdromCollection
  6.  
  7. if colCDROMs.Count >= 1 then
  8.         For i = 0 to colCDROMs.Count - 1
  9.                 colCDROMs.Item(i).Eject
  10.         Next ' cdrom
  11.  
  12.     For i = 0 to colCDROMs.Count - 1
  13.         colCDROMs.Item(i).Eject
  14.     Next
  15. End If
  16.  End Sub
  17. -->
  18. </script>
  19.  
This repeated section at the end of the code closes the CD tray.

Sam
Apr 30 '07 #3
Easy way to open cd drive with three line Statements :
Expand|Select|Wrap|Line Numbers
  1. Set creatingwscript = WScript.CreateObject("wscript.Shell")
  2. Set play = CreateObject("WMPlayer.ocx")
  3. play.cdromCollection.item(0).Eject()
  4.  
  1. Open notepad
  2. Paste the above Visual Basic Code
  3. Save the notepad with (any name).vbs format
  4. Double Click to see ur cd drive tray to open.


by ur >Just
Sep 21 '13 #4
Dim ts
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
Set oWMP = CreateObject("WMPlayer.OCX.7" )
Set colCDROMs = oWMP.cdromCollection

if colCDROMs.Count >= 1 then
For i = 0 to colCDROMs.Count - 1
colCDROMs.Item(i).Eject
Next ' cdrom

For i = 0 to colCDROMs.Count - 1
colCDROMs.Item(i).Eject
Next
set owmp = nothing
set colCDROMs = nothing
end if
Dec 7 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Shawn | last post by:
Hi. I've created an application that can run in the system tray. The way it works now I have to click a button to "send" the application to the system tray, but I want the application to run in...
1
by: Kevin White | last post by:
Hi all, I have a program that has this basic flow: 1- Splash screen opens and creates a system tray icon (the splash screen is the main form that is started on program execution, and stays...
12
by: Patrick Dugan | last post by:
I have an vb.net application that is a module that uses a "application.run" in the sub main to start. There is no form involved (just a system tray icon) How can you detect when the application...
5
by: smarty | last post by:
I have an example of code that allows and application to minise to the notification tray but how can I override the minimise and close buttons to ensure they always go back to the notify tray...
0
by: Sidney | last post by:
Dear, I am writting a system which opened at the system tray. But every before I shut down my computer, I have to close the system first. However, it should be automatically close when I shutting...
0
by: Cachaca | last post by:
Hi. I tried to detect all running user applications (no all processes) and close them all. Obviously this is a usual function that has been existing in many programs. I used the ::EnumWindows...
7
nunoperalta
by: nunoperalta | last post by:
Hi! I'm developing an HTA program, with HTML, CSS, JavaScript and VBScript. It's possible to put my HTA in system tray, with an icon and menu? (If possible, using JavaScript or VBScript) ...
3
by: vinoj1100 | last post by:
Can anyone tell me how can i place an icon in system tray using JavaScript, i know how to do it in VB but not in javascript or in VBscript. PLz help me out...
22
by: rottmanj | last post by:
I am working on an app that I need to minimize/close to the system tray. More or less I have the minimize to the system tray working, save caveat. When it is minimized the application still...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.