Solved

return value of xp_cmdshell

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 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

17 Experts available now in Live!

Get 1:1 Help Now