Alright, I know in the past I started to look into how to make an autohotkey script that would automatically eject the drive you have the PA menu on (when you click the eject button on PA menu). Well I began to write the script, and I made a basic one that works. Here it is.....
DriveGet, list,List, REMOVABLE ;Only gets Removable Drives. DriveGet, cap, capacity, %list%: ;Gets total usb size DrivespaceFree, free, %list%: ;Tells you available space on drive DriveGet, fs, fs, %list%: ;Tells you what format the drive is in, eg: Fat32, Fat DriveGet, label, label, %list%: ;Tells you what the usb Label name is, such as Nathan's Drive. DriveGet, serial, serial, %list%: ;Tells you drives serial number DriveGet, type, type, %list%: ;Tells you what type of drive it is, Removable, Fixed DriveGet, status, status, %list%: ;Tells you if the drive is able to be removed by telling you its ready If list = ExitApp else MsgBox, 4, Eject, %list%:, Total Size:%cap%MB, Free Space:%free%MB, %fs%, %label%, %serial%, %type%, %status%, Is this information correct for your removable device? If so Click yes to Eject Drive %list%: IfMsgBox No ExitApp else Driveletter = %list%: DrivePath = \\.\%Driveletter% hVolume := DllCall("CreateFile" , str, DrivePath , UInt, 0x80000000 | 0x40000000 ;GENERIC_READ | GENERIC_WRITE , UInt, 0x0 ;Tries to get exclusiv rights to the drive +++(see below) , UInt, Null , UInt, 0x3 ;OPEN_EXISTING , UInt, 0x0 , UInt, NULL) if A_LastError = 32 ;Another application has read or write-access to the drive (In this case no handle was retreived to release) { hVolume := DllCall("CreateFile" ;Get handle even if another application reads the drive , str, DrivePath , UInt, 0x80000000 | 0x40000000 ;GENERIC_READ | GENERIC_WRITE , UInt, 0x1 ;FILE_SHARE_READ , UInt, Null , UInt, 0x3 ;OPEN_EXISTING , UInt, 0x0 , UInt, NULL) if hVolume != -1 { msgbox, 4164, Warning, An application is accessing this device.`nEject it anyway? IfMsgbox, No { DllCall("CloseHandle", UInt, hVolume) ;Release handle here return } } if A_LastError = 32 ;No read access was possible also { msgbox, 4164, Warning!, Another application is writing to this device!`nEject it anyway? IfMsgbox, No return else { hVolume := DllCall("CreateFile" ;Get handle even if another application reads or writes to the drive , str, DrivePath , UInt, 0x80000000 | 0x40000000 ;GENERIC_READ | GENERIC_WRITE , UInt, 0x1 | 0x2 ;FILE_SHARE_READ | FILE_SHARE_WRITE , UInt, Null , UInt, 0x3 ;OPEN_EXISTING , UInt, 0x0 , UInt, NULL) } } } if hVolume != -1 ;Drive is Ejected { DllCall("DeviceIoControl" , UInt, hVolume , UInt, 0x2D4808 ;IOCTL_STORAGE_EJECT_MEDIA , UInt, NULL , UInt, 0 , UInt, NULL , UInt, 0 , UInt, &dwBytesReturned ;Not used , UInt, NULL) DllCall("CloseHandle", UInt, hVolume) } return
Now I also have other variables that are listed that can be used to ensure the drive you are ejecting is yours and I could also add the ability to search the drive for the PA menu, and if it is present then it will continue to run the script, this is just an outline, and if you wish to add on to it then feel free to. I think this would be great for the PA menu's eject feature and hopefully people take some interest into this.
You can get this script in exe form from here
I am an AHK starter (don't understand a thing about dll cals), but how about this:
That way, there is no need to ask the user if drive x is his drive.
Blue is everything.
Just a thought, I know that there is a window that ask's you if that is you information, so I'm thinking maybe moving the message box code to the beginning and asks if that is correct then if you hit yes, then it will save to an .ini file in the %A_ScriptDir%, and put something like, GotDriveInfo=Yes, then exit the application and in the beginning of the application read GotDriveInfo=Yes, (If its not present then it wont run then next process, but take you to initial window where you will be asked if it is correct), then I can just include the "code" that will eject the drive in a seperate .ahk files. I think I know how I can do this a bit more complicated, but I think the eject script should be really simple so it doesnt get confusing.
Also I need someone to clarify this.... is it true that usb serial numbers change from computer to computer? If no then I can always have the users serial read and this would probably have less flaws than another method.
An eye for an eye makes the whole world blind.
Mahatma Gandhi,
Indian political and spiritual leader (1869 - 1948)
I'm almost sure that all of that can be done in NSIS or (duh!) Delphi.
Insert original signature here with Greasemonkey Script.
I'm almost sure that you have been asked several times to drop the sarcastic tone. While all of it could be done in NSIS or (duh!) Delphi, AHK is Nathan's langauge of choice, it could also be done in C++, C, C#, JAVA, FreePascal, Assembly Language, and many others.
The developer formerly known as ZGitRDun8705
Are you sure it can be done in JAVA? I barely know it, but I have some doubts..
"Those people who think they know everything are a great annoyance to those of us who do." Asimov
With the right frameworks/plugins JAVA can do just about anything. Whether or not using JAVA for the task is logical/efficient is a a different story...
The developer formerly known as ZGitRDun8705
Gosh, guess lack of school really does turn brain matter to mush :(.
I was saying (duh!) Delphi because the menu was written in Delphi so the same algorithm for listing apps can be used to check close $drive\**.exe.
I'm not the sarcastic type (my friend the math wiz is :P).
Insert original signature here with Greasemonkey Script.
I think you might find this interesting.
"Those people who think they know everything are a great annoyance to those of us who do." Asimov
I'll keep an eye on this thread since I'm very interested on the outcome.
Congrats on the work so far.
Alive and kicking!
"If you were a robot, and I knew but you didn't, would you want me to tell you?"