免重启修改计算机和工作组
本帖最后由 ceoguang 于 2013-2-14 12:35 编辑都论坛找的代码,整合了一下。{:face (245):} 现在才发觉发错地方了,请版主移贴。
经测试绝对有用,环境:win7 x64系统 修改计算机名后,共享文件夹后,在虚拟机(XP系统)里面,能正常访问共享的文件夹。(新计算机名)#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 修改注册表? 是提问还是分享~ 代码中有个刷新组策略的api,这个不错~ 不错,谢谢分享 這個方法該學習!
{:face (88):} 学习一下,谢谢分享!!! 感谢分享,学习来啦 本帖最后由 lin6051 于 2013-1-19 22:44 编辑
刷新api就不用重启?
这样改的,计算机名,实际是没改,重启才真的生效 向楼主学习.... 回复 9# lin6051
我win7_x64 xp都试了可以啊,朋友你把需要连接的电脑网卡禁用启用一下试试。 回复 10# 虫子樱桃
大神,你别逗我了。{:1_492:} 看看 学习一下 回复下看内容~~ 这个来观摩学习。