Followers 0

# Can you verify a pathless ShellExecute("command")?

## 3 posts in this topic

#1 ·  Posted (edited)

Normally one uses ShellExecute("c:\foo\bar.txt"). But there are internal uses too. For example, ShellExecute("winword") launches Microsoft Word. However, ShellExecute("foobar") launches an error message. Is there a way to accept only "legal" values?

In other words, is the word "winword" registered somewhere and can be verified before it's thrown into ShellExecute?

Thanks!

Edited by LWC

##### Share on other sites

#2 ·  Posted (edited)

Would not just error checking be the solution you are looking for?

ShellExecute ("foobar")
if @error Then MsgBox(0,"error","error")

just a quick thought

nevermind..... I see what you are wanting now. sorry

Edited by damon

It always amazes me how one little thing can cause so much havoc

##### Share on other sites

The registry key HKCR\Applications appears to hold the registered executable names that will run from the ShellExecute command. I may be mistaken but it does appear to hold the ones that can be run from it from the limited testing I've done.

Try this code out to see what I'm talking about. It will scan the Applications key and show you all of the programs registered under it. I declared the array with a sizeable number to start, just in case the machine you're using has a log of subkeys in it, then I redeclared it with the ReDim command to get rid of the excess to save memory. I'm not sure that it's needed, but it makes for a cleaner display in the end.

#include <Array.au3>
Local $Test[1000] For$i = 1 To 1000
$Test[$i] = RegEnumKey("HKCR\Applications\", $i) If @error <> 0 Then ExitLoop Next ReDim$Test[$i]$Test[0] = $i-1 _ArrayDisplay($Test)

If you wanted to check that the commands are valid for ShellExecute, you could run a For...Next loop to check all values of the array $Test to see if they match or not. I also set$Test[0] to the size of the array so you could use it as a guide to tell you how many loops you have to try and not have to worry about using UBound.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator