Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Check CD drives on exit


  • Please log in to reply
2 replies to this topic
Koliberek
  • Guests
  • Last active:
  • Joined: --
Hi!
I discovered Autohotkey just a few days ago and I found it very useful.
I looked for something ejecting CD when my children leave game CD and shut down computer. I found some programs, but not free. So - I wrote it using AHK...:

#NoTrayIcon
#Persistent 
OnExit, ExitSub 
return 

ExitSub: 
if A_ExitReason in Logoff,Shutdown ; Only if computer is shutted dow or user logs out. 
{ 
	DriveGet, lista, List, CDROM ;get all CD drives
	Stringlen, cd_len, lista ;how much of drives?
	Loop, %cd_len%  ;for each drive
	{ 
		stringmid cd_letter, lista, %A_Index%, 1  ;get name of drive
		driveget isopen, StatusCD, %cd_letter% ;check if it is empty
		if (isopen != "open") ; if not - open it
		{ 
			Drive, Eject, %cd_letter% 
			} 
		
		} 
	} 
ExitApp 


I hope it will be useful for you.

--
koliberek

ILL.1
  • Members
  • 84 posts
  • Last active: Apr 28 2005 11:42 AM
  • Joined: 29 Sep 2004
You could use a "Loop, Parse, lista" to cut down on a line or two of code. Not that your code is slow or anything.
===============
----------ILL.1-----------
===============

koliberek
  • Guests
  • Last active:
  • Joined: --
Thanks a lot for advice.
It's my first script in Autohotkey and I have to learn a lot to make good scripts.