Jump to content

Improved ShellExecute UDF


ezzetabi
 Share

Recommended Posts

;better code below.

:ph34r:

Edit: Fixed a comple of bug.

1- lnkfile strangely have no Open key in the registry

2- it will work also if a user do not set a extension, but it set the path.

Edited by ezzetabi
Link to comment
Share on other sites

New version. This time it can also execute 'Registry shortcut' (HKCR\Applications application with Open key) and should be more read able than the older version...

Well. A part of this-is-me him/herself none answered. So I guess it is unimportant...

Anyway, adding the $wait thing is very easy if needed. Just take the pid of the process Run() create and at the very end await it closes.

Since it is a 'not-so-often' needed feature. You may activate it when, for example, StringRight($line,6) = '\\wait' . And remove this \\wait just a little after. So it becomes a optional parameter!

Example code:

If StringRight($line,6) = '\\wait' Then
   $wait = 1
   $line = StringTrimRight($line,6)
EndIf

At the end of the script adds something like If $wait = 1 Then ProcessWaitClose($pid)

;Better code below

Edit: since this version has been remade from zero I forgot the strange thing of .lnk file that have no Open key in the registry.

Corrected!

Edited by ezzetabi
Link to comment
Share on other sites

I'm a he. I don't think it is unimportant to most people, just most people don't know the main reason for having such a function. I personally use it many times during the day. If the real reasoning behind this udf were known, I think noobs would flock to it with open arms and hearts full of joy. :ph34r:

Who else would I be?
Link to comment
Share on other sites

I'm a he. I don't think it is unimportant to most people, just most people don't know the main reason for having such a function. I personally use it many times during the day. If the real reasoning behind this udf were known, I think noobs would flock to it with open arms and hearts full of joy. :ph34r:

<{POST_SNAPBACK}>

Can you share the reason with us? It might be interesting to know how other people use it and it could give ideas to the rest of us...
Link to comment
Share on other sites

@tuape, The shellexecute function allows you to "execute" a file without knowing what program it is associated with. Therefore, instead of running notepad.exe testfile.txt you can just shellexecute testfile.txt and shellexecute will find what program needs to be opened and open it for you. You can do the same with msi files, etc. The main reason you might need shellexecute is if you were starting a file on another person's computer and you don't know what program they want it to run in.

Example:

You want to open a webpage.

You try to run firefox.exe mypage.htm

Firefox doesn't exist on the target computer.

Your script blows up.

Example fixed with shellexecute:

You want to open a webpage.

You shellexecute mypage.htm

The page opens in their default browser

Fixed!

@ezzetabi, no prob.

Who else would I be?
Link to comment
Share on other sites

Improved even more! Now it is even more powerful than the standard Shell!

Before this update using * or ? could crash the scipt (if errorsfatal isnt set), now instead if the file appear to exist, but you used * or ?, the first file that is found with that wildcards will be open!

E.g. you have a program called C:\program files\hello_world.exe

you can run it only with "c:\program files\hello_*.exe"

If the file using *, ? seems not exist, it will be searched using the old code, that actually already worked!

E.g. you can start your console with cm?.exe since the program will look for a the first file that is cm?.exe in the whole %path%.

Registry shortcut can't be used with wildcards.

Edited by ezzetabi
Link to comment
Share on other sites

Well. It is a great idea PacMan, but it does not accept arguments (AFAI saw) and it can't work with partial filenames.

Edit: I checked better, it accepts arguments. But still the missing ability of the '$verb' ability is bad. Still, if you dont need verbs a single line agaist this big UDF can be a good deal.

Edited by ezzetabi
Link to comment
Share on other sites

Hi

I am new to this whole AutoIt, and am writing my first decent script.

I have a script that will exit filemaker pro, format a floppy, zip the user files to the floppy, and then finally asks if the user woul dlike to restart Filemaker Pro.

I though using this function I could easily do this, but Filemaker Pro starts when I use:

_ShellExecute('file.fp5','','')

But the file itself does not open. Just the dialogue box for New File, Load Existing, Blank Document thing.

Any ideas?

Thanks

Monster

Link to comment
Share on other sites

...Strange. Can you look in registry the key that this func should execute?

BTW:

The registry shortcut are stored in

HKLM\SOFTWARE\ Microsoft\Windows\ CurrentVersion\App Paths\filename.exe

not in

HKCR\Applications\filename.exe\shell\open\command as I thought...

Correcting the script right now.

Edited by ezzetabi
Link to comment
Share on other sites

...Strange. Can you look in registry the key that this func should execute?

BTW:

The registry shortcut are stored in

HKLM\SOFTWARE\ Microsoft\Windows\ CurrentVersion\App Paths\filename.exe

not in

HKCR\Applications\filename.exe\shell\open\command as I thought...

Correcting the script right now.

<{POST_SNAPBACK}>

It correctly shows Filemaker Pro.exe

If I double click the file it loads.

HTH

Monster

Link to comment
Share on other sites

No. Do you see how the udf works?

Look for the category name in the HKCR\.fp5 it is probably fp5file, look in HKCR\fp5file\Shell\open\Command . Thats the point where the udf should look for. And it replaces %1 or %l with the filename.

The btw command was a note. There was a error in the UDF managing the registry shortcut, I posted the fixed code.

Edited by ezzetabi
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...