xp_CDMShell ''Path''

  • 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

     

  • 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


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • 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.

     

  • 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


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • 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.

     

     

     

  • 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 !

     

  • 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