请把轻狂志网址 www.flighty.cn 加入收藏夹,其他俱为假冒,谨防被骗!赞助请点 这里!找东东请用右边的搜索 ===>
29 2014-08

NSIS:把计算机名转换为大写或小写字符

作者:少轻狂 | 发布:2014-08-29 | 更新:2014-08-29 | 分类:部署 | Disposition | 热度:

最近在做一个包的时候,轻狂遇到了转换大小写的问题,网络上似乎没有相关例子可以借鉴,研究了一下发现用WordFunc.nsh头文件可以实现,于是记一下方便大家。

 

	;从注册表中读取当前计算机名
	ReadRegStr $R1 HKLM "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" "ComputerName"
	MessageBox MB_OK "计算机名$R1"
	;把字符串转换为大写,如果转换为小写则把+改为-即可,还可以设置某些字符不转换哦
	${StrFilter} "$R1" "+" "" "" $R2
	MessageBox MB_OK "转换后的计算机名$R2"
	;把计算机名全部改为大写
	WriteRegStr   HKLM "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" "ComputerName" "$R2"
	WriteRegStr   HKLM "SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName" "ComputerName" "$R2"
	WriteRegStr   HKLM "SYSTEM\CurrentControlSet\services\Tcpip\Parameters" "NV Hostname" "$R2"
	WriteRegStr   HKLM "SYSTEM\CurrentControlSet\services\Tcpip\Parameters" "Hostname" "$R2"
	WriteRegStr   HKLM "SYSTEM\ControlSet001\Control\ComputerName\ComputerName" "ComputerName" "$R2"
	WriteRegStr   HKLM "SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName" "ComputerName" "$R2"
	WriteRegStr   HKLM "SYSTEM\ControlSet001\services\Tcpip\Parameters" "NV Hostname" "$R2"
	WriteRegStr   HKLM "SYSTEM\ControlSet001\services\Tcpip\Parameters" "Hostname" "$R2"
	WriteRegStr   HKLM "SYSTEM\ControlSet002\Control\ComputerName\ComputerName" "ComputerName" "$R2"
	WriteRegStr   HKLM "SYSTEM\ControlSet002\services\Tcpip\Parameters" "NV Hostname" "$R2"
	WriteRegStr   HKLM "SYSTEM\ControlSet002\services\Tcpip\Parameters" "Hostname" "$R2"
	WriteRegStr   HKCU "Software\Microsoft\Windows Media\WMSDK\General" "ComputerName" "$R2"
	WriteRegStr   HKCU "Volatile Environment" "LOGONSERVER" "\\$R2"
	WriteRegStr   HKCU "Volatile Environment" "USERDOMAIN" "$R2"