Search code examples
shellvb6shellexecuteappdata

VB6: ShellExecute an EXE inside AppData


I have the following sub:

Public Sub ShellApp(URL As String)

        Dim vResult As Long
        vResult = ShellExecute(0, "open", URL, vbNullString, vbNullString, vbMinimizedFocus)

   End If
End Sub

This is on a layer that cannot be changed due to several functionality needed on that sub.

Now, on our Main() sub for example, we check a list of added plugins saved in a text file beside the EXE, and call the above Sub in for loop with the path of the plugins to run them. So if I have 3 plugins as below in the text file:

C:\App1.EXE

C:\App2.EXE

C:\Users\AhmadMusa\AppData\Roaming\App3.exe

First two apps will run fine on all PCs (Static path), but third app will not work on any PC except mine which is not ok... Note that App3 always installed on AppData on any PC, so how to dynamically access it to run the app from any PC without adjustments on the sub.

What will be the path placed in the text file for third app so it can work on all PCs?

I tried (AppData\Roaming\App3.exe) but it does not work... I found on a thread (http://www.vbforums.com/showthread.php?529776-RESOLVED-Open-a-folder-in-AppData) that I can call something like (shell:AppData\Roaming\App3.exe) it did not work to run the App3.exe, but if I call (shell:AppData\Roaming) it will open the Roaming folder very well. But cannot run the EXE.

Any ideas ?

Thanks.


Solution

  • I believe that there is no way to solve the problem without altering the original procedure "ShellApp".

    in case you change your mind, i think this post may come in help (with some tweekings)

    Public Sub ShellApp(URL As String)
    
            Dim vResult As Long
            'vResult = ShellExecute(0, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus)
            vResult = ShellExecute(0, vbNullString, "cmd.exe", "/k """"" & URL & """""", vbNullString, vbNormalFocus)
    
    End Sub
    
    Private Sub Command1_Click()
        ShellApp "%appdata%\PROGRAME.exe"
    
    End Sub
    

    this because only "cmd.exe" and ofcourse batch scripts are able to expend variables that are enclosed with percent character "%"

    To close the console as soon as it starts change the parameter "/k" to "/c",