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)
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!