Jump to content

Shellexecute not working as expected


Recommended Posts

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
Link to comment
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")

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