【问题标题】:Creating batch to remotely recreate user win 7 profile创建批处理以远程重新创建用户 win 7 配置文件
【发布时间】:2014-08-18 21:46:37
【问题描述】:

我在 win 7 企业环境中进行以下批处理,远程重新创建用户配置文件。我知道代码可能会更有效,但是除了需要删除用户计算机上用于其个人资料的注册表项之外,它都可以正常工作。我不确定如何找到他们的特定条目然后将其删除。大家可以看看吗?此外,欢迎任何代码改进。我仍然对顶部的整个“RWM”图形有疑问,但这并不重要。你会看到你是否打开了批处理。

@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

【问题讨论】:

  • 请编辑您的代码并删除所有与您的问题无关的不必要的噪音。

标签: batch-file windows-7 remote-access user-profile recreate


【解决方案1】:

在 powershell 中你可以使用:

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

【讨论】:

    【解决方案2】:

    您可以使用专门为此任务设计的工具(从文件夹视图和注册表视图中彻底删除用户配置文件)Delprof http://www.microsoft.com/en-us/download/details.aspx?id=5405&751be11f-ede8-5a0c-058c-2ee190a24fa6=True 执行此任务。您还可以看看名为 Delprof 2 (http://www.edugeek.net/forums/windows-7/75098-delprof2-unofficial-successor-microsoft-s-delprof-user-profile-deletion-tool.html) 的新(非官方)工具

    您可能会详细解释“重新创建”用户配置文件的含义,您是否只是指擦除用户配置文件并让 Windows 重新创建它并将批处理添加到启动文件夹以进行一些自定义?

    【讨论】:

    • 正确。因此,使用该实用程序,我是否不需要设置类似 psexec 的东西以便我可以远程执行它?另外,像这样永久删除它让我有点紧张。如果用户数据备份不成功,然后删除,他们的所有数据都消失了。
    • 我希望 Win 7 像 XP 一样,我们可以重命名用户配置文件文件夹:(
    • 确实,首先,将 delprof.exe 复制到 \\%IP%\Admin$(共享为 %WINDIR% 文件夹),然后使用 psexec 和远程本地管理员组的帐户成员运行它机器。
    • 在此之前,为了安全起见,您仍然可以复制用户文件夹。最后,您问的第一件事是配置文件路径在注册表中的存储位置,即使我建议改用 delprof,您也可以查看此注册表项 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
    猜你喜欢
    • 2014-08-19
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 2014-06-21
    • 2013-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多