Open/close the CD drive with a bat
Solved
freeze
-
LIAMSI3456 -
LIAMSI3456 -
Hello,
what is the command that allows you to open/close the CD drive in a batch file or another language supported by Windows (since I don't have any compilers)
thank you
what is the command that allows you to open/close the CD drive in a batch file or another language supported by Windows (since I don't have any compilers)
thank you
Configuration: Windows XP Internet Explorer 6.0
24 réponses
- 1
- 2
Suivant
Hi, I found something,
you can launch a .vbs from your bat to open the drive (not close it)
here's the vbs
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
End If
you can launch a .vbs from your bat to open the drive (not close it)
here's the vbs
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
End If
Selim
Thank you
Hello to open and then close your drive but if it is already open it closes it...
I found this VBS tutorial
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
colCDROMs.Item(d).Eject
End If
msgbox "hamza your cd rom is closed"
and on cmd I found this
echo off && Cls && Mode 55,5 && Color 4f && Title Open Cd
Set VBS=%systemdrive%\OpenClose.vbs
Set VBS1=%systemdrive%\RemoveVBS.vbs
echo Preparing To Run The Script!
>> %vbs% Echo Dim ts
>> %vbs% Echo Dim strDriveLetter
>> %vbs% Echo Dim intDriveLetter
>> %vbs% Echo Dim fs 'As Scripting.FileSystemObject
>> %vbs% Echo Const CDROM = 4
>> %vbs% Echo On Error Resume Next
>> %vbs% Echo Set fs = CreateObject("Scripting.FileSystemObject")
>> %vbs% Echo strDriveLetter = ""
>> %vbs% Echo For intDriveLetter = Asc("D") To Asc("Z")
>> %vbs% Echo Err.Clear
>> %vbs% Echo If fs.GetDrive(Chr(intDriveLetter)).DriveType = CDROM Then
>> %vbs% Echo If Err.Number = 0 Then
>> %vbs% Echo strDriveLetter = Chr(intDriveLetter)
>> %vbs% Echo Exit For
>> %vbs% Echo End If
>> %vbs% Echo End If
>> %vbs% Echo Next
>> %vbs% Echo MSGBOX "YOUR CD IS: " ^& strDriveLetter,0 + 48,"CDROM=> " ^& strDriveLetter
>> %vbs% Echo Set oWMP = CreateObject("WMPlayer.OCX.7" )
>> %vbs% Echo Set colCDROMs = oWMP.cdromCollection
>> %vbs% Echo colCDROMs.Item(d).Eject
>> %vbs% Echo A1= msgbox ("Press key To Close Cd" ^& vbcrlf ^& "The Cd Will Close", 0 + 64, "Open Close Cd Tray")
>> %vbs% Echo colCDROMs.Item(d).Eject
>> %vbs% Echo set owmp = nothing
>> %vbs% Echo set colCDROMs = nothing
>> %vbs% Echo wscript.quit
start %vbs%
ping -n 12 127.0.0.1>nul
TASKKILL /F /T /IM Wscript.exe
TASKKILL /F /T /IM Wmiprvse.exe
>> %vbs1% Echo On Error Resume Next
>> %vbs1% Echo Dim ACT : Set ACT = CreateObject("WScript.Shell")
>> %vbs1% Echo Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
>> %vbs1% Echo Loc = ACT.ExpandEnvironmentStrings("%SystemDrive%")
>> %vbs1% Echo Fso.Deletefile("%VBS%")
>> %vbs1% Echo Fso.Deletefile(Loc ^& "\CD-Open-Close.cmd")
>> %vbs1% Echo Fso.Deletefile("%VBS1%")
>> %vbs1% Echo Set ACT = Nothing
>> %vbs1% Echo Set Fso = Nothing
start /w %vbs1%
exit
we can use the same dos method with the first script I will test it and if it works I will send you the code
@+
I found this VBS tutorial
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
colCDROMs.Item(d).Eject
End If
msgbox "hamza your cd rom is closed"
and on cmd I found this
echo off && Cls && Mode 55,5 && Color 4f && Title Open Cd
Set VBS=%systemdrive%\OpenClose.vbs
Set VBS1=%systemdrive%\RemoveVBS.vbs
echo Preparing To Run The Script!
>> %vbs% Echo Dim ts
>> %vbs% Echo Dim strDriveLetter
>> %vbs% Echo Dim intDriveLetter
>> %vbs% Echo Dim fs 'As Scripting.FileSystemObject
>> %vbs% Echo Const CDROM = 4
>> %vbs% Echo On Error Resume Next
>> %vbs% Echo Set fs = CreateObject("Scripting.FileSystemObject")
>> %vbs% Echo strDriveLetter = ""
>> %vbs% Echo For intDriveLetter = Asc("D") To Asc("Z")
>> %vbs% Echo Err.Clear
>> %vbs% Echo If fs.GetDrive(Chr(intDriveLetter)).DriveType = CDROM Then
>> %vbs% Echo If Err.Number = 0 Then
>> %vbs% Echo strDriveLetter = Chr(intDriveLetter)
>> %vbs% Echo Exit For
>> %vbs% Echo End If
>> %vbs% Echo End If
>> %vbs% Echo Next
>> %vbs% Echo MSGBOX "YOUR CD IS: " ^& strDriveLetter,0 + 48,"CDROM=> " ^& strDriveLetter
>> %vbs% Echo Set oWMP = CreateObject("WMPlayer.OCX.7" )
>> %vbs% Echo Set colCDROMs = oWMP.cdromCollection
>> %vbs% Echo colCDROMs.Item(d).Eject
>> %vbs% Echo A1= msgbox ("Press key To Close Cd" ^& vbcrlf ^& "The Cd Will Close", 0 + 64, "Open Close Cd Tray")
>> %vbs% Echo colCDROMs.Item(d).Eject
>> %vbs% Echo set owmp = nothing
>> %vbs% Echo set colCDROMs = nothing
>> %vbs% Echo wscript.quit
start %vbs%
ping -n 12 127.0.0.1>nul
TASKKILL /F /T /IM Wscript.exe
TASKKILL /F /T /IM Wmiprvse.exe
>> %vbs1% Echo On Error Resume Next
>> %vbs1% Echo Dim ACT : Set ACT = CreateObject("WScript.Shell")
>> %vbs1% Echo Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
>> %vbs1% Echo Loc = ACT.ExpandEnvironmentStrings("%SystemDrive%")
>> %vbs1% Echo Fso.Deletefile("%VBS%")
>> %vbs1% Echo Fso.Deletefile(Loc ^& "\CD-Open-Close.cmd")
>> %vbs1% Echo Fso.Deletefile("%VBS1%")
>> %vbs1% Echo Set ACT = Nothing
>> %vbs1% Echo Set Fso = Nothing
start /w %vbs1%
exit
we can use the same dos method with the first script I will test it and if it works I will send you the code
@+
Good evening
I am not an expert and I also copied this script from another forum [sorry, I don't remember the link]
you can simply delete it if the start command is in the line
start %vbs% and the script will be:
echo off && Cls && Mode 55,5 && Color 4f && Title Open Cd
Set VBS=%systemdrive%\OpenClose.vbs
Set VBS1=%systemdrive%\RemoveVBS.vbs
echo Preparing To Run The Script!
>> %vbs% Echo Dim ts
>> %vbs% Echo Dim strDriveLetter
>> %vbs% Echo Dim intDriveLetter
>> %vbs% Echo Dim fs 'As Scripting.FileSystemObject
>> %vbs% Echo Const CDROM = 4
>> %vbs% Echo On Error Resume Next
>> %vbs% Echo Set fs = CreateObject("Scripting.FileSystemObject")
>> %vbs% Echo strDriveLetter = ""
>> %vbs% Echo For intDriveLetter = Asc("D") To Asc("Z")
>> %vbs% Echo Err.Clear
>> %vbs% Echo If fs.GetDrive(Chr(intDriveLetter)).DriveType = CDROM Then
>> %vbs% Echo If Err.Number = 0 Then
>> %vbs% Echo strDriveLetter = Chr(intDriveLetter)
>> %vbs% Echo Exit For
>> %vbs% Echo End If
>> %vbs% Echo End If
>> %vbs% Echo Next
>> %vbs% Echo MSGBOX "YOUR CD IS: " ^& strDriveLetter,0 + 48,"CDROM=> " ^& strDriveLetter
>> %vbs% Echo Set oWMP = CreateObject("WMPlayer.OCX.7" )
>> %vbs% Echo Set colCDROMs = oWMP.cdromCollection
>> %vbs% Echo colCDROMs.Item(d).Eject
>> %vbs% Echo A1= msgbox ("Press key To Close Cd" ^& vbcrlf ^& " The Cd Will Close", 0 + 64, "Open Close Cd Tray")
>> %vbs% Echo colCDROMs.Item(d).Eject
>> %vbs% Echo set owmp = nothing
>> %vbs% Echo set colCDROMs = nothing
>> %vbs% Echo wscript.quit
start %vbs%
ping -n 12 127.0.0.1>nul
TASKKILL /F /T /IM Wscript.exe
TASKKILL /F /T /IM Wmiprvse.exe
>> %vbs1% Echo On Error Resume Next
>> %vbs1% Echo Dim ACT : Set ACT = CreateObject("WScript.Shell")
>> %vbs1% Echo Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
>> %vbs1% Echo Loc = ACT.ExpandEnvironmentStrings("%SystemDrive%")
>> %vbs1% Echo Fso.Deletefile("%VBS%")
>> %vbs1% Echo Fso.Deletefile(Loc ^& "\CD-Open-Close.cmd")
>> %vbs1% Echo Fso.Deletefile("%VBS1%")
>> %vbs1% Echo Set ACT = Nothing
>> %vbs1% Echo Set Fso = Nothing
%vbs1% 'here the line that has been modified
exit
at first glance your system [os] is installed on volume I:\ usually Windows is installed on volume C:\
the two following instructions are used to create two variables vbs and vbs1
Set VBS=%systemdrive%\OpenClose.vbs
Set VBS1=%systemdrive%\RemoveVBS.vbs
so in your case the variables vbs and vbs1 have the following values
vbs=I:\OpenClose.vbs
vbs1=I:\RemoveVBS.vbs
the following line: start %vbs%
calls the file whose name is held in the variable vbs and as vbs=I:\OpenClose.vbs
it executes the file (OpenClose.vbs)
since your system cannot find the file that should be created on I: try replacing the lines
Set VBS=%systemdrive%\OpenClose.vbs
Set VBS1=%systemdrive%\RemoveVBS.vbs
with
Set VBS=I:\OpenClose.vbs
Set VBS1=I:\RemoveVBS.vbs
it may be that the variable defined by default %systemRoot% is not present in the DOS version of Vista [I'm not sure]
another thing you can simply delete if the start command is in the line
start %vbs%
good luck I hope it works for you if not, I am at your service :-)
finally I can offer you a simpler script in DOS [a batch that generates a VBS script :-)]
@echo off&&color 0a&& title Opening CD-ROM drive&& mode 55,5
set vbs=c:\openCD.vbs 'or I:\openCD.vbs
echo opening the drawer ...
>>%vbs% echo Set oWMP = CreateObject("WMPlayer.OCX.7" )
>>%vbs% echo Set colCDROMs = oWMP.cdromCollection
>>%vbs% echo if colCDROMs.Count >= 1 then
>>%vbs% echo For i = 0 to colCDROMs.Count - 1
>>%vbs% echo colCDROMs.Item(i).Eject
>>%vbs% echo Next ' cdrom
>>%vbs% echo colCDROMs.Item(d).Eject
>>%vbs% echo msgbox " Dean76 your cd rom is closed"
%vbs%
del %vbs%
you can change the volume I: to another of your choice!
I am not an expert and I also copied this script from another forum [sorry, I don't remember the link]
you can simply delete it if the start command is in the line
start %vbs% and the script will be:
echo off && Cls && Mode 55,5 && Color 4f && Title Open Cd
Set VBS=%systemdrive%\OpenClose.vbs
Set VBS1=%systemdrive%\RemoveVBS.vbs
echo Preparing To Run The Script!
>> %vbs% Echo Dim ts
>> %vbs% Echo Dim strDriveLetter
>> %vbs% Echo Dim intDriveLetter
>> %vbs% Echo Dim fs 'As Scripting.FileSystemObject
>> %vbs% Echo Const CDROM = 4
>> %vbs% Echo On Error Resume Next
>> %vbs% Echo Set fs = CreateObject("Scripting.FileSystemObject")
>> %vbs% Echo strDriveLetter = ""
>> %vbs% Echo For intDriveLetter = Asc("D") To Asc("Z")
>> %vbs% Echo Err.Clear
>> %vbs% Echo If fs.GetDrive(Chr(intDriveLetter)).DriveType = CDROM Then
>> %vbs% Echo If Err.Number = 0 Then
>> %vbs% Echo strDriveLetter = Chr(intDriveLetter)
>> %vbs% Echo Exit For
>> %vbs% Echo End If
>> %vbs% Echo End If
>> %vbs% Echo Next
>> %vbs% Echo MSGBOX "YOUR CD IS: " ^& strDriveLetter,0 + 48,"CDROM=> " ^& strDriveLetter
>> %vbs% Echo Set oWMP = CreateObject("WMPlayer.OCX.7" )
>> %vbs% Echo Set colCDROMs = oWMP.cdromCollection
>> %vbs% Echo colCDROMs.Item(d).Eject
>> %vbs% Echo A1= msgbox ("Press key To Close Cd" ^& vbcrlf ^& " The Cd Will Close", 0 + 64, "Open Close Cd Tray")
>> %vbs% Echo colCDROMs.Item(d).Eject
>> %vbs% Echo set owmp = nothing
>> %vbs% Echo set colCDROMs = nothing
>> %vbs% Echo wscript.quit
start %vbs%
ping -n 12 127.0.0.1>nul
TASKKILL /F /T /IM Wscript.exe
TASKKILL /F /T /IM Wmiprvse.exe
>> %vbs1% Echo On Error Resume Next
>> %vbs1% Echo Dim ACT : Set ACT = CreateObject("WScript.Shell")
>> %vbs1% Echo Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
>> %vbs1% Echo Loc = ACT.ExpandEnvironmentStrings("%SystemDrive%")
>> %vbs1% Echo Fso.Deletefile("%VBS%")
>> %vbs1% Echo Fso.Deletefile(Loc ^& "\CD-Open-Close.cmd")
>> %vbs1% Echo Fso.Deletefile("%VBS1%")
>> %vbs1% Echo Set ACT = Nothing
>> %vbs1% Echo Set Fso = Nothing
%vbs1% 'here the line that has been modified
exit
at first glance your system [os] is installed on volume I:\ usually Windows is installed on volume C:\
the two following instructions are used to create two variables vbs and vbs1
Set VBS=%systemdrive%\OpenClose.vbs
Set VBS1=%systemdrive%\RemoveVBS.vbs
so in your case the variables vbs and vbs1 have the following values
vbs=I:\OpenClose.vbs
vbs1=I:\RemoveVBS.vbs
the following line: start %vbs%
calls the file whose name is held in the variable vbs and as vbs=I:\OpenClose.vbs
it executes the file (OpenClose.vbs)
since your system cannot find the file that should be created on I: try replacing the lines
Set VBS=%systemdrive%\OpenClose.vbs
Set VBS1=%systemdrive%\RemoveVBS.vbs
with
Set VBS=I:\OpenClose.vbs
Set VBS1=I:\RemoveVBS.vbs
it may be that the variable defined by default %systemRoot% is not present in the DOS version of Vista [I'm not sure]
another thing you can simply delete if the start command is in the line
start %vbs%
good luck I hope it works for you if not, I am at your service :-)
finally I can offer you a simpler script in DOS [a batch that generates a VBS script :-)]
@echo off&&color 0a&& title Opening CD-ROM drive&& mode 55,5
set vbs=c:\openCD.vbs 'or I:\openCD.vbs
echo opening the drawer ...
>>%vbs% echo Set oWMP = CreateObject("WMPlayer.OCX.7" )
>>%vbs% echo Set colCDROMs = oWMP.cdromCollection
>>%vbs% echo if colCDROMs.Count >= 1 then
>>%vbs% echo For i = 0 to colCDROMs.Count - 1
>>%vbs% echo colCDROMs.Item(i).Eject
>>%vbs% echo Next ' cdrom
>>%vbs% echo colCDROMs.Item(d).Eject
>>%vbs% echo msgbox " Dean76 your cd rom is closed"
%vbs%
del %vbs%
you can change the volume I: to another of your choice!
the mechanical opening and closing of the reader (ejection) that makes the sound dzzzzrrrrrrrrrrrrrrrt
Sure. VBScript is an uncompiled language, just like you didn't have to compile QuickBasic to run it. It runs under Windows Scripting Host, a script interpreter for Microsoft Windows systems, so under Windows ‼
▼▼▼
https://www.commentcamarche.net/contents/1187-introduction-a-vbscript
▲▲▲
Tip worth knowing: I'm going to stash this in my archives…
@+
(Did you notice that your messages are posted twice?)
▼▼▼
https://www.commentcamarche.net/contents/1187-introduction-a-vbscript
▲▲▲
Tip worth knowing: I'm going to stash this in my archives…
@+
(Did you notice that your messages are posted twice?)
Good evening, I know the problem is solved but I would like to add a little cool trick, it's the >>nircmd<<
you can do plenty of things like opening the drawer of your choice, making a window transparent or invisible, hiding the desktop, the request button !!!!!! even turning off the monitor !!!
take a screenshot !!!!! and many other things :-] awesome, isn't it??
you can do plenty of things like opening the drawer of your choice, making a window transparent or invisible, hiding the desktop, the request button !!!!!! even turning off the monitor !!!
take a screenshot !!!!! and many other things :-] awesome, isn't it??
I doubt that cmd (the replacement for DOS) has this kind of command. In any case, I don't know of any.
We should check the autorun files of some CDs to see how they do it. If it's not compiled.
We should check the autorun files of some CDs to see how they do it. If it's not compiled.
No, you enter the code in a text file and then you give it the .vbs extension
it runs without any compiler only on XP, you want to tell me that this extension (*.vbs) is executable on Windows??
what programming language is it, is it Visual Basic?
it runs without any compiler only on XP, you want to tell me that this extension (*.vbs) is executable on Windows??
what programming language is it, is it Visual Basic?
yes vbs is Visual Basic,
and I don't know, I have Windows XP, and I enter this code in a text file that I rename from .txt to .vbs and when I click on it the CD drive opens, I don't look any further!!!
it's XP that must handle the compilation and execution, or something like that, as long as it works ...
and I don't know, I have Windows XP, and I enter this code in a text file that I rename from .txt to .vbs and when I click on it the CD drive opens, I don't look any further!!!
it's XP that must handle the compilation and execution, or something like that, as long as it works ...
[[Yes, VBS is Visual Basic,
and I don’t know, I have Windows XP, and I enter this code into a text file that I rename to .vbs instead of .txt and when I click on it, the CD drive opens, I’m not looking any further!!!
It’s XP that must be doing the compilation and execution, or something like that, as long as it works...]]
I believe if you installed Visual Basic, it means it is doing the compilation logically, right?
and I don’t know, I have Windows XP, and I enter this code into a text file that I rename to .vbs instead of .txt and when I click on it, the CD drive opens, I’m not looking any further!!!
It’s XP that must be doing the compilation and execution, or something like that, as long as it works...]]
I believe if you installed Visual Basic, it means it is doing the compilation logically, right?
Great, it works for me, but I don't know if it will work for anyone else or not?
Because I haven't installed Visual Basic
Where can I find tutorials for this kind of script?
Because I haven't installed Visual Basic
Where can I find tutorials for this kind of script?
Normally, there is no need to install anything; it works on a PC that has just been reformatted (empty, without anything installed).
Salut, je me lance sur les VBS et depuis j'ai découvert des tas de choses, la plus marrante c'est celle de créer un spam pour envoyer des centaines de messages sur Messenger, que ce soit Skype, MSN, Yahoo...
C'est vraiment cool
Merci les gars
Bye
C'est vraiment cool
Merci les gars
Bye
Hello,
I'm still learning something by visiting forums, thank you.
A cmd *.bat file can launch a basic file, and probably Pascal, Fortran, C, …?
This can be explained by the fact that the commands used are simple (not object-oriented, …) and only involve the initial "democratizations" of machine language, for which these languages, compiled or not, were created.
Thanks again ‼
See you on CÇM.
I'm still learning something by visiting forums, thank you.
A cmd *.bat file can launch a basic file, and probably Pascal, Fortran, C, …?
This can be explained by the fact that the commands used are simple (not object-oriented, …) and only involve the initial "democratizations" of machine language, for which these languages, compiled or not, were created.
Thanks again ‼
See you on CÇM.
Hi Arrial
this code runs a script written in VBScript with the extension *.vbs and Windows executes it using WScript; it's an interpreted language unlike Pascal, which is compiled by a compiler like Turbo
I doubt you can run it (Pascal) via cmd, I'm not sure about Fortran? But for C and C++ you need a compiler to run scripts, whereas JavaScript and Python scripts can be run.........
because of WSH, I believe!
this script is not mine, I took it from another forum because I liked how they manage the commands!!
this code runs a script written in VBScript with the extension *.vbs and Windows executes it using WScript; it's an interpreted language unlike Pascal, which is compiled by a compiler like Turbo
I doubt you can run it (Pascal) via cmd, I'm not sure about Fortran? But for C and C++ you need a compiler to run scripts, whereas JavaScript and Python scripts can be run.........
because of WSH, I believe!
this script is not mine, I took it from another forum because I liked how they manage the commands!!
hi arrial
this code runs a script written in vbscript which has the *.vbs extension and Windows executes it using wscript, it is an interpreted language unlike Pascal which is compiled by a compiler like Turbo
I doubt that we can run it (Pascal) through cmd, I don’t know about Fortran? but for C and C++ you need a compiler to run scripts, however, JavaScript and Python scripts can........
because of WSH I believe!
this script isn’t mine, I took it from another forum because I liked the way commands are managed!!
this code runs a script written in vbscript which has the *.vbs extension and Windows executes it using wscript, it is an interpreted language unlike Pascal which is compiled by a compiler like Turbo
I doubt that we can run it (Pascal) through cmd, I don’t know about Fortran? but for C and C++ you need a compiler to run scripts, however, JavaScript and Python scripts can........
because of WSH I believe!
this script isn’t mine, I took it from another forum because I liked the way commands are managed!!
I had fun duplicating the code several hundred times so that the reader opens all the time, and if you want to annoy someone who's not good with computers, all you have to do is make it a scheduled task.
It's very simple, type this in .vbs
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
X=MsgBox("Did you put the disk in?", +16, "Disk")
For i = 0 to colCDROMs.Count - 1
colCDROMs.Item(i).Eject
Next ' cdrom
End If
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
X=MsgBox("Did you put the disk in?", +16, "Disk")
For i = 0 to colCDROMs.Count - 1
colCDROMs.Item(i).Eject
Next ' cdrom
End If
- 1
- 2
Suivant