#NoTrayIcon
Opt('GUIOnEventMode', 1);OnEvent模式
$hParentWin = GUICreate('xxx', 206, 80)
$Button1 = GUICtrlCreateButton('计算机名', 18, 28, 80)
$Button2 = GUICtrlCreateButton('工作组名', 112, 28, 80)
GUISetOnEvent(-3, 'gui')
GUICtrlSetOnEvent($Button1, 'gui')
GUICtrlSetOnEvent($Button2, 'gui')
GUISetState(@SW_SHOW)
While 1
Sleep(100)
WEnd
Func gui()
Switch @GUI_CtrlId
Case -3
Exit
Case $Button1
$user = InputBox("xxx","请输入想要修改的计算机名:","","","-1","-1",default,default)
If @error =1 Then
Else
_ComputerName($user)
MsgBox(64,"当前计算机名",$user)
EndIf
Case $Button2
$user = InputBox("xxx","请输入想要修改的工作组名:","","","-1","-1",default,default)
If @error =1 Then
Else
_SetWorkGroup($user)
MsgBox(64,"当前工作组",$user)
EndIf
EndSwitch
EndFunc ;==>gui
Func _ComputerName($comname)
Local $hklm1 = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet"
Local $hklm2 = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001"
RegWrite($hklm1 & "\Control\ComputerName\ComputerName","ComputerName","REG_SZ",$comname)
RegWrite($hklm1 & "\Services\Tcpip\Parameters","NV Hostname","REG_SZ",$comname)
RegWrite($hklm1 & "\Services\Tcpip\Parameters","Hostname","REG_SZ",$comname)
RegWrite($hklm2 & "\Control\ComputerName\ComputerName","ComputerName","REG_SZ",$comname)
RegWrite($hklm2 & "\Services\Tcpip\Parameters","NV Hostname","REG_SZ",$comname)
RegWrite($hklm2 & "\Services\Tcpip\Parameters","Hostname","REG_SZ",$comname)
DllCall("Userenv.dll", "int", "RefreshPolicyEx", "int", 1, "int", 1)
EndFunc
Func _SetWorkGroup($WorkGroup)
;================================
;用法:_SetWorkGroup(工作组名称)
;注意:此函数需要WMI服务的支持。
;作者:Make By Sanhen
;================================
Local $objNetwork,$strComputer
$objNetwork = ObjCreate("WScript.Network")
$strComputer = $objNetwork.ComputerName
$objComputer = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\" & _
$strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" _
& $strComputer & "'")
Return $objComputer.JoinDomainOrWorkGroup($WorkGroup)
EndFunc