473,473 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

running executable with shell

27 New Member
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 1818
9815402440
180 New Member
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
NasirMunir
27 New Member
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

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

Similar topics

4
by: Stan Sainte-Rose | last post by:
Hi guys, I would like to run a vbs script from an asp page. I ve tried many directions but no one works.. The first was : Dim oShell Set oShell = Server.CreateObject("WSCript.shell")...
3
by: John | last post by:
Hi How can I; 1. Check the existence of an exe app in a particular path such as c:\myfolder\myapp.exe, and 2. Execute the app? Thanks
2
by: Liz | last post by:
Greetings. Again, I'm hoping I'm answering an absurdly simple question. My current situation is this: I have an .exe file that contains numerous Shell commands that run an external program...
2
by: citationcj2 | last post by:
Hi All, I am trying to add an executable ass a resource and call the executable to start when I push a button. I am trying not to SHELL out to the .exe. Is this possible and if it is, How? ...
0
by: WATYF | last post by:
This is my problem... I have some code that starts a Process and returns it to a variable... (prcBat) At any time while that process is running... I want to be able to Kill it by pressing a...
11
by: Clark Stevens | last post by:
I just finished a WinForms app in VB.NET. I want to allow the user to be able to run multiple instances of the program like you can with Notepad and Wordpad. The way it is now, once I run the...
15
by: vishsid3 | last post by:
Hi guys , I am new to this forum . can anybody plz tell me - "how can I run a c executable in some directory ,while the executable is in some other directory " I am new to unix and c ,so any...
28
by: Tim Daneliuk | last post by:
I have a program wherein I want one behavior when a file is set as executable and a different behavior if it is not. Is there a simple way to determine whether a given named file is executable...
2
by: electroon | last post by:
Hi frnds, I want to know is there a way by which we can know that a C++ executable has finished its job in shell script. My task is as follows: 1.Shell script calls a executable ...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.