Computer Science Canada How can I eject a disc? |
Author: | MrAndrews [ Mon May 26, 2008 10:25 pm ] |
Post subject: | How can I eject a disc? |
I have Turing v. 4.1.1, and I was wondering how to open the disc drive. I was going to use this in to put at the end of a trivia type program something like: put "You Won!" put "As your prize, you will now receive a new Cup Holder!" (This is where you would open the disc drive) I know that to shut down the computer you use: var ret : int system ("shutdown -s -c message-here", ret) so i was thinking that to do something like open the disc drive you would need something similiar, but so far ive gotten nowhere anyway, if anyone can help, thatd be great ps. im new to this website, so im sorry if i put this in the wrong place or submitted it incorrectly somehow |
Author: | Nick [ Mon May 26, 2008 11:23 pm ] |
Post subject: | Re: How can I eject a disc? |
MrAndrews @ Mon May 26, 2008 10:25 pm wrote: var ret : int system ("shutdown -s -c message-here", ret) never used System before but it seems to use DOS prompt... look for a DOS command |
Author: | Tony [ Mon May 26, 2008 11:54 pm ] |
Post subject: | Re: How can I eject a disc? |
nick @ Mon May 26, 2008 11:23 pm wrote: look for a DOS command
unless he's running Windows 98 (or *gasp* earlier), DOS is hardly relevant. |
Author: | MrAndrews [ Tue May 27, 2008 10:50 am ] |
Post subject: | RE:How can I eject a disc? |
Personally, I havnt really used System before either . . . i got that line of code from a program a friend sent me. As for the OS, my friend wrote and tested the program on XP, and i am running Vista and it still shut my computer down |
Author: | btiffin [ Tue May 27, 2008 2:00 pm ] | ||
Post subject: | Re: How can I eject a disc? | ||
If Turing allows dll linking; Convert this C# to something similar in Turing syntax (something I know little about)
http://msdn.microsoft.com/en-us/library/ms712587%28VS.85%29.aspx for more info Cheers |
Author: | Nick [ Tue May 27, 2008 2:03 pm ] |
Post subject: | RE:How can I eject a disc? |
well DOS, command prompt, I don't know the difference, the only console I use is for ubuntu |
Author: | btiffin [ Tue May 27, 2008 2:11 pm ] |
Post subject: | RE:How can I eject a disc? |
P.S. Be careful if you experiment with mciSendString. It can do a lot, and no doubt bone things up if not shown the proper care and respect. Cheers |
Author: | MrAndrews [ Sat May 31, 2008 7:06 pm ] |
Post subject: | RE:How can I eject a disc? |
Thanks for the help so far . . . Unfortunately, i have no idea how to use C# and even less of an idea how to translate something like that into Turing. as far as i know, the system (" "ret) function that i used does the exact same thing as Sys.Exec (" ") which i have seen in other parts of compsci. They both use the Windows Command Line, however i am not sure if there is a command available through that that actually opens the cd door. anyway, if anyone has any ideas on this, some more help would be great |
Author: | [Gandalf] [ Sat May 31, 2008 9:53 pm ] |
Post subject: | Re: RE:How can I eject a disc? |
btiffin @ 2008-05-27, 2:11 pm wrote: P.S. Be careful if you experiment with mciSendString. It can do a lot, and no doubt bone things up if not shown the proper care and respect.
No reason to worry... Turing doesn't allow DLL linking, though I am sure with a little creativity just as much harm can be done... MrAndrews, I don't know how, but I don't doubt that there is a way over the command line. Just keep looking, google it. ![]() |
Author: | Stove [ Mon Jun 02, 2008 9:09 pm ] | ||||
Post subject: | Re: How can I eject a disc? | ||||
You could try making a visual basic script (make a text file and change the extension to .vbs, not real visual basic btw) with something like:
And then just execute the file with system(). The only problem is that wscript.exe or whatever program runs the script, never actually closes... You could probably run "taskkill /f /im wscript.exe" with system() afterwards to clean it up. Its kind of an "icky" approach, but I tried it in Turing and it seems to work.
One last thing, it takes forever for the script to actually load and run, so you'll have to wait a bit before you kill wscript.exe. That being said, it'd probably be a good idea to run the script on a separate thread so you don't have to block your main program while it runs. It took about 8 seconds on my laptop to run, but that time will probably vary. Anyways, hope that helps. |
Author: | btiffin [ Tue Jun 03, 2008 4:32 am ] | ||
Post subject: | Re: How can I eject a disc? | ||
If you haven't googled a good executable yet, try this ECMAScript (ECMAScript is just me using anal speak for javascript) Make a file ej.js
What ever the drive letter for the CD is (you, may need to wrap this is an error trapper and try D:, E:, F:, G: etc) I'll leave any error handling for you to figure out ... not hard ... ok a hint, ECMAScript has try/catch. If you pick a drive letter that doesn't exist, script runner will pop up an error dialog. Then try your system() Turing function on ej.js Cheers Edit; Sorry, just noticed the VB solution. This wasn't meant as a one upper, apologies for that Stove. |
Author: | jeffgreco13 [ Tue Jun 03, 2008 11:44 am ] |
Post subject: | Re: How can I eject a disc? |
I've done this before. It's been a while since I worked with it but have a look: Quote: 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 This is VBScript and it does work! You open up notepad and paste that in. Save as cdOpen.vbs MAKE SURE ITS EXTENSION IS > .vbs Then use this: Quote: var ret : int
system ("put the path to the file here", ret) that should work... for what ur looking for. There's also ways to have turing open a filestream and create that file for you if you're to make a standalone exe. PM me for details on that. |
Author: | petree08 [ Tue Jun 03, 2008 12:04 pm ] | ||
Post subject: | RE:How can I eject a disc? | ||
does anyone have a compiled (.exe) disktray opener? the following should work if the exe is named DiskOpen.exe
i suck at c and was wondering if anyone would post a compiled disk tray opener edit : sorry i didn't read the above post properly , pretty much the same thing |
Author: | Stove [ Tue Jun 03, 2008 6:55 pm ] |
Post subject: | Re: How can I eject a disc? |
@ MrAndrews Definitely use btiffin's script for opening the cd drive, as it completely avoids the whole taskkill and clean up bit that executing a visual basic script needs. @ btiffin No need to apologize, the more solutions the better. ![]() |
Author: | MrAndrews [ Fri Jun 20, 2008 10:37 pm ] |
Post subject: | RE:How can I eject a disc? |
Thanks for all the help everyone. I havnt been on in a while to read this (exams etc.) but now I have a bit more time I know nothing about javascript, so decided to try the solution given by jeffgreco13 first, which worked fine. I didn't add any taskkill feature to the program and when i went into the taskmanager, i couldnt find the VBScript. Maybe i'm not looking in the right place? Anyway this works for what I am trying to do. |
Author: | andrew. [ Sun Jun 29, 2008 1:58 pm ] |
Post subject: | Re: How can I eject a disc? |
jeffgreco13 @ Tue Jun 03, 2008 11:44 am wrote: I've done this before. It's been a while since I worked with it but have a look:
Oh yeah, I remember that script. I used to use it on my friends. I would have it on my USB stick and when they aren't looking, I would upload it to their computer. It was so funny.Quote: 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 This is VBScript and it does work! You open up notepad and paste that in. Save as cdOpen.vbs MAKE SURE ITS EXTENSION IS > .vbs Then use this: Quote: var ret : int
system ("put the path to the file here", ret) that should work... for what ur looking for. There's also ways to have turing open a filestream and create that file for you if you're to make a standalone exe. PM me for details on that. |
Author: | BigBear [ Sun Mar 15, 2009 11:41 am ] |
Post subject: | RE:How can I eject a disc? |
Sorry for Necroposting, but I am trying to do the same thing and no sense making a new topic. For some reason I cannot get this to work, I tried running the script itself and with turing system just in case. I have the correct drive letter. Also wondering how important it is to end the vb script. |
Author: | MrAndrews [ Sun Mar 15, 2009 1:27 pm ] |
Post subject: | RE:How can I eject a disc? |
ok, im not sure what you mean by "end the vb script" but i don't remember having to do anything special. i just made turing tell it to run the only thing i can think of offhand that would cause this to not work is that you may have the wrong file extension. if you right clicked and went to "new text document" then it will automatically have a .txt file extension. usually if you do this then save it as file.vbs, the computer will save the file as file.vbs.txt (though you can change some settings which will fix this problem (and cause others if you are not careful)) what you need to do is go to notepad, paste the script in, go to save as and save it as a vbs file. when you do this make SURE that change the file type from text file (*.txt) to all files (*.*), then save it as file.vbs (obviously it doesnt have to be file.vbs, you can change file to whatever you want. the .vbs is all that is important) |
Author: | corriep [ Sun Mar 15, 2009 6:05 pm ] |
Post subject: | Re: How can I eject a disc? |
All glory and praise to Google!. |
Author: | BigBear [ Mon Mar 16, 2009 7:05 am ] | ||
Post subject: | RE:How can I eject a disc? | ||
@ MrAndrews if you look at the first vb solution it has system ("taskkill /f /im wscript.exe", blah) Anyways I can get that solution to work I meant this solution btiffin @ Tue Jun 03, 2008 4:32 am wrote:
|