|
-
Jul 18th, 2005, 10:25 AM
#1
Thread Starter
New Member
Problems running .exe file - Resolved
Hey all,
I am new so sorry if this has a simple solution.
Okay, I am creating a form in excel that outputs the data entered into the table into a text file, parameters.txt. An in house re_synch.exe file uses the information in parameters.txt to get the newest version of a set of files on to the user's pc.
Right now my program works so that I can put whatever I want in parameters.txt then click start run re_synch.exe.
I want my vb program to call the .exe file and have it automaticaly run so the user doesn't have to manually open it.
The problem is when I use the shell command, the .exe file opens but it fails to read the information in parameters.txt and instead asks for user input like it is supposed to if parameters.txt is blank.
How do I fix this?
I tried
VB Code:
Dim Path, File As String
Dim TaskID As Double
Path = "C:\ReSynch\WorksetVersion\executable\Re_Synch.exe"
File = "C:\ReSynch\WorksetVersion\executable\Parameters.txt"
TaskID = Shell(Path & "" & File, 1)
but that doesn't work. Any other ideas?
Last edited by Tami; Jul 19th, 2005 at 08:23 AM.
-
Jul 18th, 2005, 10:35 AM
#2
Re: Problems running .exe file
Try adding a space between Path and File in the Shell command.
VB Code:
TaskID = Shell(Path & [b]" "[/b] & File, vbNormalFocus)
-
Jul 18th, 2005, 10:54 AM
#3
Thread Starter
New Member
Re: Problems running .exe file
I actually had a space in my code. When I rewrote it to post it on here I forgot and left it out.
The program opens but it still doesn't read the parameters.txt file.
-
Jul 18th, 2005, 11:05 AM
#4
Re: Problems running .exe file
You may want to try using ShellExecute instead so you can explititly pass parameters.
VB Code:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Sub OpenSomething()
ShellExecute Me.hWnd, "Open", "C:\Test.xls", "/something /somethinglese /3", "C:\", SW_SHOWNORMAL
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 18th, 2005, 11:07 AM
#5
Re: Problems running .exe file
If there are spaces in your file path, you will need to enclose the path in double quotes.
Pradeep
-
Jul 18th, 2005, 11:28 AM
#6
Re: Problems running .exe file
With ShellExecute you dont need to worry about spaces in the file path.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 18th, 2005, 11:36 AM
#7
Re: Problems running .exe file
Do you save the changes to your text file before you shell it?
-
Jul 18th, 2005, 01:13 PM
#8
Thread Starter
New Member
Re: Problems running .exe file
Okay thanks for all the help.
I tried using ShellExecute and the program still didn't seem to be reading the paramaters.txt file. And yes I am saving the text file before I close it. The code I have is below.
VB Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Function RunRe_Synch()
Dim TaskID As Double
cFileName = "C:\ReSynch\WorksetVersion\executable\Re_Synch.exe"
cAction = "open"
cParams = "C:\ReSynch\WorksetVersion\executable\Parameters.txt"
TaskID = ShellExecute(0, cAction, cFileName, cParams, "", 1)
End Function
-
Jul 18th, 2005, 01:39 PM
#9
Re: Problems running .exe file
Try changing the 0 to Me.hWnd
-
Jul 18th, 2005, 01:40 PM
#10
Re: Problems running .exe file
Unless the program is expecting a file, you will have to read the file, and pass the info as a string as the parameters.
-
Jul 18th, 2005, 02:12 PM
#11
Thread Starter
New Member
Re: Problems running .exe file
When I change the 0 to Me.hwnd I get an error that says "Method or data member not found"
As for the parameters the program should be expecting a .txt file. It is supposed to check parameters.txt before it runs. Which it does when I open it from start, run, but not when I try to open it in vb using ShellExecute.
-
Jul 18th, 2005, 02:14 PM
#12
Re: Problems running .exe file
 Originally Posted by Tami
When I change the 0 to Me.hwnd I get an error that says "Method or data member not found"
And you are doing this from a Visual Basic 6.0 Form?
-
Jul 18th, 2005, 02:17 PM
#13
Thread Starter
New Member
Re: Problems running .exe file
I think so... well in Microsoft Excel. And when I click on Microsoft Visual Basic, Help about, it says Microsoft Visual Basic 6.3
-
Jul 18th, 2005, 02:24 PM
#14
Re: Problems running .exe file
 Originally Posted by Tami
I think so... well in Microsoft Excel. And when I click on Microsoft Visual Basic, Help about, it says Microsoft Visual Basic 6.3
Ok, that is why you get that. You really aren't using Visual Basic. You are using Visual Basic for Applications (VBA), and the syntax can be quite different between the two.
Folks responding to this need to know that or they will be taking you down the Visual Basic path which may, or may not, work in VBA.
-
Jul 18th, 2005, 02:26 PM
#15
Thread Starter
New Member
Re: Problems running .exe file
Okay, whops, sorry. Yea I am still new at this, I didn't realize there was a difference.
-
Jul 18th, 2005, 02:29 PM
#16
Re: Problems running .exe file
Still VB6 and Office VBA are very similar. 
You can use Application.Hwnd for Excel to pass the the ShellExecute instead of Me.hWnd.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 18th, 2005, 02:44 PM
#17
Re: Problems running .exe file
But passing the hWnd is not the problem. You can just as well pass 0 as you do and the desktop will be used for your app, that's what's happening if you simply launch the application.
When you start that app from the Run dialog box, how do you then launch it?
-
Jul 18th, 2005, 03:46 PM
#18
Thread Starter
New Member
Re: Problems running .exe file
When I run it. I go to start, run, and then just type the location of the .exe file and click ok. When I do this the program recognizes the parameters.txt file (b/c the code of the .exe file tells it to look for this file) and automaticaly gets the files from the source directory and copys them to the target directory based on the information in parameters.txt.
But the problem is when I try to run the file by using shellexecute() the .exe file comes up but waits for user input for the source directory and the target directory. This is what should happen if parameters.txt is blank. So that is why I think when I open the file with vb it isn't looking for parameters.txt for some reason.
But I still have no idea why.
-
Jul 18th, 2005, 03:55 PM
#19
Re: Problems running .exe file
You need to pass the complete path with the parameters.txt file if its not in the working directory specified in the working
directory parameter of the ShellExecute API.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 18th, 2005, 04:00 PM
#20
Re: Problems running .exe file
Maybe you need to change the default directory in the shell execute statement to your app.path?
-
Jul 18th, 2005, 04:35 PM
#21
Re: Problems running .exe file
No, don't set it to app.path, set it to the directory where the shelled application is.
-
Jul 18th, 2005, 04:37 PM
#22
Re: Problems running .exe file
Something like this:
VB Code:
Call ShellExecute(0&, "Open", "C:\ReSynch\WorksetVersion\executable\Re_Synch.exe", _
vbNullString, "C:\ReSynch\WorksetVersion\executable", vbNormalFocus)
-
Jul 18th, 2005, 04:46 PM
#23
Re: Problems running .exe file
You only need to set the working directory (5th parameter) as Joacim posted. Since the app looks in its app
path (shelled app) for the parameters.txt file it doesnt need to be passed as a parameter.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 19th, 2005, 08:22 AM
#24
Thread Starter
New Member
Re: Problems running .exe file
Thank you guys so much!!
I got it working now, by changing the parameter from "C:\ReSynch\WorksetVersion\executable\parameters.txt" to "C:\ReSynch\WorksetVersion\executable"
Thanks Again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|