-2

I'm using "D:\users" profilePath for my Domain users. When I change my "systemdrive" with new windows image, Domain users creates new profile like "D:\Users\old.DNS".

I want to use old profilepath but I couldn't find any method to tell windows "use existing profile". Because of that I need to change profile path from regedit!

I tried to write something but I don't know how can I modify the registry only changes "dnsname".

Because username is different for every machine and also DNSname can be different for different companies.

I'm taking user sid with

set sid=wmic useraccount where name='%username%' get sid

%sid%

Then I need to take username and remove .DNS from it, but I don't know how can I do that. Can i write someting like "delete after "." "point" in batch?

Morphinz
  • 221
  • 1
  • 2
  • 13
  • Have you looked at this post? http://stackoverflow.com/questions/130193/is-it-possible-to-modify-a-registry-entry-via-a-bat-cmd-script – Rob Mar 31 '17 at 13:23
  • My biggest problem is taking username and remove .DNS from it. for example username is username.DNS i want to remove .DNS from it. Than i change the valuse of ProfileImagePath . – Morphinz Mar 31 '17 at 13:31
  • 1
    Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](https://meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Mar 31 '17 at 13:38
  • 1
    You can add a reg key as binary if that helps, see `reg add /?` – Bali C Mar 31 '17 at 13:51

1 Answers1

0

I found my self and this script needs admin privileges.

::get usersid first
for /F "tokens=2" %%i in ('whoami /user /fo table /nh') do set usersid=%%i

::get userpath
for /F "tokens=3" %%i in ('reg QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%usersid%" /v "ProfileImagePath"') do set oldpath=%%i

::delete after "."
for /f "tokens=1 delims=." %%a in ('echo %oldpath%') do set newpath=%%a

::update the reg with new path
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%usersid%" /v "ProfileImagePath" /t REG_EXPAND_SZ /d "%newpath%" /f

echo EVERYTHING OKAY MATE!
pause
Morphinz
  • 221
  • 1
  • 2
  • 13