标签:ad域
因为经常需要给公司员工电脑加域,以及其他的一些设置。一直想着做一个自动加域的批处理。
参照网上查到的各种信息,终于做成了一个适合自己的脚本。
分三个批处理win7需要以下文件1.bat ,joindomain.bat,clean.bat, 需要的程序netdom.exe netdom.exe.mui(可以在server2008系统中提取,32位和64位程序不同)
1.bat 负责修改机器名称
joindomain.bat 负责加入网域,将用户域账号加入本地组
clean.bat 负责清理脚本,添加权限,更新策略
--------------------------------------------------------------------------------------------------------------------------------------
1.bat
@ECHO off
color 4E
mode con: cols=75 lines=35
title ⅸ Auto Join Domain @neal ⅷ
ECHO
ECHO 自动加域批处理
ECHO
ECHO
ECHO 启动相关系统服务中..........
sc config LmHosts start= AUTO
net start "TCP/IP NetBIOS Helper"
sc config Browser start= AUTO
net start "Computer Browser"
sc config Winmgmt start= AUTO
net start "Windows Management Instrumentation"
sc config LanmanServer start= AUTO
net start "Server"
sc config LanmanWorkstation start= AUTO
net start "Workstation"
ECHO.
ECHO 服务启动完成......
pause>nul
cls
ECHO.
ECHO
ECHO 修改机器名称
ECHO
ECHO
ECHO.
ECHO 机器名类似此格式(ipt-000000-zida)
ECHO.
ECHO
ECHO.
set /p name=请输入机器名称:
reg add "HKEY_LOCAL_MACHINE\System\ControlSet001\Control\ComputerName\ActiveComputerName" /v ComputerName /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\ControlSet001\Control\ComputerName\ComputerName" /v ComputerName /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\ControlSet001\Services\Tcpip\Parameters" /v "NV Hostname" /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\ControlSet001\Services\Tcpip\Parameters" /v Hostname /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\ControlSet002\Control\ComputerName\ActiveComputerName" /v ComputerName /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\ControlSet002\Control\ComputerName\ComputerName" /v ComputerName /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\ControlSet002\Services\Tcpip\Parameters" /v "NV Hostname" /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\ControlSet002\Services\Tcpip\Parameters" /v Hostname /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ActiveComputerName" /v ComputerName /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName" /v ComputerName /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v Hostname /t reg_sz /d %name% /f >nul 2>nul
ECHO.
ECHO 机器名修改完毕......
pause>nul
cls
ECHO.
ECHO
ECHO 设置重启后的程序
ECHO
ECHO
ECHO.
::copy相应的文档至本机
copy netdom.exe C:\Windows\System32 /y
copy joindomain.bat C:\Windows\System32 /y
copy netdom.exe.mui C:\Windows\System32\en-US /y
copy clean.bat c:\windows\System32 /y
::设置重启后运行joindomain.bat
REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v joindomain /t reg_sz /d "C:\Windows\System32\joindomain.bat" /f >nul
::修改本机自动登录,省去重启后再输入密码
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d administrator /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName /t REG_SZ /d %name% /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d 本机管理员密码 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1 /f
ECHO.
ECHO 设置完毕将重启系统......
pause>nul
shutdown.exe -r -t 0
--------------------------------------------------------------------------------------------------------------------------------------
joindomain.bat
@ECHO off
color 4E
mode con: cols=75 lines=35
title ⅸ Auto Join Domain @neal ⅷ
ECHO.
ECHO
ECHO 选择ou加入网域
ECHO
ECHO.
ECHO
ECHO.
ECHO 1. computers
ECHO.
ECHO 2. abc
ECHO.
ECHO 3. def
ECHO.
ECHO
ECHO.
set OU=
set/p OU=请输入需要加入的ou:
if %OU% EQU 1 (set OUName=computers)
if %OU% EQU 2 (set OUName=abc)
if %OU% EQU 3 (set OUName=def)
netdom join %computername% /Domain:abc.com /ou:ou=%OUName%,ou="Workstations",dc=abc,dc=com /Userd:abc\域管理员账号 /Passwordd:域管理员密码
pause
cls
:start
ECHO.
ECHO
ECHO 将用户域账号加入本机群组
ECHO
ECHO.
ECHO
echo.
echo a. administrator
echo.
echo p. powerusers
echo.
set /p numis=请选择(a\p):
if /i "%numis%"=="a" goto a
if /i "%numis%"=="p" (goto p) else (echo 选择错误&&pause>nul&&goto start)
:a
echo 加入administrators组
set username=
set/p username=输入用户的域账号(abc\xxx)
net localgroup "administrators" ies\%username% /add
ECHO.
ECHO 加入成功......
goto r
:p
echo 加入powerusers组
set username=
set/p username=输入用户的域账号(abc\xxx)
net localgroup "power users" ies\%username% /add
ECHO.
ECHO 加入成功......
goto r
:r
pause>nul
cls
ECHO.
ECHO
ECHO 重启前的设置
ECHO
ECHO
ECHO.
::设置重启后运行的脚本
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v clean /t reg_sz /d "C:\Windows\System32\clean.bat" /f >nul
::因为加域后DefaultDomainName会有改变,重新设置下自动登录
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d administrator /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName /t REG_SZ /d %computername% /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d 本机管理员密码 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1 /f
ECHO.
ECHO 将自动重启
pause>nul
shutdown.exe -r -t 0
---------------------------------------------------------------------------------------------------------------------------------------
clean.bat
@ECHO off
color 4E
mode con: cols=75 lines=35
title ⅸ Auto clean @neal ⅷ
::安全问题,自动清除脚本
del C:\Windows\System32\joindomain.bat
del C:\Windows\System32\netdom.exe
del C:\Windows\System32\en-US\netdom.exe.mui
rd /s /q "C:\Users\Administrator\Desktop\autojoinwin732"
::给d,e,f盘添加pouser user的完全控制权限
ECHO 添加DEF盘pouser user的完全控制权限
cacls d:\ /g "power users":f /e
cacls e:\ /g "power users":f /e
cacls f:\ /g "power users":f /e
::取消自动登录,及修改其中注册表中保存的管理员密码
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 0 /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d IES=123 /f
ECHO 更新组策略
gpupdate /force
ECHO 任意键重启......
pause>nul
shutdown.exe -r -t 0
本文出自 “运维工程师的聚集地” 博客,请务必保留此出处http://tingwei.blog.51cto.com/9767573/1594680
标签:ad域
原文地址:http://tingwei.blog.51cto.com/9767573/1594680