这是根据我们公司工作流程及需求写的,没有用第三方软件,全用系统自带的命令完成的,XP,win7,win8都可以用!把脚本原文件放在C盘或其它目录,创建快捷方式到开机启动项就可以了,第一次运行,输入一些参数,后面就不用管了,可以根据自己公司具体情况再更改,只是写的不好,脚本底子没有,瞎捉摸的
@echo off
echo 要设置IP吗?
set /p shuru4=请输入y/n:
::if %shuru4%==y (goto ip) else (goto ks)
if %shuru4%==y (set /p ip=请输入7网段属于你的IP最后一位:) else (echo 你不打算设置IP)
echo 要更改计算机名吗?
set /p shuru1=请输入y/n:
if %shuru1%==y (set /p cmpname=请输入你的计算机名称:) else (echo 你不准备改计算机名)
echo 要加域吗?
set /p shuru8=请输入y/n:
if %shuru8%==y (set /p zz=请输入你所在的部门名称:) else (echo 你不想要加域)
if defined ip (goto :ip) else (goto ks)
:ip
@echo 设置IP
::set /p ip=请输入7网段属于你的IP最后一位:
netsh interface ip set address name=本地连接 source=static addr=192.168.7.%ip% mask=255.255.255.0 gateway=192.168.7.1 gwmetric=auto
netsh interface ip set dns name=本地连接 source=static addr=192.168.100.206 register=primary
netsh interface ip add dns name=本地连接 addr=192.168.100.202 index=2
:ks
if exist retuvlue.txt (goto jd) else (goto gm)
:gm
if defined cmpname (goto gm1) else (goto jd)
:gm1
net config workstation |find "工作站域 DNS " > name1.txt
::findstr .* name1.txt &&echo full || echo kong
for %%a in (name1.txt) do if %%~za==0 (goto gm3)
for /f "tokens=4 delims= " %%b in (name1.txt) do set q=%%b
if %q%==greatstar.com (goto gm2) else (goto gm3)
:gm2
wmic computersystem where name="%computername%" call rename name="%cmpname%" username="wfl" password="wfl" >retuvlue.txt
for /f "delims=" %%o in ('findstr Return retuvlue.txt') do set rv=%%o
echo %rv% >jg.txt
for /f "tokens=3 delims= " %%i in (jg.txt) do set e=%%i
echo %e% > fh.txt
for /f "tokens=1 delims=;" %%j in (fh.txt) do set aa=%%j
if %aa%==0 (echo 计算机名更改成功 >retuvlue.txt && goto cq) else (echo 计算机名更改失败,请再尝试一遍 && goto gm2)
:gm3
::更改计算机名
wmic computersystem where name="%computername%" call rename name="%cmpname%" >retuvlue.txt
for /f "delims=" %%l in ('findstr Return retuvlue.txt') do set fhz=%%l
echo %fhz% >jg.txt
for /f "tokens=3 delims= " %%i in (jg.txt) do set n=%%i
echo %n% > fh.txt
for /f "tokens=1 delims=;" %%j in (fh.txt) do set m=%%j
if %m%==0 (echo 计算机名更改成功 >retuvlue.txt && goto cq) else (echo 计算机名更改失败,请再尝试一遍 && goto gm3)
:cq
echo @echo off >temp.txt
echo set zz=%zz% >>temp.txt
setlocal enabledelayedexpansion
for /f "tokens=*" %%i in (jdomain.bat) do (
set /a n+=1
if !n! gtr 56 echo %%i>>temp.txt
)
shutdown -r -f -t 5
move temp.txt jdomain.bat
echo 正在重启中...
pause>nul
exit
:jd
rem 加域
if exist retuvlue.txt (goto pd) else (goto xunwen)
:pd
for /f "delims=" %%x in (retuvlue.txt) do set fhz=%%x
if %fhz%==加域成功 (goto jdok) else (if %fhz%==计算机名更改成功 (goto jd1) else (goto xuanze))
:xunwen
echo 需要加域吗?
set /p shuru3=请输入y/n:
if %shuru3%==y (goto jd1) else (goto xiande)
:jd1
if defined zz (goto zb) else (echo 你没有选择要加入到的部门 && set /p zz=请输入你所在的部门名称:)
:zb
echo 正在加域,请勿关闭...
set sleep=ping 127.0.0.1 -n
%sleep% 25 >nul
wmic computersystem where "name='%COMPUTERNAME%'" call joindomainorworkgroup fjoinoptions=3 name="greatstar.com" username="wfl" password="wfl" accountou="ou=%zz%;ou=巨星科技;ou=计算机;dc=greatstar;dc=com" > retuvlue.txt
for /f "delims=" %%x in ('findstr Return retuvlue.txt') do set fhz=%%x
echo %fhz% >jg.txt
for /f "tokens=3 delims= " %%w in (jg.txt) do set b=%%w
echo %b% > fh1.txt
for /f "tokens=1 delims=;" %%k in (fh1.txt) do set q=%%k
if %q%==0 (echo 加域成功 > retuvlue.txt && goto cq1) else (goto jd2)
:cq1
shutdown -r -f -t 0
echo 正在重启中...
pause>nul
:jdok
net config workstation |find "工作站域 DNS " > name.txt
for /f "tokens=4 delims= " %%a in (name.txt) do set p=%%a
if %p%==greatstar.com (echo 你已经成功加入域%p% && goto shanchu1) else (goto jd2)
:jd2
echo 加域失败,重新尝试加域吗?
set /p shuru=请输入y/n:
if %shuru%==y (goto jd1) else (goto tc)
:shanchu
echo 要删除加域文件吗?
set /p shuru2=请输入y/n:
if %shuru2%==y (goto shanchu1) else (goto tc)
:xuanze
echo 1:改计算机名
echo 2:加域
echo 3:退出
set /p xz=请输入你想执行的操作序号:
if %xz% equ 1 (goto gm1) else (if %xz% equ 2 (goto jd1) else (goto xiande))
:shanchu1
del retuvlue.txt /q
del retuvlue1.txt /q
del jg.txt /q
del name.txt /q
del name1.txt /q
del fh.txt /q
del fh1.txt /q
del jg1.txt /q
del jdomain.bat /q
exit
:xiande
echo 你好无聊
pause
del retuvlue.txt /q
del retuvlue1.txt /q
del jg.txt /q
del name.txt /q
del name1.txt /q
del fh.txt /q
del fh1.txt /q
del jg1.txt /q
:tc
del retuvlue.txt /q
del retuvlue1.txt /q
del jg.txt /q
del name.txt /q
del name1.txt /q
del fh.txt /q
del fh1.txt /q
del jg1.txt /q
exit
::fjoinoptions=1是默认,加入工作组,2是在域里创建一个帐户,4***一个域内存在的帐户,32允许加入到新域,即使此计算机已经加入到一个域,不过好像现在没有32了,只有3,32不起作用
::accountou加入到指定OU,如果不指定或指定accoutou=null则默认加入computers
::accountou="ou=计算机;dc=greatstar;dc=com"
::加入或更改工作组
::wmic computersystem where name="%COMPUTERNAME%" call joindomainorworkgroup name="workgroup"
:+退域
::wmic computersystem where name="%COMPUTERNAME%" call unjoindomainorworkgroup username="greatstar\wfl" password="wfl" funjoinoptions=0这个是默认操作,如果是2,可以退域后禁用计算机帐号,但不能***,但我试了后没什么用,还是不能禁用帐户
::unjoindomainorworkgroup后面的都可以不写