Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Help Pls - Remove Directory's Bat/cmd

- - - - -

  • Please log in to reply
15 replies to this topic

#1
`Felix`

`Felix`

    MSFN Contributor

  • Member
  • PipPipPip
  • 481 posts
  • Joined 28-July 04
Hi guy's

Now i know that this area is mainly for programming and i will starting to do some vb, however i need a quick batch/cmd to do the following.

I have a list of directories that may vary in name a little... basically they are duplicate

eg.

c:\documents and settings\default user
c:\documents and settings\default user.windows
c:\documents and settings\default user.windows.000
c:\documents and settings\default user.windows.001
c:\documents and settings\default user~windows
c:\documents and settings\all users
c:\documents and settings\all users.windows
c:\documents and settings\all users.windows.000
c:\documents and settings\all users.windows.001

Now i want to able to search the c:\documents and settings directory and if any of these directories other than the base like "default user" is there that i use the rd command and remove them. so in the example above i would be removing:
c:\documents and settings\default user.windows
c:\documents and settings\default user.windows.000
c:\documents and settings\default user.windows.001
c:\documents and settings\default user~windows
not
c:\documents and settings\default user

does that make sense? I would appreciate any help or advise.... thanks in advance. :hello:
"I seek not to know all the answers, but to understand the questions."
- Kwai Chang Caine.


Want to setup your default user/all users unattended install easy? - Simplify iT - GuidesCheers,
FeLiX


How to remove advertisement from MSFN

#2
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,474 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
What if you just run

RMDIR "c:\documents and settings\default user?w*" /S /Q
RMDIR "c:\documents and settings\all users?w*" /S /Q


Type RD /? or RMDIR /? at the command prompt for the meaning of the switches.

To test if you get the right directories, type:

DIR "c:\documents and settings\default user?w*"
and
DIR "c:\documents and settings\all users?w*"


BEFORE trying to use the RMDIR command!

jaclaz

P.S.: you need the quotes around the path as it contains spaces

#3
dman

dman

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 717 posts
  • Joined 01-February 05
Make sure you know which ones you are deleting first! You usually get a structure like this by installing windows several times without deleting the old dirs.
"\default user.windows.001" may very well be your active default user directory, not "\default user"

#4
`Felix`

`Felix`

    MSFN Contributor

  • Member
  • PipPipPip
  • 481 posts
  • Joined 28-July 04

Make sure you know which ones you are deleting first! You usually get a structure like this by installing windows several times without deleting the old dirs.
"\default user.windows.001" may very well be your active default user directory, not "\default user"

<{POST_SNAPBACK}>


Thanks for the advise - yes i know this, but it is worth mentioning... I have checked and am deleting those not in use.

Thanks again
"I seek not to know all the answers, but to understand the questions."
- Kwai Chang Caine.


Want to setup your default user/all users unattended install easy? - Simplify iT - GuidesCheers,
FeLiX

#5
`Felix`

`Felix`

    MSFN Contributor

  • Member
  • PipPipPip
  • 481 posts
  • Joined 28-July 04

What if you just run

RMDIR "c:\documents and settings\default user?w*" /S /Q
RMDIR "c:\documents and settings\all users?w*" /S /Q


Type RD /? or RMDIR /? at the command prompt for the meaning of the switches.

To test if you get the right directories, type:

DIR "c:\documents and settings\default user?w*"
and
DIR "c:\documents and settings\all users?w*"


BEFORE trying to use the RMDIR command!

jaclaz

P.S.: you need the quotes around the path as it contains spaces

<{POST_SNAPBACK}>


hi jaclaz,

Thanks for the information - you got me on the right track...
DIR "c:\documents and settings\all users?w*" doesn't work, however DIR "c:\documents and settings\all users.w*" does - so that i can live with, however i can't use RD with this... i get the following error "The filename, directory name, or volume label syntax is incorrect."

Any other suggestions on how i might do this?
"I seek not to know all the answers, but to understand the questions."
- Kwai Chang Caine.


Want to setup your default user/all users unattended install easy? - Simplify iT - GuidesCheers,
FeLiX

#6
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,474 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
I am sorry, it looks like I went to fast,
RMDIR does not support wildcards, see here:
http://www.ss64.com/nt/rd.html

So you need to write a batch file after all.

I'll try and make one and post it here a.s.a.p.

jaclaz

#7
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,474 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
Ok, I found this example on the wonderful Rob Vanderwoude's site:
http://www.robvander...eadprofiles.txt

@ECHO OFF
:: DelDeadProfiles, Version 1.00 for Windows NT
:: Removes unused leftovers of corrupted profiles for the current user ID.
:: If the current user profile is C:\WINNT\Profiles\userid.000 then both
:: C:\WINNT\Profiles\userid and C:\WINNT\Profiles\userid.002 will be
:: removed.
:: Written by Rob van der Woude
:: http://www.robvanderwoude.com

CALL :CheckIfCorrupt %userprofile%
GOTO:EOF

:CheckIfCorrupt
FOR /D %%A IN (%~dpn1.*) DO CALL :DelDeadProfiles %%A %userprofile%
GOTO:EOF

:DelDeadProfiles
if not [%~f1]==[%~f2] echo Deleting corrupted profile %~nx1 . . .
if not [%~f1]==[%~f2] rd /s /q %1
goto:EOF


For the meaning of the variables expansions used see here:
http://www.robvander...com/ntcall.html

Let us adapt it to your need:

@ECHO OFF
:: DELUD.BAT
:: DELete Unneded Directories
:: a script by jaclaz
:: based on script DeadProf.bat
:: Written by Rob van der Woude
:: http://www.robvanderwoude.com

If %1.==. GOTO :usage
If not  %1=="%~1" GOTO :usage2
CALL :CheckIfCorrupt %1
GOTO:EOF

:CheckIfCorrupt
::dir "%~1*"
FOR /D %%A IN ("%~1*") DO CALL :DelDeadProfiles "%%A" %1
GOTO:EOF

:DelDeadProfiles
if not ["%~f1"]==["%~f2"] echo Deleting corrupted profile "%~nx1" . . .


::IF the listing is correct, then remove the :: from the following line
::if not ["%~f1"]==["%~f2"] rd /s /q %1
GOTO:EOF

:usage
ECHO You must supply a base directory name
GOTO:EOF

:usage2
ECHO ERROR!
ECHO.
ECHO Name supplied has spaces in it
ECHO If the path includes a space it MUST have QUOTES "" around
ECHO.
ECHO This is what I understood:
ECHO %1
ECHO.
ECHO This is (probably) what you meant:
ECHO "%1 %2"
GOTO:EOF


(copy the above and paste it in notepad, saving it as delud.bat)
jaclaz

#8
`Felix`

`Felix`

    MSFN Contributor

  • Member
  • PipPipPip
  • 481 posts
  • Joined 28-July 04

Ok, I found this example on the wonderful Rob Vanderwoude's site:
http://www.robvander...eadprofiles.txt

Let us adapt it to your need:

@ECHO OFF
:: DELUD.BAT
:: DELete Unneded Directories
:: a script by jaclaz
:: based on script DeadProf.bat
:: Written by Rob van der Woude
:: http://www.robvanderwoude.com

If %1.==. GOTO :usage
If not  %1=="%~1" GOTO :usage2
CALL :CheckIfCorrupt %1
GOTO:EOF

:CheckIfCorrupt
::dir "%~1*"
FOR /D %%A IN ("%~1*") DO CALL :DelDeadProfiles "%%A" %1
GOTO:EOF

:DelDeadProfiles
if not ["%~f1"]==["%~f2"] echo Deleting corrupted profile "%~nx1" . . .


::IF the listing is correct, then remove the :: from the following line
::if not ["%~f1"]==["%~f2"] rd /s /q %1
GOTO:EOF

:usage
ECHO You must supply a base directory name
GOTO:EOF

:usage2
ECHO ERROR!
ECHO.
ECHO Name supplied has spaces in it
ECHO If the path includes a space it MUST have QUOTES "" around
ECHO.
ECHO This is what I understood:
ECHO %1
ECHO.
ECHO This is (probably) what you meant:
ECHO "%1 %2"
GOTO:EOF


(copy the above and paste it in notepad, saving it as delud.bat)
jaclaz

<{POST_SNAPBACK}>


Hi jaclaz,

Thanks very much for your help - it put me on the right path and i have taken your adaptation and modified it further. :thumbup Here is the finished result.
@ECHO OFF
:: DELUD.BAT
:: DELete Unneded Directories
:: a script by jaclaz
:: Updated by `felix`
:: based on script DeadProf.bat
:: Written by Rob van der Woude
:: http://www.robvanderwoude.com
setlocal
set theNum=0
set qry=reg query "hklm\software\microsoft\windows nt\currentversion\profilelist" /v ProfilesDirectory
set fnd1=FIND /I "Documents and Settings"
set fnd2=FIND /I "ProfileImagePath"
for /f "Tokens=1,2*" %%i in ('%qry%^|%fnd1%') do (set DocSetDir0="%%k\All Users.w*")
for /f "Tokens=1,2*" %%i in ('%qry%^|%fnd1%') do (set DocSetDir1="%%k\Default User*")

CALL :CheckIfDuplicate %DocSetDir0% %DocSetDir1%
GOTO:EOF

:CheckIfDuplicate
FOR /D %%A IN ("%~1*") DO CALL :DelDuplicateProfiles "%%A" %1
FOR /D %%A IN ("%~2*") DO CALL :DelDuplicateProfiles "%%A" %2
GOTO:EOF

:DelDuplicateProfiles
set /a theNum=%theNum%+1
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v RemoveDuplicateProfile%theNum% /d "%comspec% /C RMDIR /S /Q ""%1""" /f >NUL
echo %theNum% Deleting corrupted profile "%~nx1" . . .

endlocal

One question is there a better way for me to implement the :CHECKIF DUPLICATE section? Right now i am using 2 lines - is it possible to do it in a single line? :blink:
"I seek not to know all the answers, but to understand the questions."
- Kwai Chang Caine.


Want to setup your default user/all users unattended install easy? - Simplify iT - GuidesCheers,
FeLiX

#9
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,474 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
I'll have a look at it, it seems like a nice piece of work, but, on first glance, where is the
"fnd2" variable
reused?
:blink:

jaclaz

#10
Martin Zugec

Martin Zugec

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,373 posts
  • Joined 24-January 04
Well, if I understood what U want to do, why not just use simple line of code, e.g.

for /f "usebackq delims= tokens=1,2" %%i IN (`dir /b "c:\documents and settings"`) DO IF /i "%%i" NEQ "default user" rmdir /s /q "c:\Documents and settings\%%i"


?
Like my opinions? Read Deployment/scripting blog
Like my scripts? They are under DrinkWare license :)

#11
`Felix`

`Felix`

    MSFN Contributor

  • Member
  • PipPipPip
  • 481 posts
  • Joined 28-July 04

I'll have a look at it, it seems like a nice piece of work, but, on first glance, where is the
"fnd2" variable
reused?
:blink:

jaclaz

<{POST_SNAPBACK}>


Hi jaclaz,

in the version you see here i haven't used fnd2, as it was not needed. I just left it in there incase i want to use it later... am still building on the script :)

Also how do i address the fact that default user is hidden? When hidden it can not be found using this method :no:
"I seek not to know all the answers, but to understand the questions."
- Kwai Chang Caine.


Want to setup your default user/all users unattended install easy? - Simplify iT - GuidesCheers,
FeLiX

#12
`Felix`

`Felix`

    MSFN Contributor

  • Member
  • PipPipPip
  • 481 posts
  • Joined 28-July 04

Well, if I understood what U want to do, why not just use simple line of code, e.g.

for /f "usebackq delims= tokens=1,2" %%i IN (`dir /b "c:\documents and settings"`) DO IF /i "%%i" NEQ "default user" rmdir /s /q "c:\Documents and settings\%%i"


?

<{POST_SNAPBACK}>

Hi soulin,

Thanks for the suggestion. I am actually doing a check against the registry and then deleting duplicates for a number of directories. in the earlier posts you are only seeing part of the final code as it is still a work in progress :)
"I seek not to know all the answers, but to understand the questions."
- Kwai Chang Caine.


Want to setup your default user/all users unattended install easy? - Simplify iT - GuidesCheers,
FeLiX

#13
`Felix`

`Felix`

    MSFN Contributor

  • Member
  • PipPipPip
  • 481 posts
  • Joined 28-July 04
Think i am almost there - just need to address the hidden directories...
"I seek not to know all the answers, but to understand the questions."
- Kwai Chang Caine.


Want to setup your default user/all users unattended install easy? - Simplify iT - GuidesCheers,
FeLiX

#14
`Felix`

`Felix`

    MSFN Contributor

  • Member
  • PipPipPip
  • 481 posts
  • Joined 28-July 04
Ok guy's here it is... i have been testing and tweaking for 3 days solid and i think i have the bugs out now, but would be interested in any feedback etc particularly any ways to streamline the code further.. :thumbup

if you want some background please look at This thread

@ECHO OFF
:: Fix and Delete Duplicate Profiles 1.1.9
:: Copyright 2005. `felix`.
:: Credits to jaclaz, soulin and all the great people from MSFN
:: for there help and testing :)
setlocal
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)
for /f "Tokens=1,2*" %%i in ('%qry1%^|%fnd1%') do (set DocSetDir1="%%k\All Users")
for /f "Tokens=1,2*" %%i in ('%qry1%^|%fnd1%') do (set DocSetDir2="%%k\Default User")
for /f "Tokens=1,2*" %%i in ('%qry2%^|%fnd5%') do (set DocSetDir3="%%k")
for /f "Tokens=1,2*" %%i in ('%qry2%^|%fnd6%') do (set DocSetDir4="%%k")
for /f "Tokens=1,2*" %%i in ('%qry2%^|%fnd7%') do (set DocSetDir5="%%k")

CALL:CheckCurrentLocal
CALL:CheckIfDuplicate1 %DocSetDir1% %DocSetDir2% %DocSetDir3% %DocSetDir4% %DocSetDir5%
GOTO:EOF

:CheckCurrentLocal
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

:CheckIfDuplicate1
CALL:Header
FOR /f "Tokens=1,2*" %%i in ('%qry2%^|%fnd3%') do if /i "%%k"=="All Users" (
CALL:UnHideIt "All Users" "%DocSetDir0%" & FOR /D %%A IN ("%~1.w*") DO CALL:DelDuplicateProfiles "%%A" %1 )
FOR /f "Tokens=1,2*" %%i in ('%qry2%^|%fnd4%') do if /i "%%k"=="Default User" (
CALL:UnHideIt "Default User" "%DocSetDir0%" & FOR /D %%A IN ("%~2.*") DO CALL:DelDuplicateProfiles "%%A" %2 )
FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry2%^|%fnd5%') do if /i "%%k"=="LocalService" (
CALL:UnHideIt "LocalService" "%DocSetDir0%" & FOR /D %%A IN ("%~3.*") DO CALL:DelDuplicateProfiles "%%A" %3 )
FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry2%^|%fnd6%') do if /i "%%k"=="NetworkService" (
CALL:UnHideIt "NetworkService" "%DocSetDir0%" & FOR /D %%A IN ("%~4.*") DO CALL:DelDuplicateProfiles "%%A" %4 )
FOR /f "delims=\ Tokens=1,2*" %%i in ('%qry3%^|%fnd7%') do if /i "%%k"=="%UserName%" (
CALL:UnHideIt "%UserName%" "%DocSetDir0%" & FOR /D %%A IN ("%~5*") DO CALL:DelDuplicateProfiles "%%A" %5)
CALL:Footer
GOTO:EOF

:DelDuplicateProfiles
set /a theNum=%theNum%+1
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v RemoveDuplicateProfile%theNum% /d "%comspec% /C RMDIR /S /Q ""%1""" /f >NUL
>> c:\AllUsersProfilefix.log echo  %theNum% "%~nx1" was deleted from "%DocSetDir0%"
GOTO:EOF

:Header
> c:\AllUsersProfilefix.log echo Fix and Remove Duplicate Profiles 1.1.9
>> c:\AllUsersProfilefix.log echo Copyright 2005, `felix`.
>> c:\AllUsersProfilefix.log echo Generated %DATE:~-10%.
>> 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 default values. 
>> c:\AllUsersProfilefix.log echo  "%KEY%"
>> c:\AllUsersProfilefix.log echo.
GOTO:EOF

:Footer
>> 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?scid=kb;en-us;314045
>> c:\AllUsersProfilefix.log echo.
GOTO:EOF

:UnHideIt
for /f "usebackq delims= tokens=1,2" %%i IN (`dir /ah /b "%~2\%~1*"`) DO IF /i "%%i" NEQ "%~1" attrib -a -s -h "%~2\%%i"
GOTO:EOF

endlocal

"I seek not to know all the answers, but to understand the questions."
- Kwai Chang Caine.


Want to setup your default user/all users unattended install easy? - Simplify iT - GuidesCheers,
FeLiX

#15
`Felix`

`Felix`

    MSFN Contributor

  • Member
  • PipPipPip
  • 481 posts
  • Joined 28-July 04
Hi guy's

Well i have been streamlining the code further and i think i have all the bugs out now accept one - when i run the process i am incrementing a number that is added to the runonce insert function to remove the directories found at next logon. The directories are found and logged, but the number is not incrementing for the like directories - see example below.

Fix and Remove Duplicate Profiles 1.1.14
Copyright 2005, `felix`.
Generated 01/03/2005.

This computer was found to have one or more duplicate system or user profiles.

The following registry key has been updated with default values.
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"

1 "Daz.EPSILON" was deleted from "D:\Documents and Settings"
1 "Daz.EPSILON.000" was deleted from "D:\Documents and Settings"
1 "Daz.EPSILON.001" was deleted from "D:\Documents and Settings"
1 "Daz.EPSILON.002" was deleted from "D:\Documents and Settings"

This issue is possibly caused by the following reasons:
* The computer operating system has been reinstalled.
* The computer operating system has been restore from a back-up image.

For more information please see Microsoft Knowledge Base Article link below:
http://support.micro...kb;en-us;314045


The numbers in blue above should be sequencial, however because these are being picked up from the one dir listing they are getting the same number...

Anyone got any ideas how i can do this better... current build of code below.

@ECHO OFF
:: Fix and Delete Duplicate Profiles 1.1.14
:: Copyright 2005. `felix`.
:: Credits to jaclaz, soulin and all the great people from MSFN
:: for there help and testing :)
IF %OS%!==! GOTO:EOF
setlocal
set theNum=1
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
GOTO:EOF

:CheckCurrentLocal
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 )
rem ping -n 2 127.0.0.1>nul
GOTO:EOF

:CheckIfDuplicate
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
> c:\AllUsersProfilefix.log echo Fix and Remove Duplicate Profiles 1.1.14
>> c:\AllUsersProfilefix.log echo Copyright 2005, `felix`.
>> c:\AllUsersProfilefix.log echo Generated %DATE:~-10%.
>> 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 default values.
>> c:\AllUsersProfilefix.log echo  "%KEY%"
>> c:\AllUsersProfilefix.log echo.
GOTO:EOF

:Footer
>> 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.micro...kb;en-us;314045
>> c:\AllUsersProfilefix.log echo.
GOTO:EOF

:Doit
for /f "usebackq delims= tokens=1,2" %%i IN (`dir /ah /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" (
set /a theNum=%theNum%+1
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v RemoveDuplicateProfile%theNum% /d "%comspec% /C RMDIR /S /Q """%~2\%%i"""" /f >NUL
>> c:\AllUsersProfilefix.log echo  %theNum% "%%i" was deleted from "%DocSetDir0%")

GOTO:EOF

endlocal


Code that performs this function in PURPLE

Any help would be greatly appreciated :thumbup
"I seek not to know all the answers, but to understand the questions."
- Kwai Chang Caine.


Want to setup your default user/all users unattended install easy? - Simplify iT - GuidesCheers,
FeLiX

#16
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,474 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
It does seem like a very good work.

I'll have a look at it in the next days and post comments.

By the way, thanks for the credits, but actually you seem a much more proficent batch writer than I am.

By looking at your code I found a missing ^ character before the pipeline | in a simple script I was striving to write and that did not work.

Though seemingly unrelated, as it just deletes empty directories, I think it might be a handy tool, it is posted here:
http://www.msfn.org/...ic=24961&st=43#

jaclaz




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users