Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Trying to Execute a file using exec master.dbo.xp_cmdshell, from ASP

Reply
Thread Tools

Trying to Execute a file using exec master.dbo.xp_cmdshell, from ASP

 
 
Me
Guest
Posts: n/a
 
      11-30-2004
hi, I have this file I need to execute from an ASP client. since we
have installed it on the SQL Database server machine, I thought I
could run it
like this:


Set Cn = CreateObject("ADODB.Connection")

Cn.CursorLocation = adUseClient
Cn.ConnectionTimeout = 0
Cn.Open sConnString
Cn.Errors.Clear

If Not Cn.State = adStateOpen Then
m_sErrorData = "No active connection"
Exit Function
End If

Set Rs = CreateObject("ADODB.Recordset")
set Rs = Cn.Execute("exec master.dbo.xp_cmdshell
'C:\serverdir\test.exe usr/ProfileXXX YYY"


But, when I try this, it only works if I remove the parameter
usr/ProfileXXX YYY from the command. If I keep it, it just hangs on
the .execute command.

Strangely enough, If I try to run the same command (with the
parameter) on
the SQL Query analyzer (with the same user connection that the ASP
client uses)
it works... ( I know it works because execution proceeds to the next
line after Cn.Execute, and I get back a recordset in Rs with line
results from the executable (see below).


I have also tried to run the executable with the exec
master.dbo.xp_cmdshell command from within a stored procedure (and
then execute it from ASP)
same results. Runs only from Query analyzer...

By the way I am not doing this on ther server but on a remote machine.
Shouldn't matter though, because with Query analuyzer it does work.

I think it can only have something to do with the inclusion of the
parameter and its effects.

if the executable is run with it in query analyzer, the result in the
output grid is:

(one grid result line for each text line)

Starting Link-Run ...
0 Lines Processed out of 0
0 Elements Created with 0 Errors
NULL

(this result is ok)

but if I run it without the parameter:


Usage: 'C:\serverdir\test.exe User[/Profile] Code
NULL

I can't figure it out.

Thanks for any help....
 
Reply With Quote
 
 
 
 
Aaron [SQL Server MVP]
Guest
Posts: n/a
 
      11-30-2004
You're running it in Query Analyzer as YOU, however the ASP page is likely
running in the context of IUSR, which has a different set of security
credentials.

--
http://www.aspfaq.com/
(Reverse address to reply.)




"Me" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> hi, I have this file I need to execute from an ASP client. since we
> have installed it on the SQL Database server machine, I thought I
> could run it
> like this:
>
>
> Set Cn = CreateObject("ADODB.Connection")
>
> Cn.CursorLocation = adUseClient
> Cn.ConnectionTimeout = 0
> Cn.Open sConnString
> Cn.Errors.Clear
>
> If Not Cn.State = adStateOpen Then
> m_sErrorData = "No active connection"
> Exit Function
> End If
>
> Set Rs = CreateObject("ADODB.Recordset")
> set Rs = Cn.Execute("exec master.dbo.xp_cmdshell
> 'C:\serverdir\test.exe usr/ProfileXXX YYY"
>
>
> But, when I try this, it only works if I remove the parameter
> usr/ProfileXXX YYY from the command. If I keep it, it just hangs on
> the .execute command.
>
> Strangely enough, If I try to run the same command (with the
> parameter) on
> the SQL Query analyzer (with the same user connection that the ASP
> client uses)
> it works... ( I know it works because execution proceeds to the next
> line after Cn.Execute, and I get back a recordset in Rs with line
> results from the executable (see below).
>
>
> I have also tried to run the executable with the exec
> master.dbo.xp_cmdshell command from within a stored procedure (and
> then execute it from ASP)
> same results. Runs only from Query analyzer...
>
> By the way I am not doing this on ther server but on a remote machine.
> Shouldn't matter though, because with Query analuyzer it does work.
>
> I think it can only have something to do with the inclusion of the
> parameter and its effects.
>
> if the executable is run with it in query analyzer, the result in the
> output grid is:
>
> (one grid result line for each text line)
>
> Starting Link-Run ...
> 0 Lines Processed out of 0
> 0 Elements Created with 0 Errors
> NULL
>
> (this result is ok)
>
> but if I run it without the parameter:
>
>
> Usage: 'C:\serverdir\test.exe User[/Profile] Code
> NULL
>
> I can't figure it out.
>
> Thanks for any help....



 
Reply With Quote
 
 
 
 
Me
Guest
Posts: n/a
 
      11-30-2004
"Aaron [SQL Server MVP]" <(E-Mail Removed)> wrote in message news:<u9#(E-Mail Removed)>...
> You're running it in Query Analyzer as YOU, however the ASP page is likely
> running in the context of IUSR, which has a different set of security
> credentials.


but, (as I mentioned) I made sure that the Query analyzer connection uses
the same SQL login/pass as the ASP client connection....

what other login is there?
 
Reply With Quote
 
Aaron [SQL Server MVP]
Guest
Posts: n/a
 
      11-30-2004
Get Filemon:
http://www.sysinternals.com/ntw2k/source/filemon.shtml

If you run this while trying with each method, you should see the
difference.

--
http://www.aspfaq.com/
(Reverse address to reply.)




"Me" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> "Aaron [SQL Server MVP]" <(E-Mail Removed)> wrote in message

news:<u9#(E-Mail Removed)>...
> > You're running it in Query Analyzer as YOU, however the ASP page is

likely
> > running in the context of IUSR, which has a different set of security
> > credentials.

>
> but, (as I mentioned) I made sure that the Query analyzer connection uses
> the same SQL login/pass as the ASP client connection....
>
> what other login is there?



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Net::SSH.exec Using the "exec" method interactively Guillermo Riojas Ruby 0 11-26-2010 05:17 PM
Runtime.exec(String[]) Doesn't Always Work, bBut Runtime.exec(String) Does Hal Vaughan Java 11 05-22-2006 04:49 PM
Can i execute aspx file in my asp pag with server.execute method(sorry) Savas Ates ASP General 1 08-17-2004 04:52 PM
exec "statement" VS. exec "statement" in globals(), locals() tedsuzman Python 2 07-21-2004 08:41 PM
Backup Exec 9.1: The Backup Exec job engine system service is not responding Christian Falch Computer Support 1 06-23-2004 02:22 AM



Advertisments