vb 怎么实现改计算机用户名呢。。做机房管理系统其它都实现了,就差这一个了。
以下是实现的代码部分Private Sub Command2_Click()
Dim Num
Num = Text1.Text
Dim Name
If Num < 10 Then
Name = "KS"
Else
If Num < 100 Then
Name = "KS"
Else
Name = "KS"
End If
End If
Set sh = CreateObject("WScript.Shell")
sh.RegWrite "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName", Name + Num, "REG_SZ"
sh.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname", Name + Num, "REG_SZ"
sh.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname", Name + Num, "REG_SZ"
Set sh = Nothing
Set oShell = Nothing
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("192.168.0." & Num)
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.0.1")
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway)
Dim dns
dns = Array("218.85.152.99", "218.85.157.99")
Err = objNetAdapter.SetDNSServerSearchOrder(dns)
Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer In colComputers
'ObjComputer.Rename("game" &Num)
Next
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetIPXVirtualNetworkNumber (Num)
End Sub