You are here

Eject script

40 posts / 0 new
Last post
ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
Eject script

This is a simple eject script made with AutoIT. LINK UPDATED 31th May

It searches for processes running from the USB drive and closes them gracefully - That is unsaved open files will prompt for saving - only caveats are if an app minimises to the tray when closed as in UTorrent (behaviour can be changed in the app) and USB Files opened with programs that are not on the USB drive will not close if they do not have the path in their child window title.

http://tinyurl.com/2wkpjx

Aciago
Aciago's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2007-01-24 14:23
How it works?

I downloaded it, it is only an eject.exe and an eject.au3...

Do you have some documentation? how it works? it also uses command lines? where is the source code? do I need to have *.au3 file in my portable (not U3)?

Please provide source code, a readme, and a license... I'm specially interested in the readme file... and this forum wants the code and the license... Wink

Thanks in advance for your answers and for your work.

------------------
I don't have a signature
Should I have a signature?

If a packet hits a pocket on a socket on a port,
and the bus is interrupted as a very last resort,
and the address of the memory makes your floppy disk abort,
then the socket packet pocket has an error to report Biggrin

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
The source is the au3 file -

The source is the au3 file - It is AutoIT script The exe is just compiled and can be decompiled using AutoIT

It works by searching Windows processes for any PID with a path matching /PortableApps/. It then uses an AutoIT function WinClose() to close these Windows.

I have just uploaded an update as the original closed the script before it closed other paths .. Doh!

I am just experimenting with AutoIT scripting, its all very new to me - Just made one that sets a Windows Environment Variable for the USB drive letter.

Aciago
Aciago's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2007-01-24 14:23
If I understood well...

Just have to "run on exit PStart" and eject.exe will close any app running... don't have to say which app?

Then I have another question... convey have -exit, and I'm using it... it affect it?

------------------
I don't have a signature
Should I have a signature?

If a packet hits a pocket on a socket on a port,
and the bus is interrupted as a very last resort,
and the address of the memory makes your floppy disk abort,
then the socket packet pocket has an error to report Biggrin

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
That's the idea - Any apps

That's the idea - Any apps that minimise when closed (like utorrent) might just minimise. You can usually change that behaviour within that apps settings.

It will work from anywhere on your pen drive

Convey shouldn't affect it

Aciago
Aciago's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2007-01-24 14:23
Last question.-

Cool! ...last question...

It quit/exit/close not kill, right?

EDIT: and then it closes itself and eject the drive?

------------------
I don't have a signature
Should I have a signature?

If a packet hits a pocket on a socket on a port,
and the bus is interrupted as a very last resort,
and the address of the memory makes your floppy disk abort,
then the socket packet pocket has an error to report Biggrin

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
It closes files gracefully -

It closes files gracefully - So if a file is open it will automatically prompt a dialogue box to save or not. The script closes after you click OK on the message box at the end.

m2
Offline
Last seen: 13 years 9 months ago
Joined: 2006-12-12 12:00
One suggestion: Do not close

One suggestion: Do not close processes running from the path '/PortableApps/'. Close these on the drive you're running from. It's not only more universal - it's also safe with multiple devices connected.
ADDED:
One more:
change
StringInStr($path, "Eject")
to something like (I don't know AI3 )
StringInStr($path, "\\Eject.exe") or add a safe method of doing it.

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
StringInStr($path,

StringInStr($path, "Eject")
The above line is just to stop the script closing itself. It only parses to the function if it is false.

I have made the following changes and updated the link.

Closes all processes from the USB drive letter where ..

  • The application is running from the USB
  • USB Files opened from non-usb applications ONLY IF the drive letter is in the child window title.

The drive letter is discovered by finding the PortableApps window and extracting its path. Therefore PAM must be running.
If anyone know how to discover the path of open child windows that would be useful ...

m2
Offline
Last seen: 13 years 9 months ago
Joined: 2006-12-12 12:00
StringInStr($path,

StringInStr($path, "Eject")
The above line is just to stop the script closing itself. It only parses to the function if it is false.

I know. But there may be another open prog with "Eject" somewhere in it's path. That's why I suggest to specify the detect string as precisely as possible or (better) find own path and compare others with it.

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
OK i got you - Try the new

OK i got you - Try the new link. I've used a macro for the script path and compare it to the path

If StringInStr($var[$i][0], $driveLetter) AND $path @AutoItExe Then

Thanks for that.

John Bentley
John Bentley's picture
Offline
Last seen: 15 years 3 months ago
Developer
Joined: 2006-01-24 13:26
Instead of passing the

Instead of passing the window title to _WinGetPath pass the HWND. ($var[$i][1])

cowsay Moo
cowthink 'Dude, why are you staring at me.'

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
Now you're in unknown

Now you're in unknown territory for me. That appears to be a Hex identified? What difference will that make?

John Bentley
John Bentley's picture
Offline
Last seen: 15 years 3 months ago
Developer
Joined: 2006-01-24 13:26
You basically replace $path

You basically replace $path = _WinGetPath($var[$i][0]) with $path = _WinGetPath($var[$i][1]). That will make it so that you will get the right window if there are two matches.

cowsay Moo
cowthink 'Dude, why are you staring at me.'

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
OK i see now - That's done

OK i see now - That's done and link updated - Cheers

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
Do you know how this script

Do you know how this script could find the path of child windows? I am not sure if the SQL in the function retrieves this infor or not.

For example an image/file on the pen drive opened by a program on from C:\

John Bentley
John Bentley's picture
Offline
Last seen: 15 years 3 months ago
Developer
Joined: 2006-01-24 13:26
Sorry, I don't know how do

Sorry, I don't know how do that.

Another tip: replace the two WinClose($var[$i][0]) calls with WinClose($var[$i][1]).

cowsay Moo
cowthink 'Dude, why are you staring at me.'

m2
Offline
Last seen: 13 years 9 months ago
Joined: 2006-12-12 12:00
As you've got your path,

As you've got your path, wouldn't it be better to remove looking for PAM to get the drive letter and use yours instead?

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
Yes definately...

Yes definately... Updated link

Aciago
Aciago's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2007-01-24 14:23
Don't Work.-

I tried, first whit zz eject.exe located in /portableapps/otros/, then moved to /portableapps/, and now in root directory... it shows a message saying "close any exit dialog boxes - device is safe to remove", but...

It kills (not close) convey... it closes stickies, but pStart, nPOP and KeePass remains open, and of course USB drive don't eject.

Cry Cry Cry

------------------
I don't have a signature
Should I have a signature?

If a packet hits a pocket on a socket on a port,
and the bus is interrupted as a very last resort,
and the address of the memory makes your floppy disk abort,
then the socket packet pocket has an error to report Biggrin

azjerry
Offline
Last seen: 7 years 2 months ago
Joined: 2005-12-09 12:42
ditto

KeePass and PStart are not closed. If I manually close all apps prior to executing, the drive isn't ejected.

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
@MISIIM Thanks done Convey

@MISIIM Thanks done

Convey closes OK for me, I do not run PStart or Keypass so please try the latest upload and test again.

This is not a perfect Eject script, I am working on its limitations so testing helps... but my main objective is to learn AutoIT scripting Wink

azjerry
Offline
Last seen: 7 years 2 months ago
Joined: 2005-12-09 12:42
I think

I figured out part of the problem. Using Process Explorer I see that

PStart.exe command line is \PortableApps\PStart\PStart.exe

KeepassPortable.exe shows no command line
KeePass.exe command line is "V:\PortableApps\KeePassPortable\App\keepass\keepass.exe"

It appears that eject can't match Pstart and KeePassPortable but I'm not sure why KeePass.exe itself isn't ended.

Other portablexxxx.exe that I looked at all start with v:\portableapps\xxxx as do the corresponding applications.

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
Do these apps close normally

Do these apps close normally or do you have to right click a menu to exit them? Any apps that minimise instead of closing as their default behaviour will not close with this script.

I may be able to search these out and brute force kill their processes.

azjerry
Offline
Last seen: 7 years 2 months ago
Joined: 2005-12-09 12:42
well

both normally reside in the tray.

Using XP's taskkill command I can close keepass.exe without using the /f parameter. It works whether or not it's minimized to the tray.

With PStart I have to add the /f parameter to force it to close.

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
Try the new file I put in

Try the new file I put in the zip file.
It uses processclose for keepass.exe and pstart.exe

m2
Offline
Last seen: 13 years 9 months ago
Joined: 2006-12-12 12:00
I don't like this

I don't like this idea.
Can't you just check executable path instead of command line?
It would also work faster.
BTW did you try Eject on limited user account? Getting command line of some (possibly all..) processes may fail. With highly limited privileges (i.e. admin may set they low for apps that are not run from Program Files) it definitely will.

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
I agree, was a quick fix...

I agree, was a quick fix... If those two apps have command line exit switches I could use those instead. Do they?

Aciago
Aciago's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2007-01-24 14:23
No, they don't

In fact I just received an answer from nPOP telling me that they are going to add it (-exit) to the new release...

Convey closes by itself (-exit)

KeePass don't close and stickies don't close... with eject.

Both nPOP, KeePass, and stickies are minimized when pressing close, both three needs right click -> exit.

Since my last post I started using NirCmd (search in this forum) to close running apps, and tried RemoveDrive (search this forum) to eject but it doesn't work either.

------------------
I don't have a signature
Should I have a signature?

If a packet hits a pocket on a socket on a port,
and the bus is interrupted as a very last resort,
and the address of the memory makes your floppy disk abort,
then the socket packet pocket has an error to report Biggrin

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
Check the settings for

Check the settings for Keepass and other apps as they sometimes give you the option to uncheck 'Minimize to tray on close'

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
Check the settings for

Check the settings for Keepass and other apps as they sometimes give you the option to uncheck 'Minimize to tray on close'

azjerry
Offline
Last seen: 7 years 2 months ago
Joined: 2005-12-09 12:42
I unchecked

the minimize to close in Keepass. As long as the keepass window is open Eject works on keepass but not pstart. Eject with kill does kill pstart but still doesn't kill keepass when it's minimized to the tray.

That got me thinking. I can set pstart to run regular eject when pstart closes. That solves the pstart problem Smile but not keepass Sad

An automatic eject at the end this would be great.

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
As @m2 says this is not a

As @m2 says this is not a great solution and I am near my knowledge limit on this, though I am searching the AutoIT forums. What I want most for tis script at the moment is the ability to detect child windows (Files opened by external apps to the pen drive.) though I am not sure AutoIT can detect these.

m2
Offline
Last seen: 13 years 9 months ago
Joined: 2006-12-12 12:00
App-specific solutions is an

App-specific solutions is an endless work - there are hundreds if not thousands mobile apps around and new ones comming at least weekly.
Read http://support.microsoft.com/kb/176391 , it should solve the problem with termination instead of closing.

"Those people who think they know everything are a great annoyance to those of us who do." Asimov

Espreon
Espreon's picture
Offline
Last seen: 12 years 3 months ago
Joined: 2006-09-29 18:23
Can I include this in my Suites?

You know the Armogohma Suites... (find out more by looking for the thread in the beta forums), I will give you credit.

Also this script helps me alot when using Papps. So thanx!

--
As all of ya should know Microsoft is the Evil Empire, and Windows (a.k.a. Winblows or Windoze) is their greatest general, so please make a difference and install Linux or Free BSD on yer Windows comp.

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
Feel free - Glad you like it

Feel free - Glad you like it Smile

Gamer239
Offline
Last seen: 17 years 3 months ago
Joined: 2007-04-15 00:04
can i use it too? i am

can i use it too? i am working on an app and i think that i may have figured out how to eject with a single .exe. it doesn't always work but i'm trying to figure that out. i will give you plenty of credit. and one more question, how do you find what the drive letter that you are on?

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
Free to all who want it

Free to all who want it Wink

xrxca
Offline
Last seen: 10 years 10 months ago
Joined: 2007-07-03 23:59
Suggestion

I made this change on the version of the eject script I use (along with a direct process kill for an annoying app I use that will not respond to any messages I send it)
Instead of bringing up a messagebox when I'm done I run the device removal dialog (works in XP and Vista)

Run("Rundll32.exe Shell32,Control_RunDLL hotplug.dll", @WindowsDir)

_________________________
* programmer (noun) : a predominantly nocturnal creature fueled by either Caffeine or Sugar (Or Both).

ozbodd
Offline
Last seen: 16 years 1 week ago
Joined: 2007-02-22 15:12
Excellent I'll add it when I

Excellent I'll add it when I get a chance.

Log in or register to post comments