![]() ![]() |
Jan 12 2005, 12:38 AM Post
#1 | |
| MSFN Contributor ![]() ![]() ![]() Group: Members Posts: 481 Joined: 28-July 04 From: Perth, Western Australia Member No.: 25674 |
Hi All, I have been doing some stuff with unattended backup and installs using scripted installs and ghost. A user logs on to the system, their user account is created on partition 2 (system is on partition 1) so it is easy to restore or upgrade a system without having to do much with the user data. This all works correctly, however the problem i have is after i restore partition 1 using ghost, and the same user logs on again, they have a new account created using the preferences in the default user profile because the system does know anything about their profile even know it is still on partition 2 - so the user profile folder is duplicated with the machine name appended. see below before restore d:\documents and settings\user1 after restore d:\documents and settings\user1 d:\documents and settings\user1.machine_name Does anyone know how to overcome this issue? Any and all help appreciated |
| | |
Jan 12 2005, 12:58 AM Post
#2 | |
| MSFN Junkie ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 3288 Joined: 19-May 04 Member No.: 20315 |
put the files in $OEM$\$Docs into an SFX file & have it extract @ T-12 the problem occurs when windows sees the directory is already made |
| | |
Jan 12 2005, 01:01 AM Post
#3 | |
| MSFN Contributor ![]() ![]() ![]() Group: Members Posts: 481 Joined: 28-July 04 From: Perth, Western Australia Member No.: 25674 | QUOTE (MCT @ Jan 12 2005, 02:58 PM) put the files in $OEM$\$Docs into an SFX file & have it extract @ T-12 the problem occurs when windows sees the directory is already made Thats a good idea, however it will old work if i was doing a scripted install - i am having the problem after a restore of partition 2. That is to say i have already installed the system to partition 1 via unattended method and then taken a ghost image of partition 1. now when i restore partition 1 from the backup image i have the problem stated above. |
| | |
Jan 12 2005, 09:28 AM Post
#4 | |
| MSFN Contributor ![]() ![]() ![]() Group: Members Posts: 481 Joined: 28-July 04 From: Perth, Western Australia Member No.: 25674 |
Has no one seen this problem?
|
| | |
Jan 12 2005, 11:55 AM Post
#5 | |
| Junior ![]() Group: Members Posts: 63 Joined: 12-November 03 From: MD, USA Member No.: 9369 OS: Windows 7 x64 |
Are you running sysprep before you make your ghost image or are you just imaging the drive?
|
| | |
Jan 12 2005, 07:13 PM Post
#6 | |
| MSFN Contributor ![]() ![]() ![]() Group: Members Posts: 481 Joined: 28-July 04 From: Perth, Western Australia Member No.: 25674 | QUOTE (TrAvELAr @ Jan 13 2005, 01:55 AM) Are you running sysprep before you make your ghost image or are you just imaging the drive? Yep sure am and the mini setup is running after the restore to fix duplicate SID's |
| | |
Jan 13 2005, 07:29 AM Post
#7 | |
| Junior ![]() Group: Members Posts: 63 Joined: 12-November 03 From: MD, USA Member No.: 9369 OS: Windows 7 x64 |
When you sysprep it, did you tell it to generate a new sid (only required if the restore is going to another machine)? If you are generating a new sid, that would cause this problem. -nosidgen - Runs the Sysprep.exe file without generating new SIDs. You must use this parameter if you are not duplicating the computer where you are running the Sysprep.exe file or if you are preinstalling domain controllers. |
| | |
Jan 13 2005, 07:29 PM Post
#8 | |
| MSFN Contributor ![]() ![]() ![]() Group: Members Posts: 481 Joined: 28-July 04 From: Perth, Western Australia Member No.: 25674 | QUOTE (TrAvELAr @ Jan 13 2005, 09:29 PM) When you sysprep it, did you tell it to generate a new sid (only required if the restore is going to another machine)? If you are generating a new sid, that would cause this problem. -nosidgen - Runs the Sysprep.exe file without generating new SIDs. You must use this parameter if you are not duplicating the computer where you are running the Sysprep.exe file or if you are preinstalling domain controllers. Good point and yes i have tried both. The problem arrises because the restore is from a default clean image and so it doesn't know about the users that have logged on since the build... therefore when the machine is restored the accounts as far as the USER Accounts are missing... so basically i need to be able to backup the sam and security configurations and then restore those... something you may be interested in is this information - this basically is what is happening. HOW TO: Restore a User Profile |
| | |
Jan 14 2005, 07:09 AM Post
#9 | |
| Junior ![]() Group: Members Posts: 63 Joined: 12-November 03 From: MD, USA Member No.: 9369 OS: Windows 7 x64 |
Ahhh... I see now. I was assuming that the user base was already populated. |
| | |
Jan 17 2005, 01:09 AM Post
#10 | |
| MSFN Contributor ![]() ![]() ![]() Group: Members Posts: 481 Joined: 28-July 04 From: Perth, Western Australia Member No.: 25674 | QUOTE (TrAvELAr @ Jan 14 2005, 09:09 PM) Ahhh... I see now. I was assuming that the user base was already populated. Hi TrAvELAr, Thankyou for taking the time to investigate and help me out - i would be interested in reading what you find out.... In the meantime i have managed to write a batch file to check this and correct the issue automatically - I am in the process now of looking to programing it into a single com or exe file as there are some other utils like getsid and reg that are currently used with the batch file that i believe i can do away with in a single application file. I will post the results when i have finished |
| | |
Jan 19 2005, 06:20 AM Post
#11 | |
| Junior ![]() Group: Members Posts: 63 Joined: 12-November 03 From: MD, USA Member No.: 9369 OS: Windows 7 x64 |
Hey 'Felix', Sorry for the delayed response, but things got a bit hectic around here. I was able to reproduce this, but I have not had sufficient time to come up with a working solution. It sounds like you have something in the works tho, albeit somewhat painful. I'm interested in seeing what you've come up with. |
| | |
Jan 28 2005, 01:49 AM Post
#12 | |
| MSFN Contributor ![]() ![]() ![]() Group: Members Posts: 481 Joined: 28-July 04 From: Perth, Western Australia Member No.: 25674 |
Hi TrAvELAr - sorry bout the delayed response..... Ok here is my present solution (fully tested and working) [Tested on Windows 2000, Windows XP and Windows 2003 - Windows NT users a little bit different naming process] UserProfileChecker.cmd CODE @echo off cls ::If other than WinNT (2000/XP/2003) Environment - bailout. IF %OS%!==! GOTO _NotNT setlocal GOTO _CHECKS :_CHECKS ::Get current user SID. FOR /F "tokens=7" %%A IN ('getsid \\%computername% %username% \\%computername% %username%') DO SET USERSID=%%A ::Get current user Profile Path. FOR /F "tokens=2* delims=\" %%A IN ('reg query "hklm\software\microsoft\windows nt\currentversion\profilelist\%USERSID%" /v ProfileImagePath') DO SET PIP=%%B ::If the current username and the current user profile path match - bailout! IF "%USERNAME%"=="%PIP%" goto _eof ::Set Directory to be removed next logon... FOR /F "tokens=2*" %%A IN ('reg query "hklm\software\microsoft\windows nt\currentversion\profilelist\%USERSID%" /v ProfileImagePath') DO SET ToRemove="%%B" ::Get the system profiles path - normally %systemdrive%\documents and settings\ ::Or D:\documents and settings\ FOR /F "tokens=2*" %%A IN ('reg query "hklm\software\microsoft\windows nt\currentversion\profilelist" /v ProfilesDirectory') DO set USERDIR=%%B ::Check the system profiles path for a directory name that matches the username echo %USERDIR% | DIR /AH /B "%USERDIR%\%username%\NTUSER.DAT" | find /c /i "NTUSER.DAT" >NUL ::If no match - bailout! if errorlevel 1 goto _eof IF NOT "%USERNAME%"=="%PIP%" GOTO _ModifyUserImagePath :_ModifyUserImagePath call :_splash ::Let the user know something is happening... popup /YN /HF "userprofilechecker.hlp" /IE /M "Duplicate User Profile Detected" /T "User Profile Checker 1.0" if errorlevel 7 goto _eof ::if use says yes - then update the users SID Profile Image path to original value... reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%USERSID%" /v ProfileImagePath /t REG_EXPAND_SZ /d "%userdir%\%username%" /f >NUL reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DocFolderPaths" /v %USERNAME% /d "%userdir%\%username%\My Documents" /f >NUL reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v RemoveDuplicateProfile /d "%comspec% /C RMDIR /S /Q ""%ToRemove%""" /f >NUL rem shutdown -l -f goto _eof :_NotNT cls echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ echo This program is designed for Windows NT, Windows 2000, Windows XP, Windows 2003 echo and above. echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ echo. goto _eof :_ERROR cls echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ echo You have cancelled this update, as a result your profile will not be updated. echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ echo. goto _eof :_Splash echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ echo User Profile Checker v1.0 echo Copyright 2004-2005 Darren Blackley, Simplify I.T. All rights reserved. echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ :_EOF Required 3rd party utilities for the batch to work. REG.EXE - Windows Resource Kit GETSID.EXE - Windows Resource Kit SHUTDOWN.EXE - Windows Resource Kit POPUP.EXE - Just a windows message popup for notifying the user. (Attached) UserProfileChecker.hlp CODE ********** A DUPLICATE OF YOUR USER PROFILE HAS BEEN DETECTED. ********** This situation can happen when your computer has been restored from a disaster/ System crash, an operating system upgrade, a service patch/hotfix or your user Account has been erroneously deleted from the computer. Your original user profile including your files should all be available under your original profile directory. Presently you are operating on a default (new) profile that Windows as created for you because it has found a duplicate directory. To restore your original profile and regain access to all of your original user configuration including My Documents etc. - Click on YES. Note: Once you click yes, your profile will be automatically corrected and you will be automatically logged off. Simply Login again to gain access to your original profile. If you do not wish to restore profile or require more information click NO and contact your local IT support staff member. For more specific information visit this reference on the Microsoft website: http://support.microsoft.com/default.aspx?scid=kb;en-us;314045 Next step is to build it all into a single exe or com so that no third party utils are required, however i am going to have to go away and learn some delphi or something to do that... any programmers like to give it a try? Attached File(s) |
| | |
Mar 3 2005, 01:51 AM Post
#13 | |
| MSFN Contributor ![]() ![]() ![]() Group: Members Posts: 481 Joined: 28-July 04 From: Perth, Western Australia Member No.: 25674 |
Hi there all, Finally after some weeks and many, many hours of work i have completed the next version of User Profile Checker. Version 2.6 YAHOO! It is now a compiled file and has lots of smarts built in. USE: Ok now to use it you simply add it to the runonce key of your user profile - i suggest adding it to your default user ntuser.dat hive (if you want to know how to do this Click here). If you add it to your default user runonce then add the command option RESTART. eg. UPC.EXE RESTART. What this will do is if any changes are made, UPC will then restart your computer after notifying the user. This is required to completely allow the change to be implemented and to remove the duplicate directories. If you add UPC.EXE to your RunOnceEx during installation and you have a reboot at the end of your installation there is no need to use the RESTART option. Each time you run UPC.EXE a log file called "AllUsersProfilefix.log" will be generated in c:\. INSTALLATION: -Installing to existing installation. Simply extract the contents of the archive attached to your %systemdrive%\windows\system32 directory then it will be in the path and available from anywhere. -Installing to AIO Installation CD or Network Share. Simply extract the contents of the archive attached to your [path to AIO install point]\$oem$\$$\System32 directory then it will be in the path after your new installation of windows and available from anywhere. Caveats: - User must have Administrator access. I have not done any testing with Power Users accounts, however i expect it would work if you have allowed Power Users to make changes to the registry. - Currently UPC will address the following profiles the first time you use it: all users.windows, default user.windows, localservice.nt authority and networkservice.nt authority - the last 3 are normally hidden. It will also address the current user logged on by using the %username% environment variable. Other user accounts will not be effected until the actual user logs on. TODO LIST: - Address ALL system users (not All User profile) in a single pass, thus allowing an administrator to logon and run UPC once to correct the profiles and remove the duplicate directories. - Add addition command line options: shutdown timeout, logfile name and location & some help syntax. - Fully document functions and features. - Maybe redevelop using VB or something else that would allow for the functions performed by getsid, popup and reg to be done internally. --------------- Well that is about it for now, however we am open to suggestions and comments. PLEASE TEST first before adding this to production systems. We (esas and I) have spent many weeks testing in VMware and actual machines, however we may have missed something. Well i hope this address' your needs and is helpful - enjoy! Ok esas has been continuing to refine my orginal code and has now compiled the code and related files into a single exe file that works very well. you can now download the current version here UPC | Mirror #1 Special Thanks to esas for his continuing work! This post has been edited by `Felix`: Dec 6 2005, 08:57 PM Attached File(s) |
| | |
Mar 3 2005, 07:07 AM Post
#14 | |
| Newbie Group: Members Posts: 20 Joined: 7-February 05 Member No.: 43360 |
Great work Felix! I'll test this during the next week.. You'll hear from me then.. |
| | |
Mar 9 2005, 06:34 PM Post
#15 | |
| Newbie Group: Members Posts: 20 Joined: 7-February 05 Member No.: 43360 |
Hey Felix! I've been testing UPC for some days now, and I have a few things to report.. 1. When a duplicated userfolder is detected and deleted the originally folder doesn't appear in "My Computer" ![]() 2. The Popup only says "Duplicated profile dected", with the buttons "Yes"and "No". This isn't even a question. I really liked your previously version with the help button, and the possibility to write my own popup. (I would also like to translate this to my norwegian XP by time) 3. The popup is being displayed no mather what. Even if there isn't a duplicated account. It also creates the logfile, even though it doesn't delete anything. 4. I can't get the RESTART option to work. I have to restart manually. Is it necessary to restart? Is is not enough to logof the user like in the first version? Just asking. 5. A SILENT option would be great. That way I won't have to answar yes during RunOnceEX. This wasn't a issue in the first version as I could edit the cmd-file myself. Can't do that now. That's all..... I also want to thank you for the work you have done so far. You are great!! |
| | |
Mar 10 2005, 02:43 AM Post
#16 | |
| MSFN Contributor ![]() ![]() ![]() Group: Members Posts: 481 Joined: 28-July 04 From: Perth, Western Australia Member No.: 25674 | QUOTE (esas @ Mar 10 2005, 08:34 AM) Hey Felix! I've been testing UPC for some days now, and I have a few things to report.. 1. When a duplicated userfolder is detected and deleted the originally folder doesn't appear in "My Computer" ![]() Ok so in the log is it reporting that it is deleting your original account too? need more information here... i need to try and duplicate the problem so i can fix it QUOTE 2. The Popup only says "Duplicated profile dected", with the buttons "Yes"and "No". This isn't even a question. I really liked your previously version with the help button, and the possibility to write my own popup. (I would also like to translate this to my norwegian XP by time) Yes you do for all the profiles to be fully released from system control.3. The popup is being displayed no mather what. Even if there isn't a duplicated account. It also creates the logfile, even though it doesn't delete anything. 4. I can't get the RESTART option to work. I have to restart manually. Is it necessary to restart? Is is not enough to logof the user like in the first version? Just asking. QUOTE 5. A SILENT option would be great. That way I won't have to answar yes during RunOnceEX. This wasn't a issue in the first version as I could edit the cmd-file myself. Can't do that now. That's all..... I also want to thank you for the work you have done so far. You are great!! Ok well the easiest thing i can do is just give you the source. here it is below CODE @ECHO OFF :: Fix and Delete Duplicate Profiles 1.1.17 :: Copyright 2005, `felix` :: Last updated: March 3, 2005 IF %OS%!==! GOTO:EOF setlocal If /I "%1"=="RESTART" SET RS=YES set theNum=0 set KEY=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList set gtid=getsid \\%computername% %username% \\%computername% %username% for /f "Tokens=7" %%i in ('%gtid%^') do (set UserSID=%%i) set qry1=reg query "%KEY%" /v ProfilesDirectory set qry2=reg query "%KEY%" /s set qry3=reg query "%KEY%\%USERSID%" /v ProfileImagePath set fnd1=FIND /I "Documents and Settings" set fnd2=FIND /I "ProfileImagePath" set fnd3=FIND /I "AllUsersProfile" set fnd4=FIND /I "DefaultUserProfile" set fnd5=FIND /I "LocalService" set fnd6=FIND /I "NetworkService" set fnd7=FIND /I "%UserName%" for /f "Tokens=1,2*" %%i in ('%qry1%^|%fnd1%') do (set DocSetDir0=%%k) CALL:CheckCurrentLocal CALL:CheckIfDuplicate if %RS%==YES call:restartIt GOTO:EOF :CheckCurrentLocal :: Check the registry to and make sure the profiles are correct based :: a totally clean default installation. If duplicate profiles are :: found based on reinstall or lost of user account information, we :: correct the paths to the correct directories here. FOR /f "Tokens=1,2*" %%i in ('%qry2%^|%fnd3%') do if /i not "%%k"=="All Users" ( reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /v AllUsersProfile /d "All Users" /f >NUL ) FOR /f "Tokens=1,2*" %%i in ('%qry2%^|%fnd4%') do if /i not "%%k"=="Default User" ( reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /v DefaultUserProfile /d "Default User" /f >NUL ) FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry2%^|%fnd5%') do if /i not "%%k"=="LocalService" ( reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-19" /v ProfileImagePath /d "%DocSetDir0%\LocalService" /f >NUL ) FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry2%^|%fnd6%') do if /i not "%%k"=="NetworkService" ( reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-20" /v ProfileImagePath /d "%DocSetDir0%\NetworkService" /f >NUL ) FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry2%^|%fnd7%') do if /i not "%%k"=="%UserName%" ( reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%UserSID%" /v ProfileImagePath /d "%DocSetDir0%\%UserName%" /f >NUL ) GOTO:EOF :CheckIfDuplicate ::Let the user know something is happening... popup /YN /HF "userprofilechecker.hlp" /IS /M "Duplicate User Profile Detected" /T "User Profile Checker 1.1.16" if errorlevel 7 EXIT :: Now we actually check againist the registry for duplicates :: Normally they will be username.computername, all users.windows, :: default user.windows, localservice.nt authority and networkservice.nt authority. :: the last 3 are hidden. CALL:Header FOR /f "Tokens=1,2*" %%i in ('%qry2%^|%fnd3%') do if /i "%%k"=="All Users" (CALL:DoIt "All Users" "%DocSetDir0%") FOR /f "Tokens=1,2*" %%i in ('%qry2%^|%fnd4%') do if /i "%%k"=="Default User" (CALL:DoIt "Default User" "%DocSetDir0%") FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry2%^|%fnd5%') do if /i "%%k"=="LocalService" (CALL:DoIt "LocalService" "%DocSetDir0%") FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry2%^|%fnd6%') do if /i "%%k"=="NetworkService" (CALL:DoIt "NetworkService" "%DocSetDir0%") FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry3%^|%fnd7%') do if /i "%%k"=="%UserName%" (CALL:DoIt "%UserName%" "%DocSetDir0%") CALL:Footer GOTO:EOF :Header :: We output the list of directories to the log so we have a record :: of the directories deleted and to check the script loaded. > c:\AllUsersProfilefix.log echo Fix and Remove Duplicate Profiles 1.1.17 >> c:\AllUsersProfilefix.log echo Copyright 2005, `felix` >> c:\AllUsersProfilefix.log echo www.simplify-i-t.com >> c:\AllUsersProfilefix.log echo Automatically Generated %DATE:~-10%. >> c:\AllUsersProfilefix.log echo -------------------------------------------------------------------------------- >> c:\AllUsersProfilefix.log echo. >> c:\AllUsersProfilefix.log echo This computer was found to have one or more duplicate system or user profiles. >> c:\AllUsersProfilefix.log echo. >> c:\AllUsersProfilefix.log echo The following registry key has been updated with restored values. >> c:\AllUsersProfilefix.log echo "%KEY%" >> c:\AllUsersProfilefix.log echo. GOTO:EOF :Footer >> c:\AllUsersProfilefix.log echo. >> c:\AllUsersProfilefix.log echo -------------------------------------------------------------------------------- >> c:\AllUsersProfilefix.log echo This issue is possibly caused by the following reasons: >> c:\AllUsersProfilefix.log echo * The computer operating system has been reinstalled. >> c:\AllUsersProfilefix.log echo * The computer operating system has been restore from a back-up image. >> c:\AllUsersProfilefix.log echo. >> c:\AllUsersProfilefix.log echo For more information please see Microsoft Knowledge Base Article link below: >> c:\AllUsersProfilefix.log echo http://support.microsoft.com/default.aspx?...kb;en-us;314045 >> c:\AllUsersProfilefix.log echo. GOTO:EOF :Doit :: We check to make sure it is not a valid user directory and :: unhide all the directories that are hidden first so we can :: build the list to remove them. for /f "usebackq delims= tokens=1,2" %%i IN (`dir /a /b "%~2\%~1*"`) DO IF /i "%%i" NEQ "%~1" attrib -a -s -h "%~2\%%i" for /f "usebackq delims= tokens=1,2" %%i IN (`dir /ad /b "%~2\%~1*"`) DO IF /i "%%i" NEQ "%~1" call:flagIt %~2\%%i GOTO:EOF :flagIt :: The list of duplicate/unrequired directories is built :: and added to the Local Machine RunOnce key to be removed :: at next boot. :: The directories can not be removed before a reboot because the :: system still has them loaded even know we have changed the paths :: in the registry. set /a theNum=%theNum%+1 reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v RemoveDuplicateProfile%theNum% /d "%comspec% /C RMDIR /S /Q """%*"""" /f >NUL >> c:\AllUsersProfilefix.log echo %theNum%. %* has been deleted! GOTO:EOF :restartIt shutdown -r -f -t 90 -c "%computername%" needs to restart to finish the update to the user profiles." GOTO:EOF endlocal |
| | |
Mar 10 2005, 08:47 AM Post
#17 | |
| Newbie Group: Members Posts: 20 Joined: 7-February 05 Member No.: 43360 |
Hi! I've been looking at the source and made some changes. QUOTE @ECHO OFF :: Fix and Delete Duplicate Profiles 1.1.17 :: Copyright 2005, `felix` :: SILENT option added by esas :: Last updated: March 10, 2005 IF %OS%!==! GOTO:EOF setlocal ::Check for options (RESTART or SILENT) If /I "%1"=="RESTART" SET RS=YES If /I NOT "%1"=="RESTART" SET RS=NO if %RS%==NO goto CheckmoreRS if %RS%==YES goto SkipCheckmoreRS :CheckmoreRS If /I "%2"=="RESTART" SET RS=YES If /I NOT "%2"=="RESTART" SET RS=NO :SkipCheckmoreRS If /I "%1"=="SILENT" SET SL=YES If /I NOT "%1"=="SILENT" SET SL=NO if %SL%==NO goto CheckmoreSL if %SL%==YES goto SkipCheckmoreSL :CheckmoreSL If /I "%2"=="SILENT" SET SL=YES If /I NOT "%2"=="SILENT" SET SL=NO :SkipCheckmoreSL set theNum=0 set KEY=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList set gtid=getsid \\%computername% %username% \\%computername% %username% for /f "Tokens=7" %%i in ('%gtid%^') do (set UserSID=%%i) set qry1=reg query "%KEY%" /v ProfilesDirectory set qry2=reg query "%KEY%" /s set qry3=reg query "%KEY%\%USERSID%" /v ProfileImagePath set fnd1=FIND /I "Documents and Settings" set fnd2=FIND /I "ProfileImagePath" set fnd3=FIND /I "AllUsersProfile" set fnd4=FIND /I "DefaultUserProfile" set fnd5=FIND /I "LocalService" set fnd6=FIND /I "NetworkService" set fnd7=FIND /I "%UserName%" for /f "Tokens=1,2*" %%i in ('%qry1%^|%fnd1%') do (set DocSetDir0=%%k) CALL:CheckCurrentLocal CALL:CheckIfDuplicate if %RS%==YES call:restartIt GOTO:EOF :CheckCurrentLocal :: Check the registry to and make sure the profiles are correct based :: a totally clean default installation. If duplicate profiles are :: found based on reinstall or lost of user account information, we :: correct the paths to the correct directories here. FOR /f "Tokens=1,2*" %%i in ('%qry2%^|%fnd3%') do if /i not "%%k"=="All Users" ( reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /v AllUsersProfile /d "All Users" /f >NUL ) FOR /f "Tokens=1,2*" %%i in ('%qry2%^|%fnd4%') do if /i not "%%k"=="Default User" ( reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /v DefaultUserProfile /d "Default User" /f >NUL ) FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry2%^|%fnd5%') do if /i not "%%k"=="LocalService" ( reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-19" /v ProfileImagePath /d "%DocSetDir0%\LocalService" /f >NUL ) FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry2%^|%fnd6%') do if /i not "%%k"=="NetworkService" ( reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-20" /v ProfileImagePath /d "%DocSetDir0%\NetworkService" /f >NUL ) FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry2%^|%fnd7%') do if /i not "%%k"=="%UserName%" ( reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%UserSID%" /v ProfileImagePath /d "%DocSetDir0%\%UserName%" /f >NUL ) GOTO:EOF :CheckIfDuplicate ::Let the user know something is happening unless SILENT option in used... if %SL%==YES goto Skippopup popup /YN /HF "userprofilechecker.hlp" /IS /M "Duplicate User Profile Detected" /T "User Profile Checker 1.1.16" if errorlevel 7 EXIT :Skippopup :: Now we actually check againist the registry for duplicates :: Normally they will be username.computername, all users.windows, :: default user.windows, localservice.nt authority and networkservice.nt authority. :: the last 3 are hidden. CALL:Header FOR /f "Tokens=1,2*" %%i in ('%qry2%^|%fnd3%') do if /i "%%k"=="All Users" (CALL:DoIt "All Users" "%DocSetDir0%") FOR /f "Tokens=1,2*" %%i in ('%qry2%^|%fnd4%') do if /i "%%k"=="Default User" (CALL:DoIt "Default User" "%DocSetDir0%") FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry2%^|%fnd5%') do if /i "%%k"=="LocalService" (CALL:DoIt "LocalService" "%DocSetDir0%") FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry2%^|%fnd6%') do if /i "%%k"=="NetworkService" (CALL:DoIt "NetworkService" "%DocSetDir0%") FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry3%^|%fnd7%') do if /i "%%k"=="%UserName%" (CALL:DoIt "%UserName%" "%DocSetDir0%") CALL:Footer GOTO:EOF :Header :: We output the list of directories to the log so we have a record :: of the directories deleted and to check the script loaded. > c:\AllUsersProfilefix.log echo Fix and Remove Duplicate Profiles 1.1.17 >> c:\AllUsersProfilefix.log echo Copyright 2005, `felix` >> c:\AllUsersProfilefix.log echo www.simplify-i-t.com >> c:\AllUsersProfilefix.log echo Automatically Generated %DATE:~-10%. >> c:\AllUsersProfilefix.log echo -------------------------------------------------------------------------------- >> c:\AllUsersProfilefix.log echo. >> c:\AllUsersProfilefix.log echo This computer was found to have one or more duplicate system or user profiles. >> c:\AllUsersProfilefix.log echo. >> c:\AllUsersProfilefix.log echo The following registry key has been updated with restored values. >> c:\AllUsersProfilefix.log echo "%KEY%" >> c:\AllUsersProfilefix.log echo. GOTO:EOF :Footer >> c:\AllUsersProfilefix.log echo. >> c:\AllUsersProfilefix.log echo -------------------------------------------------------------------------------- >> c:\AllUsersProfilefix.log echo This issue is possibly caused by the following reasons: >> c:\AllUsersProfilefix.log echo * The computer operating system has been reinstalled. >> c:\AllUsersProfilefix.log echo * The computer operating system has been restore from a back-up image. >> c:\AllUsersProfilefix.log echo. >> c:\AllUsersProfilefix.log echo For more information please see Microsoft Knowledge Base Article link below: >> c:\AllUsersProfilefix.log echo http://support.microsoft.com/default.aspx?...kb;en-us;314045 >> c:\AllUsersProfilefix.log echo. GOTO:EOF :Doit :: We check to make sure it is not a valid user directory and :: unhide all the directories that are hidden first so we can :: build the list to remove them. for /f "usebackq delims= tokens=1,2" %%i IN (`dir /a /b "%~2\%~1*"`) DO IF /i "%%i" NEQ "%~1" attrib -a -s -h "%~2\%%i" for /f "usebackq delims= tokens=1,2" %%i IN (`dir /ad /b "%~2\%~1*"`) DO IF /i "%%i" NEQ "%~1" call:flagIt %~2\%%i GOTO:EOF :flagIt :: The list of duplicate/unrequired directories is built :: and added to the Local Machine RunOnce key to be removed :: at next boot. :: The directories can not be removed before a reboot because the :: system still has them loaded even know we have changed the paths :: in the registry. set /a theNum=%theNum%+1 reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v RemoveDuplicateProfile%theNum% /d "%comspec% /C RMDIR /S /Q """%*"""" /f >NUL >> c:\AllUsersProfilefix.log echo %theNum%. %* has been deleted! GOTO:EOF :restartIt shutdown -r -f -t 90 -c "%computername% needs to restart to finish the update to the user profiles." GOTO:EOF endlocal As you can see I've added a SILENT option. It can be used with or without the RESTART option, and it doesn't mather in whitch order you put the options. The reson the RESTART option didn't work before was a error in the shutdown line. I removed the " after the %computername% and it worked. You might want to put the UserprofileChecker.hlp in the UPC.rar. I wasn't using it untill I saw I had to in the source. Figured it build in with the UPC.exe or something. It still creates the logfile and launches the popup (If the SILENT option isn't used) even though there isn't duplicated user account. A little irritating. QUOTE Ok so in the log is it reporting that it is deleting your original account too? need more information here... i need to try and duplicate the problem so i can fix it No the log only report that it has deleted the new account. Except for this the original account seems find. |
| | |
Apr 10 2005, 03:25 PM Post
#18 | |
| Newbie Group: Members Posts: 36 Joined: 12-September 04 Member No.: 30824 |
Is there an updated package available for download somewhere?
|
| | |
Sep 27 2005, 01:11 PM Post
#19 | |
| Friend of MSFN ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 879 Joined: 28-June 04 From: Eerbeek Member No.: 23554 OS: XP Pro x86 |
This method is new to me but it sounds cool. I would like to see an option to do all this stuff before a user actually logons. AFAIK all changes upto T13 are copied to the Default User Account. However this account is created directly after the commands from cmdlines.txt have passed (T12) More interesting is that this account is not in use during install but the generic System Account is used. The Administrator account is created at first logon after the reboot. Is it possible to run this script at T9 [SetupParams] to move the newly created Default User.001 Account to Default User, overwriting existing files and change the appropiate registry entries, since it's not yet in use. This would be cool in use when you have specific software settings not stored in the registry, custom shortcuts etc, documents folder, history, favorites etc. from a previous installation. All you would have to do is a unique username for each system. If anyone has experience with this please reply |
| | |
Oct 2 2005, 11:50 AM Post
#20 | |
| Friend of MSFN ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 879 Joined: 28-June 04 From: Eerbeek Member No.: 23554 OS: XP Pro x86 |
I have worked this out. For me it's not necessary to keep the existing user profiles. So I use this: WinNT.sif CODE [SetupParams] UserExecute="cmd.exe /C adminchange.cmd" cmdlines.txt CODE [COMMANDS] "runonceex.cmd" "rundll32.exe iernonce.dll,RunOnceExProcess" RunOnceEx.cmd CODE @echo off FOR %%a IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO ((( set drv=%%a:) & (call :setupdocs)) ) goto :ending :setupdocs FOR /F "tokens=7 delims=:= " %%a IN ( 'vol %drv%' ) DO ( IF /I %%a==Documenten ( set docsdrive=%drv% ) IF /I %%a==nLite ( set CDDRIVE=%drv% goto :endloop ) ) :endloop GOTO :EOF :ending IF not defined docsdrive set docsdrive=%systemdrive% IF NOT Defined CDDRIVE set CDDRIVE=%CD%^\^.^. cacls "%docsdrive%\Profieldata\" /E /T /P Administrators:F rmdir /S /Q "%docsdrive%\Profieldata" reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Profilelist" /v "ProfilesDirectory" /t REG_EXPAND_SZ /d "%docsdrive%\Profieldata" /f AdminChange.cmd CODE @echo off FOR %%a IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO ((( set drv=%%a:) & (call :setupdocs)) ) goto :ending :setupdocs FOR /F "tokens=7 delims=:= " %%a IN ( 'vol %drv%' ) DO ( IF /I %%a==Documenten ( set docsdrive=%drv% ) IF /I %%a==nLite ( set CDDRIVE=%drv% goto :endloop ) ) :endloop GOTO :EOF :ending IF not defined docsdrive set docsdrive=%systemdrive% IF NOT Defined CDDRIVE set CDDRIVE=%CD%^\^.^. ::get systemsid for /f "skip=1" %%a in ('psgetsid') do set sid=%%a ::set adminsid set adminsid=%sid%-500 for /f "tokens=2* delims=\" %%a in ('reg query "hklm\software\microsoft\windows nt\currentversion\profilelist\%adminsid%" /v "ProfileImagePath"') do set pid=%%b reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Profilelist" /v "ProfilesDirectory" /t REG_EXPAND_SZ /d "%docsdrive%\Profieldata" /f reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Profilelist\%adminsid%" /v "ProfileImagePath" /t REG_EXPAND_SZ /d "%docsdrive%\Profieldata\Administrator" /f XCOPY /C /H /E /O /I /Y "%systemdrive%\Documents and Settings" "%docsdrive%\Profieldata" reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v "CleanProfile" /d "cmd.exe /C \"RMDIR /S /Q \"%systemdrive%\Documents and Settings\"\"" /f EXIT You need psgetsid btw. This post has been edited by hp38guser: Oct 2 2005, 11:51 AM |
| | |
![]() ![]() |
| Lo-Fi Version | Time is now: 22nd November 2009 - 06:13 AM |