Solved

ShellExecute()

Posted on 2002-07-01
5
808 Views
Last Modified: 2008-02-26
==========================
VB.NET
Windows 2000
==========================

(Though I'm using VB.NET, I think I would have this same problem with VB6, and this forum gets so much more traffic...so I'm posting the question here...)

I guess I've never called ShellExecute() with command-line parameters, because I'm sure not able to do so successfully today.

I need to call an executable with a (possibly long) list of switches and parameters.  Here's my code at the moment:

======START CODE======
   Public Const SW_SHOWDEFAULT As Integer = 10
   Public 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
   ...
   Dim nTemp As Long
   Dim sEXEPath As String
   Dim sFilePath As String
   ...
   sEXEPath = "C:\dev\XML\XMILL\win32\XMILL.EXE"
   sFilePath = "C:\~RexDB.XML"

   nTemp = ShellExecute(0, "open", sEXEPath, sFilePath, "", SW_SHOWDEFAULT)

======END CODE======

This .EXE always produces an output file at the path of the file it's provided ("sFilePath" above).  The absence of this file tells me it's not working.  It works just fine through the DOS window ("C:\dev\XML\XMILL\win32\XMILL.EXE C:\~RexDB.XML").

How do I call this from VB.NET?  I've tried several different things, but no luck thus far.

Thanks

0
Comment
Question by:bryker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 100 total points
ID: 7122698
Why are you using shellexecute instead of simply shell?  ShellExecute opens a file with it's associated exe.  shell simply executes a command as if it was at the command line (almost.)
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7122725
have you looked at the Shell function (see the help file for "Shell function").
0
 

Author Comment

by:bryker
ID: 7122803
Mr. Hewson:

Works great--thanks for the help.  Don't know why I wasn't using Shell.

By the way, what do you mean by "as if it was at the command line (almost)"?  Does it have some constraints, or things it won't do?(piping output, switches, something like that?)
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 7123018
>piping output,

When you try to use it to redirect StdOut using ">" to a file, Shell (and associated win32 api methods) will not perform the redirect.  There are ways around it however, if it is necessary to redirect from the command line.
0
 

Author Comment

by:bryker
ID: 7123130
Just wondering.  Thanks again.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question