Sign in to follow this  
Followers 0
ezzetabi

Improved ShellExecute UDF

38 posts in this topic

#1 ·  Posted (edited)

;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

Share this post


Link to post
Share on other sites



You can also use non default right click menu actions, like print, enqueue...

Share this post


Link to post
Share on other sites

Could you add a run or runwait parameter? EG: _ShellExecute('www.hiddensoft.com\forum','', 1) to wait on iexplore or the program to finish?


Who else would I be?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

With easy:

;Better code below.

Edit: corrected the same bugs :">

Edited by ezzetabi

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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?

Share this post


Link to post
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...

Share this post


Link to post
Share on other sites

Thanks you this-is-me. I am happy now. :ph34r:

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Try

Run(@SystemDir & "\RUNDLL32.EXE shell32.dll,ShellExec_RunDLL """ & $sCmd & """")

If you want a quick and easy way of calling ShellExecute

Edited by pacman

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Also, that command only works on 2k or above.


Who else would I be?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

...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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

There is only the .exe name? No %1 or %L ?

Share this post


Link to post
Share on other sites

There is only the .exe name? No %1 or %L ?

<{POST_SNAPBACK}>

In HKCR\Applications\filename.exe\shell\open\command

There is a %1

You asked me to check HKLM\SOFTWARE\ Microsoft\Windows\ CurrentVersion\App Paths\filename.exe

HTH

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Can you see why it is not working?

Is it because the application has a space in it's name? "Filemaker Pro.exe"

I have attached a screenshot of my REGEDIT screen showing the items you asked about.

Cheers

Monster

Share this post


Link to post
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
Sign in to follow this  
Followers 0