Solved

return value of xp_cmdshell

Posted on 2000-08-04
4
1,008 Views
Last Modified: 2012-05-04
I am creating a VB program.  I am calling the program from an SQL stored procedure using xp_cmdshell.  Xp_cmdshell returns a value of 1 for success and 0 for failure.  In the VB program how do I effect the return value of xp_cmdshell from a VB program?  
0
Comment
Question by:mnachtrab
4 Comments
 
LVL 2

Expert Comment

by:Slava_K
ID: 3785442
Why whould you do that? Can you explain.
0
 
LVL 3

Accepted Solution

by:
meos earned 25 total points
ID: 3785572
In this example, the xp_cmdshell extended stored procedure also suggests return status. The return code value is stored in the variable @result.

DECLARE @result int

EXEC @result = xp_cmdshell 'dir *.exe'

IF (@result = 0)

    PRINT 'Success'

ELSE

    PRINT 'Failure'
0
 
LVL 20

Expert Comment

by:hes
ID: 3785955
Declare this in your form (or if in a bas make it Public)

Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)

When you want to exit
If you want to send a 0
ExitProcess 0&

For a one (1)

ExitProcess 1&

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 3798154
I think you are looking for something like this:

dim adoCommand as ADODB.Command
set adoCommand = new adodb.command
with adoCommand
  .CommandText = "xp_cmdshell"
  .CommantType = adCmdStoredProc
  .Parameters.Append (.CreateParameter("command", adVarchar, adParamInput, 200, "DIR *.*" ))
  .Execute adExecuteNoRecords

  debug.print .Parameters(0).Value
End With
set adoCommand = nothing

Hope this helps
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 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…

679 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