locked
Searching within registry and replacing the lefthand side of paths RRS feed

  • Question

  • Hi,

    I am changing over some locations on our network and I need to rewrite any registry keys holding UNC paths...

    Example:

    Homeshare Old Location \\server1\xyz\username\homedatafiles\

    Homeshare New location \\server10\abc\username\data

    As the machine will only be able to find the new homeshare from the environment variable I was intending on doing the following...

    1. Fine any key with "homedatafiles" in it
    2. Replace the left hand section of any string containing this with the new homeshare location

    So for example if it finds:

    \\server1\xyz\username\homedatafiles\help\sheet1.htm

    It will replace it with

    \\server10\abc\username\data\help\sheet1.htm

    So I basically need to know how to get it to change all the to the left and including the data we have found.

    Thanks

    Tuesday, May 29, 2012 10:33 AM

Answers

  • Hi,

    I am changing over some locations on our network and I need to rewrite any registry keys holding UNC paths...

    Example:

    Homeshare Old Location \\server1\xyz\username\homedatafiles\

    Homeshare New location \\server10\abc\username\data

    As the machine will only be able to find the new homeshare from the environment variable I was intending on doing the following...

    1. Fine any key with "homedatafiles" in it
    2. Replace the left hand section of any string containing this with the new homeshare location

    So for example if it finds:

    \\server1\xyz\username\homedatafiles\help\sheet1.htm

    It will replace it with

    \\server10\abc\username\data\help\sheet1.htm

    So I basically need to know how to get it to change all the to the left and including the data we have found.

    Thanks

    That is not in the regeistry it is in active Directory.  Just change all of the users AD homeshare path with any of the AD tools.


    ¯\_(ツ)_/¯

    Tuesday, May 29, 2012 10:48 AM

All replies

  • Hi,

    I am changing over some locations on our network and I need to rewrite any registry keys holding UNC paths...

    Example:

    Homeshare Old Location \\server1\xyz\username\homedatafiles\

    Homeshare New location \\server10\abc\username\data

    As the machine will only be able to find the new homeshare from the environment variable I was intending on doing the following...

    1. Fine any key with "homedatafiles" in it
    2. Replace the left hand section of any string containing this with the new homeshare location

    So for example if it finds:

    \\server1\xyz\username\homedatafiles\help\sheet1.htm

    It will replace it with

    \\server10\abc\username\data\help\sheet1.htm

    So I basically need to know how to get it to change all the to the left and including the data we have found.

    Thanks

    That is not in the regeistry it is in active Directory.  Just change all of the users AD homeshare path with any of the AD tools.


    ¯\_(ツ)_/¯

    Tuesday, May 29, 2012 10:48 AM
  • There is no need to hack the registry to change environmental variables. The following commands will do it more elegantly:

    set HomeShare=\\server10\abc\username\data
    setx  /M HomeShare 
    \\server10\abc\username\data

    Tuesday, May 29, 2012 10:53 AM
  • There is no need to hack the registry to change environmental variables. The following commands will do it more elegantly:

    set HomeShare=\\server10\abc\username\data
    setx  /M HomeShare 
    \\server10\abc\username\data

    'Homeshare' is not an environment variable.

    Paths in the registry either come from Active Directory or from the mapping of drives.  Usually the drives are mapped via GP or a logon script.

    To update these you can either modify or change the logon script or use Group Policy Preferences.  To modify the aD setting use one of the AD tools.

    The OP is trying to search within strings in the registry and update all references.  It would be better toknow which locations are needed.  Almost all are handled as I noted above.  SOme usage beause a program will remember a UNC can usually be ignored.  The user will just have to reaquire the path.

    Searching the registry in a logon script for a part of a string can take a very long time.  You do not want to do this.  Tools that mangage the registry do this by dumping the registry to a text file and searching the text which is much faster but requires some tricky programming to extract the location from the surrounding text.  This still takes a long time.

    As an example.  To search for the string :homedatapat" within every registry key would require enumerating every key in the registry to all levels then reading every value under every key and doing a string match for the value. 

    Look in the repository to see any registry search ing code.  I suspect yu will not find it as no one has found much use for writing this code.

    You can experiment with POwerShell because it can search deep but is stillvery sloe.

    Get-ChildItem hkcu: -rec |%{get-itemproperty $_}|%{$_.psbase.Properties}|?{$_.value -match 'homedatafiles'}

    I stated running this on my profile about 5 minutes ago and it still hasn't completed.  It will also throw exceptions on every empty key.  You can ignore these or add -ea 0.


    ¯\_(ツ)_/¯

    Tuesday, May 29, 2012 11:31 AM
  • 'Homeshare' is not an environment variable.

    ¯\_(ツ)_/¯

    Since the OP wrote "As the machine will only be able to find the new homeshare from the environment variable" I assumed that he created his own variable.
    Tuesday, May 29, 2012 11:35 AM
  • 'Homeshare' is not an environment variable.

    ¯\_(ツ)_/¯

    Since the OP wrote "As the machine will only be able to find the new homeshare from the environment variable" I assumed that he created his own variable.

    YOu may be correct but I don't think so.  I have seen this question before and it has tracked back to 'homedrive' and homefolder' on AD.  The users were assumoiing it got into teh environment from the registry but it is injected by AD.  The custom paths in most cases are from a tool and may be rewritten by the tool or they are injected via a login script.

    The other big item is relocating the My Documents to a server share which is very popular.  If we use Grop Policy we can move this tranpartently any time we want.  If it has been done manually we can still use a GP to move it.  There is no need to use teh registry and I recommend usng a GP for future reliability.

    If this is just a passive manual entry applied by manually editing the environment then your method will probably work except for the HOMEDRIVE and HOMEPATH variables which will/can be set by AD.

    This is not about the environment:

    So for example if it finds:

    \\server1\xyz\username\homedatafiles\help\sheet1.htm

    It will replace it with

    \\server10\abc\username\data\help\sheet1.htm

    That is a request to modify 'recently used' lists.  That I addressed in teh issue of "WHY?"  the tools and the user can fix that esily.  DOing it in a logon script would relaly pu the user out of business.  Doing it with an optional user executed script would be OK but you would have to have a lot of patience.  My test with PowerShell is still running after 15 minutes.  Now I have a large hive because of al of teh development tools but even on a smaller hive the search can take over 5 minutes.


    ¯\_(ツ)_/¯

    Tuesday, May 29, 2012 11:57 AM
  • Dooley_Do,

    Are your home folders specified in Active Directory? In Active Directory Users and Computers, check on the "Profile" tab of user properties for the field labeled "Home folder, Connect to:". Is that where the home folder is specified? If so, the change must be made in Active Directory, and this can be scripted.


    Richard Mueller - MVP Directory Services

    Friday, June 1, 2012 1:13 AM
  • As there has been no activity in this thread for a few days, we assume the issue is resolved. We will mark it as "answered" to assist others in similar situations. If you disagree, please reply with further information. You can unmark the answer if you wish. If a reply helped answer your question, please mark it as the answer.


    Richard Mueller - MVP Directory Services

    Saturday, June 9, 2012 7:57 PM