Jump to content

Recommended Posts

Posted (edited)

Hello,

I have a problem, is simply in theory but i can't find a solution. I have one inputbox and two button, one for select the file and one for launch the file.

The possible scenario are:

1) User select a file to launch

2) User select an .exe to lauch

For both two i can use ShellExecute. But there is also a third case:

3) User select an exe and add a command line parameter

I theory in that case i can use Run or second parameter of ShellExecute, but i don't know if there is a command line parameter. Example:

C:\Test.txt
C:\WINDOWS\NOTEPAD.EXE
C:\WINDOWS\NOTEPAD.EXE /a "C:\Test.txt"

How i can make one function for launch all of the three cases? I'll hope i was clear. A simply "ready to use" script

$sTest = "C:\Test.txt"
_ShellEx($sTest) ; work

Sleep(1000)

$sTest = "C:\WINDOWS\NOTEPAD.EXE"
_ShellEx($sTest) ; work

Sleep(1000)

$sTest = 'C:\WINDOWS\NOTEPAD.EXE /a "C:\Test.txt"'
_ShellEx($sTest) ; NOT work

Func _ShellEx($sPath)
    ShellExecute($sPath)
    ; and now?
EndFunc

 

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Posted (edited)

Maybe:

Global $iFile = "C:\Test.txt"
Global $iApp = @HomeDrive & "\WINDOWS\NOTEPAD.EXE"

; S> TEST FILE
#RequireAdmin
If Not FileExists($iFile) Then FileWrite($iFile, "TEST-XXX")
; E> TEST FILE

_ShellEx($iFile)
Sleep(1000)

_ShellEx($iApp, $iFile)
Sleep(1000)

_ShellEx($iApp)
Sleep(1000)

Local $sTest = '"' & $iApp & '" /a "' & $iFile & '"'
_ShellEx($sTest)


Func _ShellEx($iFilename, $iParameters = "", $iWorkingDir = @WorkingDir)
    Local $iCheck = StringInStr($iFilename, '"'), $iReturn = 0
    If FileExists($iFilename) Then
        If $iCheck Then
            $iReturn = ShellExecute($iFilename, $iParameters, $iWorkingDir)
        Else
            $iReturn = ShellExecute('"' & $iFilename & '"', $iParameters, $iWorkingDir)
        EndIf
    Else
        If $iCheck Then
            If ($iParameters = "") Then
                $iReturn = Run($iFilename, $iWorkingDir)
            Else
                $iReturn = Run($iFilename & ' ' & $iParameters, $iWorkingDir)
            EndIf
        Else
            If ($iParameters = "") Then
                $iReturn = Run('"' & $iFilename & '"', $iWorkingDir)
            Else
                $iReturn = Run('"' & $iFilename & '" ' & '"' & $iParameters & '"', $iWorkingDir)
            EndIf
        EndIf
    EndIf
    Return SetError(@error, @extended, $iReturn)
EndFunc   ;==>_ShellEx

 

Edited by VIP

Regards,
 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...