Sign in to follow this  
Followers 0
thepip3r

Help looping through the PATH env var to test a string against it...

4 posts in this topic

In my prog, I have an input field that I'm trying to emulate the functionality of the Run Command where say if you just type "notepad" or "calc", it will run those passed programs because notepad.exe and calc.exe exist in the PATH statement. So far as I have now, I'm grabbing the PATH var using envget() and writing it's values to an array using stringsplit. my problem is I'm not sure how I can loop through each entry of that array trying to run the value typed in the input field and testing it against each path in the PATH variable to run it if it is... this is what i have so far:

Func __mainFormRunButton()
    Local $strInputVal,$strRunVal,$tempPath,$arrPath,$y
    
    $strPathVal     = GUICtrlRead($mainFormPathCheckbox)
    $strInputVal    = GUICtrlRead($mainFormInput)
    
    If $strPathVal = 1 Then
        $tempPath = EnvGet("PATH")
        If $tempPath <> "" Then
            $arrPath = StringSplit($tempPath,";")
            
            $y=1
            ShellExecute($arrPath[$y])
            While @error<>0 Or $y <= Ubound($arrPath) Then ;<-- This is my crappy attempt to accomplish that.
                $y += 1
                ShellExecute($arrPath[$y] & "\" & $strInputVal)
            WEnd
            If @error <> 0 Then
                MsgBox(0,"",$strInputVal & " could not be located in the System Path.")
            EndIf
        Else
            MsgBox(0,"","The %PATH% variable could not be retrieved.")          
        EndIf
    Else 
        __ExecuteTryAll($strInputVal)
    EndIf   
EndFunc

When this code runs, I get the following error, "Illegal text at the end of statement (one statement per line)." -- Can anyone offer any assistance on how to better loop through the array of paths & passed input values to test whether they can be run, if not, go to the next path to test, and if so, run the program.... I'd appreciate it.


My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

While doesn't use Then. That's where you're getting the error.

While 1 = 1
WEndoÝ÷ Ù8Z·l¶©®^®Ì§µ¬@±ú+¶¬r¸©¶)àzw«jWhzÈî²×hxéeº×·öz-z{·öz-Âä~ò¢à®²+]¡ë¢¹ëh"Ýý±§jwRéeº×ºw-ìjëh«bq©eÊë¶1Ú³¥Gb´  l¡ú+)x-º.¶¸§*eÖ«­¬­çèZ0x0¢¹,~)Þjëh×6$array = StringSplit('Saunders;thepip3r;CrazeStar', ';')
For $i = 1 to $array[0]
  MsgBox(0, '', $array[$i])
Next
Edited by Saunders

Share this post


Link to post
Share on other sites

Would simplify it some to get it working the way you want then build from there.

Try this

Func __mainFormRunButton()
    Local $strInputVal,$strRunVal,$tempPath,$arrPath,$y
    
    $strPathVal     = GUICtrlRead($mainFormPathCheckbox)
    $strInputVal    = GUICtrlRead($mainFormInput)
    
    If $strPathVal = 1 Then
        $tempPath = EnvGet("PATH")
        If $tempPath <> "" Then
            $arrPath = StringSplit($tempPath,";")
            If Not @error Then
                For $i = 1 To $arrPath[0]
                    If FileExists($arrPath[$i] & '\' & $strInputVal) Then
                        ShellExecute('"' & $arrPath[$i] & '\' & $strInputVal & '"')
                        If Not @error Then
                            ExitLoop
                        EndIf
                    EndIf
                Next
            EndIf
        Else
            MsgBox(0,"","The %PATH% variable could not be retrieved.")            
        EndIf
    Else
        __ExecuteTryAll($strInputVal)
    EndIf    
EndFuncoÝ÷ ØÚ-zØZ·Mú²ÚÏjØUj(ºW[-®)ཀྵnzØZ¶+z)àr©j·¶§"{^êðØb*.­Êy*&yÊxZvfzÞ¾*.²¥¢,y¨­æ«y«"*.®)íz·¬µçZºÚ"µÍÌÍÙ[]H  ÌÎNÉ][ÝÉÌÎNÈ    [ÈÐ]
    ÌÎNÐ]]Ú]Ë^IÌÎNËH    [È ÌÎNÉ][ÝÉÌÎNÂYÝÜ[SÙÐÞ
    ÌÎNÉÌÎNË  ÌÎNÑ[]   ÌÎNÈ [È ÌÍÙ[]    [È [È [È ÌÎNÔÝ[  ][ÝÉÌÎNÈ   [ÈÛÜÚ[Ñ    [È ÌÎNÉ][ÝÉÌÎNÊB[ÙBSÙÐÞ
    ÌÎNÉÌÎNË  ÌÍÙ[]    [È ÌÎNÈÝÝ[    ÌÎNÊB[Y[ÈÐ]
    ÌÍÙ[K    ÌÍÙ]ÙXÚH
BSØØ[ ÌÍÚÙ^K  ÌÍÜ] ÌÍÜÜ]   ÌÍÚK ÌÍÙÝ[   ÌÍÚ[WÜÙXÚ ÌÍÙ[]NÈÚXÚÈ]È[YÚÝBIÌÍÚÙ^HHYÔXY
    ÌÎNÒÓIÌLÔÓÑÐTIÌLÓZXÜÜÛÙ  ÌLÕÚ[ÝÜÉÌLÐÝ[Ú[ÛÌLÐ]ÉÌLÉÌÎNÈ [È ÌÍÙ[K    ÌÎNÉÌÎNÊBRYÝÜ[BRY[Q^ÝÊ    ÌÍÚÙ^JH[ÝÝ[Ò[Ý[QÙ]]X   ÌÍÚÙ^JK ÌÎNÑ ÌÎNÊH[BBT]   ÌÍÚÙ^BBQ[YQ[YNÈÚXÚÈÞÝ[H]IÌÍÜ]H[Ù]
    ÌÎNÜ]    ÌÎNÊBRY  ÌÍÜ][BIÌÍÜÜ]HÝ[ÔÜ]
    ÌÍÜ] ÌÎNÎÉÌÎNÊBBRYÝÜ[BBQÜ  ÌÍÚHHHÈ ÌÍÜÜ]ÌBBBBRYÝ[ÔYÚ
    ÌÍÜÜ]ÉÌÍÚWKJHH  ÌÎNÉÌLÉÌÎNÈ[BBBBIÌÍÜÜ]ÉÌÍÚWHHÝ[Õ[TYÚ
    ÌÍÜÜ]ÉÌÍÚWKJBBBBQ[YBBBRY[Q^ÝÊ ÌÍÜÜ]ÉÌÍÚWH [È ÌÎNÉÌLÉÌÎNÈ [È ÌÍÙ[JH[BBBBT]    ÌÍÜÜ]ÉÌÍÚWH [È ÌÎNÉÌLÉÌÎNÈ [È ÌÍÙ[BBBBQ[YBBS^BQ[YQ[YRY ÌÍÙ]ÙXÚ[BNÈÚXÚÈÙÜ[H[ÂBIÌÍÚ[WÜÙXÚH[Q[Ý[JÙÜ[Q[Ñ [È ÌÎNÉÌLÊÌÎNÊBBRY ÌÍÚ[WÜÙXÚ ÉÝÈLH[BBUÚ[HBBBBIÌÍÙÝ[H[Q[^[J   ÌÍÚ[WÜÙXÚ
BBBBRYÜ[^]ÛÜBBBIÌÍÙ[]HÙÜ[Q[Ñ   [È ÌÎNÉÌLÉÌÎNÈ [È ÌÍÙÝ[   [È ÌÎNÉÌLÉÌÎNÈ [È ÌÍÙ[BBBBRY[Q^ÝÊ    ÌÍÙ[]
H[BBBBRY    ÌÍÙ]ÙXÚH[BBBBBQ[PÚ[ÙQÙÜ[Q[Ñ   [È ÌÎNÉÌLÉÌÎNÈ [È ÌÍÙÝ[
BBBBBQ[YBBBBT]  ÌÍÙ[]BBBQ[YBBUÑ[BQ[YQ[YTÙ]ÜJBT]   ÌÍÙ[B[[

:D

Share this post


Link to post
Share on other sites

Thanx for all the tips Saunders... they were all things I didn't know and appreciate the info.


My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume

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