running executable with shell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NasirMunir
    New Member
    • Jun 2007
    • 27

    running executable with shell

    I am trying to run an executable using shell. The executable look for certain files in the same directory and then run on those files.
    My problem: I have created a form which asks from the user to locate those files using browse option. Then I ask the user to locate the executable. The next step is to copy the executable to those files directory. Everything is dandy uptil here, but when I use the shell to run that executable, the executable doesn't run from the directory where the files are.
    the code:
    Code:
    Private Sub Command3_Click()
    
        Dim src As String
        Dim des As String
        Dim count As Integer
        Dim resDes As String
        Dim result As String
        Dim i As Integer
        Dim runExe As Double
            
        src = seiengFile ' this is the path i will be getting from user for executable
        des = sdrsFile ' path for the files on which executable will run
        
        'this for loop parse the path in order to get to the folder containing the files 
        'when user locates the file, the path will contain the file name, so I am getting
        ' the folder name which contains those files.
        For i = 0 To Len(des)
            resDes = Mid(des, Len(des) - i, 1)
            If (resDes = "\") Then
                count = Len(des) - i
                Exit For
            End If
        Next i
        result = Left(des, count)
        MsgBox (count & " " & result)  ' this shows me the right path
        FileCopy src, result + "SEIENG.exe"
        runExe = Shell(result & "SEIENG.exe", vbMaximizedFocus)
    
    End Sub
  • 9815402440
    New Member
    • Oct 2007
    • 180

    #2
    hi

    i tried your code. its fine. moving one step up in 'des' is ok if you are using common dialog box to get the path. if your using DirListBox then your file will be copied in the immididate parent of the last directory in the 'des' path.
    in this case you need to loop through the 'des' variable.




    regards
    manpreet singh dhillon hoshiarpur

    Comment

    • NasirMunir
      New Member
      • Jun 2007
      • 27

      #3
      Shell is still not working fine for me, the way I want. The executable is not running from the directory/path I am providing in the shell statement.
      Code:
      Private Sub Command3_Click()
      
          Dim src As String
          Dim des As String
          Dim Count As Integer
          Dim resDes As String
          Dim Result As String
          Dim i As Integer
          Dim runExe As Double
          Dim finPath As String
          
          
          src = seiengFile
          des = SDRSFile
          
          'NM: finding the folder that contains the sdrs files. The path is parced to locate
          'the last back slash. The location is used as a second argument for Left function to get to the folder.
          
          For i = 0 To Len(des)
              resDes = Mid(des, Len(des) - i, 1)
              If (resDes = "\") Then
                  Count = Len(des) - i
                  Exit For
              End If
          Next i
          Result = Left(des, Count)
          
          finPath = Result & "SEIENG.exe"
          Debug.Print finPath
          Debug.Print Result & "SEIENG.exe"
          FileCopy src, finPath
          runExe = Shell(finPath, vbMaximizedFocus)
          frmSeieng.Hide
      
      End Sub
      In my research so far, I read some where that perhaps I cannot use a varialbe as a path name in the shell statement. If I want to use the variable then I have to set that as an environment variable. My problem is, I don't know the path. The path will be selected by the user. I am quite sure that the path I am providing to the shell is fine: I used print command to see the result and it is good- as I want it.
      Can I get some help here?
      Thanks.

      Comment

      Working...