0

I'm making the batch below in the win 7 corporate environment that recreates a users profile remotely. I know the code could be more efficient, but it all works except where the registry entry on the users computer for their profile needs to be removed. I'm not sure how I would find their specific entry and then delete it. Could you guys take a look? Also, any code improvements are welcomed. I'm still having issues with the whole "RWM" graphic at the top, but that's not important right now. You'll see if you open the batch.

@echo off
MODE 75,30

::Notes
::Remote Workstation Manager BETA unreleased
::
::

:start
cls
TITLE Remote Workstation Manager BETA unreleased

::Declarations
setLocal EnableDelayedExpansion
set date=%date:~4,2%%date:~7,2%%date:~10,4%%
color 0a

echo.&echo.&echo.&echo.&echo.&echo.
SET /P ".=                   "<nul &Call :Color 0E " ######      #     #     #     # " end&echo.
SET /P ".=                   "<nul &Call :Color 0E " #     #     #  #  #     ##   ## " end&echo.
SET /P ".=                   "<nul &Call :Color 0E " #     #     #  #  #     # # # # " end&echo.
SET /P ".=                   "<nul &Call :Color 0E " ######      #  #  #     #  #  # " end&echo.
SET /P ".=                   "<nul &Call :Color 0E " #   #   ### #  #  # ### #     # " end&echo.
SET /P ".=                   "<nul &Call :Color 0E " #    #  ### #  #  # ### #     # " end&echo.
SET /P ".=                   "<nul &Call :Color 0E " #     # ###  ## ##  ### #     # " end&echo.
echo.
SET /P ".=                   "<nul &Call :Color 09 "=================================" end&echo.
SET /P ".=                   "<nul &Call :Color 09 "=" &Call :Color 0C " R" &Call :Color 0f "emote" &Call :Color 0C " W" &Call :Color 0f "orkstation" &Call :Color 0C " M" &Call :Color 0f "anager v1" &Call :Color 09 " =" end&echo.
SET /P ".=                   "<nul &Call :Color 09 "=================================" end&echo.&echo.&echo.

echo 1. - Recreate Windows User Profile
::Restarts Users Laptop and when at Login Screen

echo.0. - Exits

set /p input=Choose a number and press enter: 
if %input%==1 goto :1
if %input%==0 goto :0

:1
cls
@echo off
TITLE Recreating Windows Profile

set /p ip= Enter the computers IP or Workstation Name: 
echo The ip is %ip%

set /p username= Enter the users EUID: 
echo The username is %USERNAME%

cls
echo Press enter to restart the users machine.
echo.
pause

xcopy "\\utils\h$\Utilities\Restore.bat" "\\%ip%\c$\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" /i /y

cls
echo Restarting users PC . . .

@echo off

shutdown -r -f -t 1 -m \\%ip%

@echo off

:loop
Timeout /t 15
ping -n 1 %ip% >null
if %ERRORLEVEL% EQU 0 goto :loop
if %ERRORLEVEL% EQU 1 goto :continue2

:continue2
cls
@echo off
echo Waiting for Startup . . .
:retry
Timeout /t 2
IF NOT EXIST "\\%ip%\c$\Users\%USERNAME%\" goto :retry
IF EXIST "\\%ip%\c$\Users\%USERNAME%\" goto :continue3

:continue3
Timeout /t 10
cls
echo Refreshing profile . . .

rmdir "\\%ip%\c$\Users\Temp" /s /q

rmdir "\\%ip%\c$\Users\Temp.COF" /s /q

rename "\\%ip%\c$\Users\%USERNAME%" %USERNAME%.%date%

echo.
echo Complete.

Timeout /t 10
cls

echo Waiting for the User to log in . . .

:retry2
sleep 2
IF NOT EXIST "\\%ip%\c$\Users\%USERNAME%\" goto :retry2
IF EXIST "\\%ip%\c$\Users\%USERNAME%\" goto :continue4

:continue4

cls
echo Completed. Wait for new profile to be created and verify the users data has been restored.

echo.
pause
goto :start

0:
exit
Sandfrog
  • 33
  • 9

2 Answers2

0

You might use a tool specifically designed for this task (deleting user profile cleanly, both from folder view and from registry view) Delprof http://www.microsoft.com/en-us/download/details.aspx?id=5405&751be11f-ede8-5a0c-058c-2ee190a24fa6=True do this task. You might also have a look to a new (unofficial) tool called Delprof 2 (http://www.edugeek.net/forums/windows-7/75098-delprof2-unofficial-successor-microsoft-s-delprof-user-profile-deletion-tool.html)

You might explain more about what you mean by "recreate" user profile, do you simply mean wipe the user profile and let Windows recreate it and add a batch to startup folder that will do some customization ?

rebrec
  • 515
  • 4
  • 8
  • Correct. So using that utility, wouldn't I then need to set up something like psexec so I can remotely execute it? Also, deleting it permanentely like that makes me a bit nervous. If the users data is somehow not successfull in backing up, and that deletes it, all their data is gone. – Sandfrog Jun 27 '14 at 20:32
  • I wish Win 7 was like XP where we could just rename the Users Profile folder :( – Sandfrog Jun 27 '14 at 21:04
  • Indeed, first, copy delprof.exe into \\%IP%\Admin$ (share for %WINDIR% folder) then run it using psexec with an account member of the local admin group of the remote machine. – rebrec Jun 28 '14 at 12:09
  • Before that, you can still make a copy of the user folder for safety purpose. Last, the first thing you asked was where the profile path was stored in the registry, even if i would suggest to use delprof instead, you might have a look at this registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList – rebrec Jun 28 '14 at 12:15
0

In powershell you could use:

gci "HKLM:\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\ProfileList" -rec -ea SilentlyContinue | % { if((get-itemproperty -Path $_.PsPath) -match "techid") { $_.PsPath} } | Remove-Item