Jump to content

Recommended Posts

Posted

I made a generic "shortcut" script with a configurable ini file. I thought about using it to launch an explorer browser for a network share but for some reason there's a weird behavior.

Here's the code:

#include <Misc.au3>
Opt("MustDeclareVars", 1)
Opt("ExpandEnvStrings", 1)
Opt("ExpandVarStrings", 1)
HotKeySet("{PAUSE}", "_Close")
Func _Close()
    Exit
EndFunc

Global $error = 0
Global $ininame = "_" & StringReplace(@ScriptName, ".exe", "") & ".ini"
Global $section = "Options"
If Not FileExists($ininame) Then
    MsgBox(0x2000, "Error", """" & $ininame & """ not found! Creating file.")
    IniWrite($ininame, $section, "Path", "")
    IniWrite($ininame, $section, "WorkingDir", ".\")
    IniWrite($ininame, $section, "Flag", "")
    IniWrite($ininame, $section, "Wait", "1")
    IniWrite($ininame, $section, "Password", "<none>")
    Exit
EndIf
Global $path = StringStripWS(IniRead($ininame, $section, "Path", ""), 3)
Global $wdir = StringStripWS(IniRead($ininame, $section, "WorkingDir", ".\"), 3)
Global $flag = StringStripWS(IniRead($ininame, $section, "Flag", ""), 3)
Global $wait = Int(StringStripWS(IniRead($ininame, $section, "Wait", "1"), 3))
Global $password = StringStripWS(IniRead($ininame, $section, "Password", "<none>"), 3)
Global $pass = False

If StringCompare($password, "<none>") == 0 Then
    $pass = True
Else
    Local $input
    Local $error = 1
    While $error <> 0
        $input = InputBox("Please Enter Password", "Password:", "", "*", 200, 120)
        $error = @error
    WEnd
    If StringCompare($password, $input) == 0 Then
        $pass = True
    Else
        MsgBox(0x2000, "Error", "Invalid password!")
    EndIf
EndIf
If $pass Then
    If StringLen($path) > 0 Then
        If StringLen($wdir) == 0 Then
            $wdir = ".\"
        EndIf
        If StringLen($flag) > 0 Then
            If $wait Then
                RunWait($path, $wdir, $flag)
                $error = @error
            Else
                Run($path, $wdir, $flag)
                $error = @error
            EndIf
        Else
            If $wait Then
                RunWait($path, $wdir)
                $error = @error
            Else
                Run($path, $wdir, $flag)
                $error = @error
            EndIf
        EndIf
        If $error Then
            MsgBox(0x2000, "Error", """" & $path & """ not found!")
        EndIf
    Else
        MsgBox(0x2000, "Error", "No path specified!")
    EndIf
EndIf

Now, the weird bit is that when I set the 'path' key to 'explorer.exe /n' with the 'wait' key set to 1, the script correctly opens a new windows explorer window. However, if the 'wait' key is set to 0, a new explorer.exe process just runs and no window displays. Note that all $wait does is just switch between using Run and RunWait for calling the program set in 'path'.

Also, I don't think the 'flag' key works properly, so don't bother trying to use it. It's not part of my issue.

Posted

RunWait ( "filename" [, "workingdir" [, show_flag [, opt_flag ]]] )

Run ( "filename" [, "workingdir" [, show_flag[, opt_flag ]]] )

See that the third parameter is the show flag ? Only the filename param. is mandatory.

Check the value of the third parameter.

Posted (edited)

Oops! Didn't see that extra $flag there. Stupid copy/pasta coding techniques... @_@

Works fine now. Even fixed it so the flags can also be used.

#include <Misc.au3>
Opt("MustDeclareVars", 1)
Opt("ExpandEnvStrings", 1)
Opt("ExpandVarStrings", 1)
HotKeySet("{PAUSE}", "_Close")
Func _Close()
    Exit
EndFunc
Func _GetFlag($input)
    Switch $input
        Case 1
            Return @SW_HIDE
        Case 2
            Return @SW_MINIMIZE
        Case 3
            Return @SW_MAXIMIZE
    EndSwitch
    Return 0
EndFunc

Global $error = 0
Global $ininame = "_" & StringReplace(@ScriptName, ".exe", "") & ".ini"
Global $section = "Options"
If Not FileExists($ininame) Then
    MsgBox(0x2000, "Error", """" & $ininame & """ not found! Creating file.")
    Local $file = FileOpen($ininame, 2)
    FileWriteLine($file, ";INI file for Process Shortcut")
    FileWriteLine($file, ";")
    FileWriteLine($file, ";INI file format is:")
    FileWriteLine($file, ";[Options]")
    FileWriteLine($file, ";KEY = VALUE")
    FileWriteLine($file, ";")
    FileWriteLine($file, ";Key(s) are: Path, WorkingDir, Flag, Wait, Password")
    FileWriteLine($file, ";")
    FileWriteLine($file, ";Path -> path of executable")
    FileWriteLine($file, ";WorkingDir -> working directory")
    FileWriteLine($file, ";Flag -> 0 = none")
    FileWriteLine($file, ";        1 = @SW_HIDE")
    FileWriteLine($file, ";        2 = @SW_MINIMIZE")
    FileWriteLine($file, ";        3 = @SW_MAXIMIZE")
    FileWriteLine($file, ";Wait -> 0 = wait for program finish")
    FileWriteLine($file, ";        1 = close script immediately")
    FileWriteLine($file, ";Password -> password to run program, <none> for no password")
    FileWriteLine($file, "[Options]")
    FileWriteLine($file, "Path")
    FileWriteLine($file, "WorkingDir")
    FileWriteLine($file, "Flag")
    FileWriteLine($file, "Wait=1")
    FileWriteLine($file, "Password=<none>")
    FileClose($file)
    Exit
EndIf
Global $path = StringStripWS(IniRead($ininame, $section, "Path", ""), 3)
Global $wdir = StringStripWS(IniRead($ininame, $section, "WorkingDir", ".\"), 3)
Global $flag = _GetFlag(IniRead($ininame, $section, "Flag", ""))
Global $wait = Int(StringStripWS(IniRead($ininame, $section, "Wait", "1"), 3))
Global $password = StringStripWS(IniRead($ininame, $section, "Password", "<none>"), 3)
Global $pass = False

If StringCompare($password, "<none>") == 0 Then
    $pass = True
Else
    Local $input
    Local $error = 1
    While $error <> 0
        $input = InputBox("Please Enter Password", "Password:", "", "*", 200, 120)
        $error = @error
    WEnd
    If StringCompare($password, $input) == 0 Then
        $pass = True
    Else
        MsgBox(0x2000, "Error", "Invalid password!")
    EndIf
EndIf
If $pass Then
    If StringLen($path) > 0 Then
        If StringLen($wdir) == 0 Then
            $wdir = ".\"
        EndIf
        If $flag <> 0 Then
            If $wait Then
                RunWait($path, $wdir, $flag)
                $error = @error
            Else
                Run($path, $wdir, $flag)
                $error = @error
            EndIf
        Else
            If $wait Then
                RunWait($path, $wdir)
                $error = @error
            Else
                Run($path, $wdir)
                $error = @error
            EndIf
        EndIf
        If $error Then
            MsgBox(0x2000, "Error", """" & $path & """ not found!")
        EndIf
    Else
        MsgBox(0x2000, "Error", "No path specified!")
    EndIf
EndIf
Edited by omikron48

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
×
×
  • Create New...