Solved

Run Command Line Executable Code?

Posted on 2001-06-14
10
183 Views
Last Modified: 2010-05-02
We have a function that executes a commandline and it works on NT4 but not Win2000.  Is there something different we have to do for 2000 or a way to change it to run on both?

Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ReturnValue As Integer

' Initialize the STARTUPINFO structure:
start.cb = Len(start)

' Start the shelled application:
ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
   NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

' Wait for the shelled application to finish:
Do
   ReturnValue = WaitForSingleObject(proc.hProcess, 0)
   DoEvents
Loop Until ReturnValue <> 258

ReturnValue = CloseHandle(proc.hProcess)
0
Comment
Question by:anyanicky
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 3

Expert Comment

by:RodStephens
ID: 6190960
Not an answer but a suggestion: you might try executing the command line from a DOS window in Win2000 to see what it does. Then you can at least verify that the command line can work outside of CreateProcessA.
0
 
LVL 1

Author Comment

by:anyanicky
ID: 6191140
We tried that - runs fine if we do it manually at the dos prompt.  That's what is so strange.
0
 
LVL 3

Accepted Solution

by:
casassus earned 50 total points
ID: 6191211
The return value from CreateProcess is a long and not an integer.
Try to change the data type of ReturnValue and the declaration of the function.

0
 
LVL 1

Author Comment

by:anyanicky
ID: 6191224
We tried that - runs fine if we do it manually at the dos prompt.  That's what is so strange.
0
 
LVL 1

Author Comment

by:anyanicky
ID: 6191244
The function's return value is boolean and we are setting it after that code. We don't use ReturnValue after the loop ends - it is just a "catch-all."
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 18

Expert Comment

by:deighton
ID: 6191350
he means that 32 bit createprocess api returns a long not an integer
0
 
LVL 3

Expert Comment

by:RodStephens
ID: 6191413
Yes, although the result may be a Boolean, you need to allocate a long integer to hold the result.

Are you running in the IDE on the Win2000 machine? Can you tell what the error is? Or does it just quietly not start the process?
0
 
LVL 3

Expert Comment

by:casassus
ID: 6191445
What give you the CreateProcessA function as return.
What king of program do you want to launch
0
 
LVL 1

Author Comment

by:anyanicky
ID: 6192077
This function is called from an ASP page.  The process begins and runs for a second and quits.  It runs ok on an NT4 box.
0
 
LVL 3

Expert Comment

by:casassus
ID: 6194613
You can test your procass with GetExitCodeProcess to know his state.
Try it
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

759 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

21 Experts available now in Live!

Get 1:1 Help Now