Solved

return value of xp_cmdshell

Posted on 2000-08-04
4
984 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 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

863 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

24 Experts available now in Live!

Get 1:1 Help Now