Solved

ShellExecute()

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…
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…

770 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