基于PXE启动的WINDOWS 2000/XP的多播克隆(4)
'主程序
Sub Main()
Dim wjmc As String, address As String, SKeyVal As String, SKeyVal1 As Long, SS As String
Dim ComputerName As String, MacAddress As String
Dim lpName As String, Vname As String, S1 As String
Dim i As Integer, bj As Integer, Idx As Long, idx1 As Long
Dim wsversion As Long, hKey As Long, hKey1 As Long,
Dim lenData As Long, typeData As Long
Dim ret As Long, ret1 As Long, ret2 As Long, ret3 As Long
wjmc = App.Path + "\netname.dat"
If Dir(wjmc) = "" Then End
wsversion = GetVersion()
address = GetMACAddress() ’获取MAC地址
Open wjmc For Input As #1 ’打开MAC——计算机名映射表文件
Do While Not EOF(1) ' 循环至文件尾。
Input #1, ComputerName, MacAddress ' 将数据读入两个变量。
ComputerName = UCase(ComputerName)
MacAddress = UCase(MacAddress)
If address = MacAddress Then
i = SetComputerName(ComputerName) ’修改NetBIOS计算机名(Computername)
If i = 0 Then
MsgBox "设置计算机名失败!", vbOKOnly
End If
If (wsversion And &H80000000) = 0 Then
ret = RegCreateKey(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\ _
Tcpip\Parameters", hKey)
If ret = 0 Then
RegSetValueEx hKey, "NV Hostname", 0, REG_SZ, ByVal ComputerName, _
Len(ComputerName) + 1 ’修改DNS主机名(Hostname)
End If
RegCloseKey hKey
'下面这段程序用于检测是否安装过五笔字型FOR 2K或极品五笔,如果安装过,在输入法面板中恢复这两种输入法的显示。
ret = RegOpenKey(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\ _
Keyboard Layouts", hKey)
If ret = 0 Then
Idx = 0
lpName = String(9, Chr(0))
Do
ret1 = RegEnumKey(hKey, Idx, lpName, Len(lpName))
If ret1 = 0 Then
SS = UCase(Left(lpName, 8))
If SS = "E0100804" Or SS = "E0200804" Then
If SS = "E0100804" Then bj = 1 Else bj = 2
ret2 = RegOpenKey(HKEY_CURRENT_USER, "Keyboard Layout\Preload", hKey1)
If ret2 = 0 Then
idx1 = 1
Vname = idx1
Do
ret3 = RegQueryValueEx(hKey1, idx1, 0, typeData, _
ByVal vbNullString, lenData)
If ret3 = 0 Then
S1 = String(lenData, Chr(0))
ret3 = RegQueryValueEx(hKey1, Vname, 0, typeData, ByVal S1, lenData)
S1 = Left(S1, InStr(S1, Chr(0)) - 1)
If UCase(Trim(S1)) = "E0100804" Or UCase(Trim(S1)) = "E0200804" Then
Exit Do
End If
End If
idx1 = idx1 + 1
Vname = idx1
Loop Until ret3 <> 0
If ret3 <> 0 Then
Vname = idx1 - 1
If bj = 1 Then
RegSetValueEx hKey1, Vname, 0, REG_SZ, ByVal "E0100804", 9
Else
RegSetValueEx hKey1, Vname, 0, REG_SZ, ByVal "E0200804", 9
End If
Else
Exit Do
End If
End If
End If
End If
Idx = Idx + 1
Loop Until ret1 <> 0
End If
RegCloseKey hKey
ret = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\ _
CurrentVersion\Winlogon", hKey)
If ret = 0 Then
'下面键值的设置是:自动登录
SKeyVal = "1"
RegSetValueEx hKey,"AutoAdminLogon",0,REG_SZ,ByVal SKeyVal,Len(SKeyVal)+1
'下面键值的设置是:默认域名
SKeyVal = ComputerName
RegSetValueEx hKey,"DefaultDomainName",0,REG_SZ,ByVal SKeyVal,Len(SKeyVal)+1
'下面键值的设置是:默认用户名
SKeyVal = "administrator"
RegSetValueEx hKey,"DefaultUserName",0,REG_SZ,ByVal SKeyVal,Len(SKeyVal)+1
'下面键值的设置是:登录密码为空
SKeyVal = ""
RegSetValueEx hKey,"DefaultPassword",0,REG_SZ,ByVal SKeyVal,Len(SKeyVal)+1
'下面键值的设置是:登录使用欢迎屏幕(适用于Windows XP)
SKeyVal1 = &H1
RegSetValueEx hKey, "LogonType", 0, REG_DWORD, ByVal SKeyVal, 4
'下面键值的设置是:使用快速用户切换(适用于Windows XP)
SKeyVal1 = &H1
RegSetValueEx hKey, "AllowMultipleTSSessions", 0, REG_DWORD, ByVal SKeyVal, 4
End If
RegCloseKey hKey
End If
Exit Do
End If
Loop
Close #1
Kill wjmc
AdjustToken
ret = ExitWindowsEx(EWX_REBOOT Or EWX_FORCE, 0) '重新启动计算机
End Sub
-(全文完)-
本文地址:http://com.8s8s.com/it/it36949.htm