CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2003
    Location
    San Diego, California
    Posts
    49

    ShellExecute Help

    Hello, I am having problems with the following statement:

    Code:
    slAppToRun = ShellExecute(0, vbNullString, "WordPad", App.Path & """\Extension Table.txt""", vbNullString, vbNormalFocus)
    This statement works fine if my App.Path is C:\. But when my App.Path is C:\Documents and Settings\Administrator\My Documents\ it doesn't work.

    I get a message box from word pad telling me:

    C:\Documents
    Cannot find this file
    Please verify that the correct path and file name are given

    Is the error because there are spaces in my path string? How can I correct this?

    Thanks very much!
    ~Steph

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: ShellExecute Help

    It has nothing to do with the spaces. All strings use spaces as characters. Any string that you declare can have as many spaces as you want in it.

    You have to remember that the ShellExecute has the path set in it as a string called.

    Code:
    slAppToRun = ShellExecute(0, vbNullString, "WordPad", "Extension Table.txt", App.Path, vbNormalFocus)
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: ShellExecute Help

    Hi Steph,

    I have got this error before and the reason for this error is using single backslash...

    try it this way

    Code:
    Dim sPath As String
    	sPath = Replace(App.Path, "\", "\\") 
    	slAppToRun = ShellExecute(0, vbNullString, "WordPad", sPath & """\\Extension Table.txt""", vbNullString, vbNormalFocus)
    hope this helps

    --Shuja

    Edit:
    Corrected the code....Sorry for that..oops
    Last edited by vb_the_best; April 3rd, 2005 at 04:14 AM.

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: ShellExecute Help

    Question vb_the_best,

    The path/directory of the file you are trying to execute is right in the API call itself. Why not just put it there instead of putting it in the file string call in the API call? Why not just do my solution which requires no string combinations and follows the API's primary usage???

    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
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: ShellExecute Help

    Hi Peejavery,
    Nothing wrong with your code, I was just showing the other way of doing it..

    There can be hundered different ways of doing a single thing.. so people give different solutions...

    Shuja

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

Featured