SQL Server Performance

find current working directory

Discussion in 'General Developer Questions' started by mtmingus, Dec 16, 2003.

  1. mtmingus New Member

    there are host_name(), user_name(), but no pwd()
    according to System Functions in BOL.
  2. ChrisFretwell New Member

    You want someones password? Really? Their sql or windows password? Nope. If it was that easy, then all forms of security would be tossed out the window (windows would be tossed out too).

    There are hacks around for assorted things, but not the password.
  3. mtmingus New Member

    Sorry for the UNIX convention. I meant:

    Present Working Directory

    or current working directory.

  4. ChrisFretwell New Member

    oooohhhh. Yes, but I only know one way - there may be others, even better ones
    and it gets more than that

    xp_cmdshell 'dir *.*'

    I'm not a dos person (I went directly from mainframe to client/server) so I dont know how to find the current directory only from dos, but I'm sure its available and anything you do that way, you can do with xp_cmdshell

    Chris
  5. satya Moderator

    Use
    XP_CMDSHELL "CD" which will return the current directory

    _________
    Satya SKJ
    Moderator
    SQL-Server-Performance.Com
  6. FrankKalis Moderator

    Satya, wouldn't the output always be something like 'C:winntsystem32' ???

    I'm not sure what is meant by working directory. There are some paths stored in the registry like SQLDataRoot and SQLPath.

    Frank
    http://www.insidesql.de
    http://www.familienzirkus.de
  7. satya Moderator

    Frank

    I think it will return the default path from SQL as MSSQLBINN directory and not the windows default directory.

    I'm aware of those registry keys but as a percautionary measure didn't mentioned them.

    TA

    _________
    Satya SKJ
    Moderator
    SQL-Server-Performance.Com
  8. FrankKalis Moderator

  9. mtmingus New Member

    That's right. Using cmdshell will take you to the
    system folder, no memory of your current working directory.
    So our conclusion is, there is no way?

    quote:Originally posted by FrankKalis

    Actually I was asking because in all three cases (local, production and test server) it did return that 'c:winntsystem32'

    Frank
    http://www.insidesql.de
    http://www.familienzirkus.de
  10. FrankKalis Moderator

  11. mtmingus New Member

    I guess Current Working Directory is an irrelavent issue to
    SQL Server, that is why they don't support this idea, or,
    all queries are run from the system folder afterall.
    What I meant is, if I build my db in a particular folder,
    say, d:mydb, all my scripts are stored in d:mydbin,
    if I run one script, I like to know its absolute path
    such as d:mydbin his_script.sql
  12. FrankKalis Moderator

    Well, now I got it!
    One solution could be to open Query Analyzer -> Extras -> Options -> General and set the first value to whatever directory you like -> Save and exit.
    Then open Windows registry, search for Query Analyzer. In my case I found
    HKEY_USERS......SoftwareMicrosoftMicrosoft SQl Server80ToolsSQL Query AnalyzerOptionsGeneralTabScriptsPath the path I specified in QA.
    You can query this with the undocumented xp xp_regread.

    HTH

    Frank
    http://www.insidesql.de
    http://www.familienzirkus.de
  13. FrankKalis Moderator

    Oops, hit the button too early.

    Syntax for xp_regread is
    EXEC master.dbo.xp_regread hive, key, value [, result OUTPUT]

    where hive could be 'HKEY_LOCAL_MACHINE', 'HKEY_CLASSES_ROOT'....

    Note this xp is not documented and M$ reserves the right to change it at service pack level


    Frank
    http://www.insidesql.de
    http://www.familienzirkus.de
  14. mtmingus New Member

    Thanks Frank.

    Your answer spin off a new topic:
    using xp_regread can retreive the value of a reg key
    if you know the exact name of the key. What if I want to
    retrieve all name value pairs under one certain key, just
    like select * from <table>? Here I don't know the name
    of any sub-key, and possibly don't even know if there is
    any sub-key.


    quote:Originally posted by FrankKalis

    Oops, hit the button too early.

    Syntax for xp_regread is
    EXEC master.dbo.xp_regread hive, key, value [, result OUTPUT]

    where hive could be 'HKEY_LOCAL_MACHINE', 'HKEY_CLASSES_ROOT'....

    Note this xp is not documented and M$ reserves the right to change it at service pack level


    Frank
    http://www.insidesql.de
    http://www.familienzirkus.de
  15. Luis Martin Moderator

    If I undertand what you need use something like:

    xp_cmdshell 'dir *.exe /s'

    this give you all exe from current directory to any subdirectory under current.

    In your case:

    xp_cmdshell 'dir d:mydb *.exe /s'

    Hope help.

    Luis Martin

    ...Thus mathematics may be defined as the subject in which we never know what we are talking about, nor whether what we are saying is true.
    Bertrand Russell
  16. mtmingus New Member

    Thanks.

    quote:Originally posted by LuisMartin

    If I undertand what you need use something like:

    xp_cmdshell 'dir *.exe /s'

    this give you all exe from current directory to any subdirectory under current.

    In your case:

    xp_cmdshell 'dir d:mydb *.exe /s'

    Hope help.

    Luis Martin

    ...Thus mathematics may be defined as the subject in which we never know what we are talking about, nor whether what we are saying is true.
    Bertrand Russell
  17. FrankKalis Moderator

    It is possible, and also undocumented


    EXECUTE master.dbo.xp_regenumkeys 'HKEY_LOCAL_MACHINE', 'SOFTWAREMicrosoftMicrosoft SQL Server'
    EXECUTE master.dbo.xp_regenumvalues 'HKEY_LOCAL_MACHINE', 'SOFTWAREMicrosoftMicrosoft SQL Server'


    Frank
    http://www.insidesql.de
    http://www.familienzirkus.de
  18. mtmingus New Member

    Thanks a lot, Frank!

    quote:Originally posted by FrankKalis

    It is possible, and also undocumented


    EXECUTE master.dbo.xp_regenumkeys 'HKEY_LOCAL_MACHINE', 'SOFTWAREMicrosoftMicrosoft SQL Server'
    EXECUTE master.dbo.xp_regenumvalues 'HKEY_LOCAL_MACHINE', 'SOFTWAREMicrosoftMicrosoft SQL Server'


    Frank
    http://www.insidesql.de
    http://www.familienzirkus.de

Share This Page