DanDWolff
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?
Thanks
Dan
DECLARE @rc AS INT
DECLARE @sqlcmd AS VARCHAR(100)
SET @sqlcmd = 'c:\c\7.bat'
EXEC @rc = master.dbo.xp_cmdshell @sqlcmd
go
Thanks
Dan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
The .bat file is very basic it calls a .exe and passes a commandline argument to it.
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.
@echo off
cd \
cd c
c:\c\ssmgr.exe -fid 4
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.
ASKER
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
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
ASKER
I feel dumb, I forgot the sp_xp_cmdshell_proxy_accou nt. I gave that account access to the folder and all is well.
Thanks to everybody that looked at this for me.
Dan
Thanks to everybody that looked at this for me.
Dan
ASKER
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.
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???
ASKER
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.
Open in new window