Link to home
Start Free TrialLog in
Avatar of DanDWolff
DanDWolffFlag for United States of America

asked on

xp_cmdshell confused

I am trying to execute a file, tried both a .bat file that kicks off the .exe and the .exe file that I want to run.  I don't get an error, the results tab gives me a 1 and null and the messages tab says one row affected.  But the file is never executed.  I can do a directory   of the c:\c folder, and create directories in that folder using xp_cmdshell so security on the folder should be ok.  But the file is never executed.  The executable writes a log file that is how I know it doesn't execute.  Any ideas?

DECLARE @rc AS INT
DECLARE @sqlcmd AS VARCHAR(100)

SET @sqlcmd = 'c:\c\7.bat'
EXEC @rc = master.dbo.xp_cmdshell @sqlcmd
go

Open in new window


Thanks

Dan
ASKER CERTIFIED SOLUTION
Avatar of Bill Bach
Bill Bach
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DanDWolff

ASKER

Thanks for the quick response.  I double checked and Everyone has modify rights to the folder.  I did a search of my entire computer for the log file and search didn't find any copies.

I added a print command to the @RC variable after the exec command it it returns the following code in the messages tab -1066598274.  I would have expected a 1 or 0.  Going to try looking that up.

DECLARE @rc AS INT
DECLARE @sqlcmd AS VARCHAR(100)

SET @sqlcmd = 'c:\c\7.bat'
EXEC @rc = master.dbo.xp_cmdshell @sqlcmd
PRINT @RC
go

Open in new window

The .bat file cannot be interactive in any way; that is, it cannot ask qs or for any input from the caller.  You can only call code that can run directly from the command line input, not requiring any direct user input at all.
The .bat file is very basic it calls a .exe and passes a commandline argument to it.

@echo off
cd \
cd c
c:\c\ssmgr.exe -fid 4

Open in new window


ssmgr.exe doesn't have anything output the the screen either.  Presently all it does it read an sql database using the commandline and output a text file based on what it reads in the database.  Both the bat file and exe run from command prompt like they should.
it is something with my security on the folder I am trying to run the executable from.  If I move everything to the root c:\  it works just like it is supposed to.  The security on the folder that I am trying to run it from is as follows:

Everyone - modify
authenticated users - modify
system - full
domain\computername$ - modify
administrators - full
user - full - trying anything at this point but this is not an option for me when I move this to production.

Any ideas what I am missing?

Thanks

Dan
I feel dumb, I forgot the sp_xp_cmdshell_proxy_account.  I gave that account access to the folder and all is well.

Thanks to everybody that looked at this for me.

Dan
I've requested that this question be closed as follows:

Accepted answer: 0 points for DanDWolff's comment #a38419067

for the following reason:

I figured out what I missed on my own before the experts did.
it may lack the rights to write the log file to the location you wanted.
Wasn't this the crux of my first answer???