Results 1 to 24 of 24

Thread: Problems running .exe file - Resolved

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    10

    Unhappy 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:
    1. Dim Path, File As String
    2. Dim TaskID As Double
    3. Path = "C:\ReSynch\WorksetVersion\executable\Re_Synch.exe"
    4. File = "C:\ReSynch\WorksetVersion\executable\Parameters.txt"
    5. TaskID = Shell(Path & "" & File, 1)

    but that doesn't work. Any other ideas?
    Last edited by Tami; Jul 19th, 2005 at 08:23 AM.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Problems running .exe file

    Try adding a space between Path and File in the Shell command.
    VB Code:
    1. TaskID = Shell(Path & [b]" "[/b] & File, vbNormalFocus)

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    10

    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.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Problems running .exe file

    You may want to try using ShellExecute instead so you can explititly pass parameters.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
    4. ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    5.  
    6. Private Const SW_SHOWNORMAL As Long = 1
    7. Private Const SW_SHOWMAXIMIZED As Long = 3
    8.  
    9. Private Sub OpenSomething()
    10.     ShellExecute Me.hWnd, "Open", "C:\Test.xls", "/something /somethinglese /3", "C:\", SW_SHOWNORMAL
    11. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Problems running .exe file

    If there are spaces in your file path, you will need to enclose the path in double quotes.


    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Problems running .exe file

    Do you save the changes to your text file before you shell it?

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    10

    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:
    1. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
    2.    ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    3.  
    4.    Private Const SW_SHOWNORMAL As Long = 1
    5.    Private Const SW_SHOWMAXIMIZED As Long = 3
    6.  
    7. Function RunRe_Synch()
    8.  
    9. Dim TaskID As Double
    10. cFileName = "C:\ReSynch\WorksetVersion\executable\Re_Synch.exe"
    11. cAction = "open"
    12. cParams = "C:\ReSynch\WorksetVersion\executable\Parameters.txt"
    13.  
    14. TaskID = ShellExecute(0, cAction, cFileName, cParams, "", 1)
    15.  
    16. End Function

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Problems running .exe file

    Try changing the 0 to Me.hWnd

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  11. #11

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    10

    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.

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Problems running .exe file

    Quote 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?

  13. #13

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    10

    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

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Problems running .exe file

    Quote 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.

  15. #15

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    10

    Re: Problems running .exe file

    Okay, whops, sorry. Yea I am still new at this, I didn't realize there was a difference.

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  17. #17
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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?

  18. #18

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    10

    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.

  19. #19
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  20. #20
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Problems running .exe file

    Maybe you need to change the default directory in the shell execute statement to your app.path?

  21. #21
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Problems running .exe file

    No, don't set it to app.path, set it to the directory where the shelled application is.

  22. #22
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Problems running .exe file

    Something like this:
    VB Code:
    1. Call ShellExecute(0&, "Open", "C:\ReSynch\WorksetVersion\executable\Re_Synch.exe", _
    2.  vbNullString, "C:\ReSynch\WorksetVersion\executable", vbNormalFocus)

  23. #23
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  24. #24

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    10

    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
  •  



Click Here to Expand Forum to Full Width