windows 自定义配置
个人电脑
curl -o wget.exe http://iso.sqlfans.cn/windows/system32/wget.exe
curl -o rar.exe http://iso.sqlfans.cn/windows/system32/rar.exe
curl -o unzip.exe http://iso.sqlfans.cn/windows/system32/unzip.exe
move /y wget.exe c:\windows\system32\
move /y rar.exe c:\windows\system32\
move /y unzip.exe c:\windows\system32\
自定义的编排
::1.将计算机图标添加到桌面
rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0
::2.显示已知文件类型的扩展名
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v HideFileExt /t REG_DWORD /d 0 /f
taskkill /f /im explorer.exe & start explorer.exe
::3.创建cmd快捷方式到桌面
set path=%WINDIR%\System32\cmd.exe
set topath="%USERPROFILE%\Desktop\cmd.url"
echo [InternetShortcut] > %topath%
echo URL="%path%" >> %topath%
echo IconIndex=0 >> %topath%
echo IconFile=%path% >> %topath%
::4.禁用windows自动更新
net stop wuauserv
sc config wuauserv start= disabled
windows 7
::1.修改机器信息
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation" /v "Manufacturer" /t REG_SZ /d "你把账结了" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation" /v "Model" /t REG_SZ /d "Windows 7 旗舰版" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation" /v "SupportHours" /t REG_SZ /d "09:00-18:00" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation" /v "SupportPhone" /t REG_SZ /d "15212345678" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation" /v "SupportUrl" /t REG_SZ /d "https://user.qzone.qq.com/78667417" /f
windows 11
::1.移除资源管理器中的 OneDrive
cmd /k reg add "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /v "System.IsPinnedToNameSpaceTree" /d "0" /f
::2.依次移除资源管理器中 3D对象、视频、音乐、图片、主文件夹、图库
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A}" /f
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{f86fa3ab-70d2-4fc7-9c99-fcbf05467f3a}" /f
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{3dfdf296-dbec-4fb4-81d1-6a3438bcf4de}" /f
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{24ad3ad4-a569-4530-98e1-ab02f9417aa8}" /f
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{f874310e-b6b7-47dc-bc84-b9e6b38f5903}" /f
reg add "HKCU\Software\Classes\CLSID\{e88865ea-0e1c-4e20-9aa6-edcd0212c87c}" /v "System.IsPinnedToNameSpaceTree" /t REG_DWORD /d 0 /f
::3.关闭快速访问
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" /v "HubMode" /t REG_DWORD /d 1 /f
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v "NoRecentDocsHistory" /t REG_DWORD /d 1 /f
::4.设置开机自动密码登录,比如账密:Administrator / admin147
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 "DefaultPassword" /t REG_SZ /d "admin147" /f
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "AutoAdminLogon" /t REG_DWORD /d 1 /f
服务器
Windows Server 2008
echo ## Enable role and feature ##
ServerManagerCmd.exe -install NET-Framework-Core
ServerManagerCmd.exe -install Telnet-Client
:: 通过 ServerManagerCmd 启用 .NET Framework 3.5 功能
ServerManagerCmd.exe -install NET-Framework-Core
:: 通过 ServerManagerCmd 移除 .NET Framework 3.5 功能
ServerManagerCmd.exe -remove NET-Framework-Core
Windows Server 2012 R2
- 通过 dism 启用 .NET Framework 3.5 功能(不再用ServerManagerCmd来安装)
echo ## 启用 .NET Framework 3.5 ##
cd /d c:\
wget -c http://iso.sqlfans.cn/windows/win2012r2/sources.zip
unzip sources.zip
dism /online /enable-feature /featurename:NetFX3 /All /Source:C:\sources\sxs /LimitAccess
echo ## Enable role and feature ##
dism /online /Enable-Feature /FeatureName:TelnetClient
Windows Server 2016
- 通过 dism 启用 .NET Framework 3.5 功能(不再用ServerManagerCmd来安装)
cd /d c:\
wget -c http://iso.sqlfans.cn/windows/win2016/sources.zip
unzip sources.zip
dism /online /enable-feature /featurename:NetFX3 /All /Source:C:\sources\sxs /LimitAccess
Windows Server 2019
- 通过 dism 启用 .NET Framework 3.5 功能(不再用ServerManagerCmd来安装)
cd /d c:\
wget -c http://iso.sqlfans.cn/windows/win2019/sources.zip
unzip sources.zip
dism /online /enable-feature /featurename:NetFX3 /All /Source:C:\sources\sxs /LimitAccess
Windows Server 2022
- 通过 dism 启用 .NET Framework 3.5 功能(不再用ServerManagerCmd来安装)
cd /d c:\
wget -c http://iso.sqlfans.cn/windows/win2022/sources.zip
unzip sources.zip
dism /online /enable-feature /featurename:NetFX3 /All /Source:C:\sources\sxs /LimitAccess
Windows Server 2025
- 通过 dism 启用 .NET Framework 3.5 功能(不再用ServerManagerCmd来安装)
cd /d c:\
wget -c http://iso.sqlfans.cn/windows/win2025/sources.zip
unzip sources.zip
dism /online /enable-feature /featurename:NetFX3 /All /Source:C:\sources\sxs /LimitAccess
安装补丁包
dism /Online /Add-Package /PackagePath:"C:\Downloads\xxx.cab"
wmic qfe get hotfixid | findstr "KB5063877 KB5012170 KB5005112"
定时任务
::1.删除7天前的日志文件
forfiles /p "%systemdrive%\inetpub\logs\LogFiles" /s /m *.log /d -7 /c "cmd /c del @path"
forfiles /p "%windir%\Logs\CBS" /s /m *.log /d -7 /c "cmd /c del @path"
forfiles /p "%windir%\system32\LogFiles\HTTPERR" /s /m *.log /d -7 /c "cmd /c del @path"
配置防火墙
echo ## Set windows advfirewall ##
netsh advfirewall set allprofiles state off
netsh advfirewall firewall set rule name=all dir=in new enable=no
netsh advfirewall firewall set rule name=all dir=out new enable=no
netsh advfirewall firewall add rule name="permit_ping_echo_request" protocol=ICMPv4 dir=in action=allow
netsh advfirewall firewall add rule name="permit_mstsc_tcp_3389" protocol=TCP dir=in remoteip=192.168.0.0/255.255.0.0,47.100.228.234 localport=3389 action=allow
netsh advfirewall firewall add rule name="permit_http_tcp_80" protocol=TCP dir=in localport=80 action=allow
netsh advfirewall firewall add rule name="permit_https_tcp_443" protocol=TCP dir=in localport=443 action=allow
netsh advfirewall firewall add rule name="permit_ftp_tcp_10021" protocol=TCP dir=in remoteip=47.100.228.234 localport=10021 action=allow
netsh advfirewall firewall add rule name="permit_ftp_passive_tcp" protocol=TCP dir=in remoteip=47.100.228.234 localport=65500-65535 action=allow
netsh advfirewall firewall add rule name="block_in_tcp_135_137_138_139_445" protocol=TCP dir=in localport=135,137,138,139,445 action=block
netsh advfirewall firewall add rule name="block_in_udp_135_137_138_139_445" protocol=UDP dir=in localport=135,137,138,139,445 action=block
netsh advfirewall firewall add rule name="block_out_tcp_135_137_138_139_445" protocol=TCP dir=out localport=135,137,138,139,445 action=block
netsh advfirewall firewall add rule name="block_out_udp_135_137_138_139_445" protocol=UDP dir=out localport=135,137,138,139,445 action=block
netsh advfirewall set allprofiles state on
配置优化
echo ## Disable useless service for security ##
net stop Browser /yes
sc config Browser start= disabled
net stop WinHttpAutoProxySvc /yes
sc config WinHttpAutoProxySvc start= disabled
net stop RemoteRegistry /yes
sc config RemoteRegistry start= disabled
net stop SCardSvr /yes
sc config SCardSvr start= disabled
net stop SCPolicySvc /yes
sc config SCPolicySvc start= disabled
net stop Spooler /yes
sc config Spooler start= disabled
echo ## Enable necessary service for window update ##
net start BITS /yes
sc config BITS start= auto
net start wuauserv /yes
sc config wuauserv start= auto
echo ## 同步时间 ##
net start W32Time /yes
sc config W32Time start= auto
w32tm /config /manualpeerlist:ntp.aliyun.com /syncfromflags:manual /reliable:yes /update
w32tm -resync
服务器激活
echo ## 服务器激活-通过kms服务器激活,示例 116.211.11.18 ##
sc config W32Time start= auto
net start W32Time
Cscript c:\windows\system32\slmgr.vbs /skms 116.211.11.18
Cscript c:\windows\system32\slmgr.vbs /ato
Cscript c:\windows\system32\slmgr.vbs /skms 116.211.11.18
Cscript c:\windows\system32\slmgr.vbs /ato
echo ## windows2019服务器激活-通过序列号激活 ##
slmgr /upk
slmgr /ipk WMDGN-G9PQG-XVVXX-R3X43-63DFG
slmgr /skms zh.us.to
slmgr /ato
echo ## 查看激活信息 ##
slmgr /dli
调优排障
::查看系统信息
msinfo32
::收集硬件信息
msinfo32 /nfo C:\msinfo32.nfo /categories +systemsummary
::收集应用日志
wevtutil epl System C:\system.evtx
wevtutil epl Application C:\app.evtx
::查看簇大小
fsutil fsinfo ntfsinfo d:
::查看cpu型号
wmic cpu get Name
rem 查看OS版本\机器名\SN号\内存大小
wmic os get Caption,CSName,SerialNumber,TotalVisibleMemorySize
rem 查看处理器个数
echo %number_of_processors%
rem 查看处理器架构
echo %processor_architecture%
rem 查看处理器标识符
echo %processor_identifier%
IIS管理
:: 老机器:先导出所有应用程序池,再导出所有站点
%windir%\system32\inetsrv\appcmd list apppool /config /xml > c:\apppools.xml
%windir%\system32\inetsrv\appcmd list site /config /xml > c:\sites.xml
:: 新机器:先导入所有应用程序池,再导入所有站点
%windir%\system32\inetsrv\appcmd add apppool /in < c:\apppools.xml
%windir%\system32\inetsrv\appcmd add site /in < c:\sites.xml
:: 在IIS服务器上启用静态文件(.js、.css、.html之类)压缩
cscript C:\Inetpub\adminscripts\adsutil.vbs set w3svc/filters/compression/parameters/HcDoStaticCompression true
:: 在IIS服务器上启用动态文件(.asp之类)压缩
cscript C:\Inetpub\adminscripts\adsutil.vbs set w3svc/filters/compression/parameters/HcDoDynamicCompression true
::删除当前所有站点及应用程序池
cd /d d:
%windir%/system32/inetsrv/appcmd list site > allsite.txt
%windir%/system32/inetsrv/appcmd list apppool > allpool.txt
for /f "delims=(" %i in (allsite.txt) do %windir%/system32/inetsrv/appcmd delete %i
for /f "delims=(" %i in (allpool.txt) do %windir%/system32/inetsrv/appcmd delete %i
学习
dism角色功能
::列出操作系统中所有可用的功能,例如:
Dism /online /Get-Features
::启用映像中的特定功能,例如:
dism /online /Enable-Feature /FeatureName:TelnetClient
::启用映像中的特定功能。你可以使用 /All 参数在相同的命令中启用所有父功能,例如:
Dism /online /Enable-Feature /FeatureName:TFTP /All
::禁用映像中的特定功能,例如:
Dism /online /Disable-Feature /FeatureName:TelnetClient
::删除映像中的特定功能,而不删除映像中的功能清单,例如:
Dism /online /Disable-Feature /FeatureName:TFTP /Remove
软件的安装与卸载
:: 安装软件
start azure-cli-2.79.0-x64.msi
:: 查看已安装的版本
winget list | findstr "Azure"
:: 卸载指定版本
winget uninstall --id "Microsoft.AzureCLI" --version 2.79.0 --force
服务的注册与管理
:: 注册服务(注意有空格),并添加描述
sc create ReportService binPath= "C:\tools\ReportServer\ReportService.exe /instance:sr1" DisplayName= "上报服务"
sc description ReportService "填写服务描述信息"
:: 设置自动启动(注意有空格),并启动服务
sc config ReportService start= auto
net start ReportService
:: 创建用户,并更改服务的启动账号
net user sysadmin kT6f7m_wPKdW4037 /add /Y /expires:never
net localgroup administrators sysadmin /add
net stop ReportService
sc config ReportService obj= ".\sysadmin" password= "kT6f7m_wPKdW4037"
net start ReportService
:: 启动服务 net start ReportService
:: 停止服务 net stop ReportService
:: 卸载服务 sc delete ReportService
:: 删除服务
sc delete ReportService