Sign in to follow this  
Followers 0
Ventura

Shellexecute not working as expected

4 posts in this topic

#1 ·  Posted (edited)

I have created a simple gui tool to open files for me and create shortcut in script dir, but actually ShellExecute doesn't work when I select the text file and open it from gui.. and the shortcut file is there.. but it works when I close the gui and open it again.. so what am I doing wrong? code here...

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form = GUICreate("Open", 154, 76, 399, 245)
$Button = GUICtrlCreateButton("Open file", 32, 24, 89, 33)
GUISetState(@SW_SHOW)

If FileExists("text.lnk") = True Then
    GUICtrlSetData($Button, "Open text")
Else
    GUICtrlSetData($Button, "Open file")
EndIf

While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
        Case $Button
            Switch GUICtrlRead($Button)
                Case "Open file"
                    $Dialog = FileOpenDialog("Select text", "\", "(*.txt)", "", "")
                    If Not @error Then
                        FileCreateShortcut($Dialog, @ScriptDir & "\text.lnk")
                    EndIf
                    GUICtrlSetData($Button, "Open text")
                Case "Open text"
                    ShellExecute("text.lnk")
            EndSwitch
    EndSwitch
WEnd

 

Edited by Ventura

Share this post


Link to post
Share on other sites



Worked fine for me as written IF the text file was in same dir as the script. Otherwise "Windows can't find text.lnk".

What made it work was: Case "Open text"

                                            ShellExecute(@ScriptDir & "\text.lnk")

1 person likes this

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@J2team tested and it didn't work 

@lorenkinzel it works.. didn't think I was missing that part hehe

Edited by Ventura

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