Solved

ShellExecute()

Posted on 2002-07-01
5
783 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
Comment Utility
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 69

Expert Comment

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

Author Comment

by:bryker
Comment Utility
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
Comment Utility
>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
Comment Utility
Just wondering.  Thanks again.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Best way to parse out a json string in VB6? 10 69
How does CurrentUser work? 10 25
Copy a row 12 52
using web browser with BING 40 80
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now