bryker
asked on
ShellExecute()
==========================
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\XM ILL.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\X MILL.EXE C:\~RexDB.XML").
How do I call this from VB.NET? I've tried several different things, but no luck thus far.
Thanks
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\XM
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\X
How do I call this from VB.NET? I've tried several different things, but no luck thus far.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
have you looked at the Shell function (see the help file for "Shell function").
ASKER
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?)
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?)
>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.
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.
ASKER
Just wondering. Thanks again.