February 7, 2007 at 7:13 am
Hi
I was wondering if anyone could bring any light to the following.
in a command prompt window run this !
Path
IN a SQL query window run this !
ExEC xp_CMDSHell 'Path'
When I do this I get different paths.
the question is how do you add new paths to the xp_CMDSHell 'Path' ?
Hence enabling xp_cmdSHell to have visibility of other exe's.
one way seems to be to change the environment variable path and reboot the server! I was wondering if anyone knows how to change it at run time! e.g. add a path run xp_cmdSHell then remove it !
Thanks
February 7, 2007 at 7:37 am
PATH is session specific... and each use of xp_CmdShell creates a new session. The only way to do this is to make sure that whatever code you are running contains both the PATH assignment and all of the rest of the code. Probably the best thing to do is create a .Bat or .Cmd file with all of the instructions in it and then execute that. And, there's no need to remove the added path... as soon as the session ends, it'll go away.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 8, 2007 at 5:29 am
Using the SET command should take care of what you are trying to do.
You probably want to do something like SET PATH=%PATH%;Additional Path.
February 8, 2007 at 6:29 am
Doh! I missed that part of the question. Yes, Ron is correct but do remember what I said... It's session specific from SQL Server.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 8, 2007 at 6:34 am
The safest way would be to specify the path to everything in the batch script. That will insulate your highly-priviledged batch file from being affected by what other people, processes, and things do to your environment variables.
February 12, 2007 at 4:14 am
WOW ! Thanks for all the reponses!
I appreciate all the comments.
The main issue I have is that there is some process which I am trying to track down that seems to change this "session path" --- permanently. i.e. it changes the path for all sessions not just one session ! I suspect it is some code somehwere that is changing the Path instead of Appending to it!
I have set up a job to check the path every hour and let me know when it changes to try indentify which process is changing this path -- well at least give me a time frame to search logs-- This job just runs "EXEC xp_CmdShell 'Path'" and compares this to the value it is when the system is restarted -- if it is not this value it lets me know.
Does anyone know where this "Default" session path is held and how to change it. Because until I can find the subsystem that keeps changing this path I need a means by which to set it ! (I have started writing this as a batch file as suggested.) finally knowing the code that would change this path (Gloablly -- not change just for the current sesssion) enables me to search for those keyword in code !
thanks for clarifying that Set Path is session specific. I was pulling my har out wondering why when I set it it did not persist.
Thanks again !
February 12, 2007 at 6:46 am
MyComputer >> Properties Advanced tab.
There is a button labeled "Environment Variables". Therein you can set the system environment and the environment for the current user.
This is on my XP box. It should be substantially similar for 2000 or 2003.
I'm sticking by using explicit paths for security reasons.
jg
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply