URGENT! How to verify a process finished successfully using Shell or CreateProcess and close the resulting command window?

Hi all!

Here's my problem: I need to run a command line program from my VB6 application. In this case, it's sqlcmd.exe that I use to do some backup of a SQL Express 2005 database. I don't have any problem with the command line program working, I just have a problem with knowing if it succeeded or not and closing the resulting window.

The command line is:  
sqlcmd -SmyServer\SQLEXPRESS -UmyUser -PmyPWD -q"BACKUP DATABASE ARMS TO DISK = 'C:\Data\DB-04152006.dat'"

Here's my code that calls the process:

strcmd = "sqlcmd -SmyServer\SQLEXPRESS -UmyUser -PmyPWD -q"BACKUP DATABASE ARMS TO DISK = 'C:\Data\DB-04152006.dat'""

Shell strCmd, vbHide

This works great and the database gets backed up, but I can't find out how to verify that without physically checking it (after waiting long enough for the process to finish). I need to be able to give the user a prompt letting them know that it was backed up and where.

I've also tried this which also works just fine, but this leaves the DOS box open and I still don't know if it succeeded or not from within my VB6 application (just visually).

Call ExecCmd (strcmd)

Public Sub ExecCmd(stCmdline As String)

   Dim proc As PROCESS_INFORMATION
   Dim start As STARTUPINFO
   Dim ret As Long

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

   ' Start the shelled application:
   ret = CreateProcessA(0&, stCmdline, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

   ' Wait for the shelled application to finish:
   ret = WaitForSingleObject(proc.hProcess, INFINITE)
   ret = CloseHandle(proc.hProcess)
   
End Sub


What I need is a solution that runs the process and gives me some value that lets me know if it succeeded or not AND also closes the command window (DOS Box).

I've also tried ShellExecute, but can't get it to run the command at all.

Any help would be greatly appreciated!

Thanks,

Ron
LVL 1
weiroblpayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nffvrxqgrcfqvvcCommented:
Try using the /C switch in your command line this should execute your string and then terminate the dos window automatically
0
weiroblpayAuthor Commented:
Thanks eql1044, but I found I can terminate the dos window OK, I just can't tell if it ran successfully or if it failed. I need my application to be able to tell if the command ran properly or if there were errors.
0
nffvrxqgrcfqvvcCommented:
I am not familiar with the command line but you might be able to use createpipe to throw back the data to your application but this would only work if that command line actually tells you if it succeeded or failed. Does this happen?
0
nffvrxqgrcfqvvcCommented:
Here is the link

How To Create a Process for Reading and Writing to a Pipe
http://support.microsoft.com/kb/q173085/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
weiroblpayAuthor Commented:
Thanks. The link and your comments provided me with the help I needed to get confirmation of what was going on. Even better, it works by showing the dos box, then going away and giving my app what I need to verify what happened.

Thanks for your help.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.