Sign in to follow this  
Followers 0
Capileone

ShellExecute fails with $CmdLine parameters filled by drag & drop

4 posts in this topic

Hi,

I'd liked to pass a list of files by dragging and dropping them over a first script which, in turn, pass them as parameters of a ShellExecute() to a second script.

Total operation looks like:

Drag & drop of file_path_list -> CallTarget.au3 -> Target1.au3

Code of CallTarget.au3 is straightforward:

Const $STOP_ICON = 0x10

Dim $sParam = ""
If ($CmdLine[0] > 0) Then $sParam = $CmdLine[1]

; The same path, but put in the text code, works!
;$sParam = "C:\TMP\PROGRAM\AutoIt\BugRun\File1.txt"

Dim $nCodeShellExec
$nCodeShellExec = ShellExecute("Target1.au3", $sParam)
If NOT $nCodeShellExec Then MsgBox($STOP_ICON, @ScriptName, "ShellExecute() error #" & @error)

but it throws a system error in a modal dialog box:

   "The file "Target1.au3" cannot be found"

Followed by the AutoIt error:

   "ShellExecute() error #1"

I rewrote the script in VBScript to get the same error:

   "Error: The system cannot find the file specified.
   Code: 80070002"

It's incredible, but if I write out the path in the text code, it works!

After some search on the Net, I only found that:

https://bugs.kde.org/show_bug.cgi?id=292381

"Bug 292381 - Calligra StartApp.vbs"

Has anyone already heard something about this "bug"? Thanks for your reply.

PS.

Code for Target1.au3:

Const $INFO_ICON = 0x40

If ($CmdLine[0] > 0) Then MsgBox($INFO_ICON, @ScriptName, $CmdLine[1])

To experiment with the "bug", you need those three files in a temp. directory:
   CallTarget.au3
   Target1.au3
   File1.txt
Drag and drop File1.txt over CallTarget.au3.
 

Share this post


Link to post
Share on other sites



Maybe you could supply the full path and file name to the shellexecute function and see if that works.


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

Share this post


Link to post
Share on other sites

Yes, you're right. I replaced ShellExecute() by Run():

Dim $nRunRetCode
$nRunRetCode = Run("""C:\Program Files\AutoIt3\AutoIt3.exe"" Target1.au3 " & $sParam)
If NOT $nRunRetCode Then MsgBox($STOP_ICON, @ScriptName, "Run() error #" & @error)

and got the error message:

   Line 0 (File "C:Target1.au3")
   Error: Error opening the file

There is the issue: when you pass some parameters got by drag & drop, the script engine looks for the script to execute/to run in the root directory. Otherwise, it looks in the current directory.

Fill in the optional parameter "workingdir" of the ShellExecute() or Run() functions tames the problem.

Problem solved.
 

@BrewManNH : thanks for your reply.

Share this post


Link to post
Share on other sites

It's always wise to give the full path.

i.e. using @ScriptDir or whatever the file location is.

  • $nCodeShellExec = ShellExecute(@ScriptDir & "Target1.au3", $sParam)

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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