469,903 Members | 1,874 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command3_Click()
  2.  
  3.     Dim src As String
  4.     Dim des As String
  5.     Dim count As Integer
  6.     Dim resDes As String
  7.     Dim result As String
  8.     Dim i As Integer
  9.     Dim runExe As Double
  10.  
  11.     src = seiengFile ' this is the path i will be getting from user for executable
  12.     des = sdrsFile ' path for the files on which executable will run
  13.  
  14.     'this for loop parse the path in order to get to the folder containing the files 
  15.     'when user locates the file, the path will contain the file name, so I am getting
  16.     ' the folder name which contains those files.
  17.     For i = 0 To Len(des)
  18.         resDes = Mid(des, Len(des) - i, 1)
  19.         If (resDes = "\") Then
  20.             count = Len(des) - i
  21.             Exit For
  22.         End If
  23.     Next i
  24.     result = Left(des, count)
  25.     MsgBox (count & " " & result)  ' this shows me the right path
  26.     FileCopy src, result + "SEIENG.exe"
  27.     runExe = Shell(result & "SEIENG.exe", vbMaximizedFocus)
  28.  
  29. End Sub
Nov 4 '07 #1
2 1626
9815402440
180 100+
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
Nov 4 '07 #2
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.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command3_Click()
  2.  
  3.     Dim src As String
  4.     Dim des As String
  5.     Dim Count As Integer
  6.     Dim resDes As String
  7.     Dim Result As String
  8.     Dim i As Integer
  9.     Dim runExe As Double
  10.     Dim finPath As String
  11.  
  12.  
  13.     src = seiengFile
  14.     des = SDRSFile
  15.  
  16.     'NM: finding the folder that contains the sdrs files. The path is parced to locate
  17.     'the last back slash. The location is used as a second argument for Left function to get to the folder.
  18.  
  19.     For i = 0 To Len(des)
  20.         resDes = Mid(des, Len(des) - i, 1)
  21.         If (resDes = "\") Then
  22.             Count = Len(des) - i
  23.             Exit For
  24.         End If
  25.     Next i
  26.     Result = Left(des, Count)
  27.  
  28.     finPath = Result & "SEIENG.exe"
  29.     Debug.Print finPath
  30.     Debug.Print Result & "SEIENG.exe"
  31.     FileCopy src, finPath
  32.     runExe = Shell(finPath, vbMaximizedFocus)
  33.     frmSeieng.Hide
  34.  
  35. 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.
Nov 5 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Stan Sainte-Rose | last post: by
3 posts views Thread by John | last post: by
11 posts views Thread by Clark Stevens | last post: by
28 posts views Thread by Tim Daneliuk | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.