Solved

ShellExecute()

Posted on 2002-07-01
5
801 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBS file using code from 2nd file (txt or vbs) 4 42
Visual Studio 2005 text editor 10 43
Help me. 3 60
VBA: loop recent folder and copy txt file. 8 33
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

808 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