Автор: Master_Alex
Дата сообщения: 27.03.2006 22:57
VelDmi
Ну а на скрипт центр заглянуть или погуглить?
Вот - гугл выдал:
[more]'Change computername.vbs
' Created by CrazyMatt
' The script changes both the local name and the name in AD
' netdom.exe must be in the same dir as the script (found on win2k3 srv resourcekit)
' The script uses "changename.xls" (in the same dir as script) where the old name is in Column 1 and the new in Colum 2
' Row 1 is used for description and shouldnt have any computernames
'
' The script first checks if the computer is reachable and then changes the name and reboots the computer.
'
' Last it writes to either Sucess.txt or Error.txt
sAdminName = InputBox("Is used to change the computername" & vbNewLine & vbNewLine & _
"Even if you have to specify an adminaccount here" & vbNewLine & _
"its important you are running the script with admin rights!!!" & vbNewLine & vbNewLine & _
"Enter an adminaccount with AD rights" & vbNewLine & "EG: user-adm",sAdminName)
If sAdminName = "" Then Wscript.Quit(1)
sAdminPwd = InputBox("Specify password" & vbNewLine & "", sAdminPwd)
If sAdminPwd = "" Then Wscript.Quit(1)
sReboot = MsgBox("Do you want the computer(s) to be restarted after the namechange?" &_
vbNewLine & "", vbYesNo)
sWaitTime = InputBox("Specify seconds to wait before scripts starts" & vbNewLine & "Default is 0", sWaitTime)
If sWaitTime = "" Then sWaitTime = 0
sSleepTime = sWaitTime * 1000
Const ForAppending = 8
Set oShell = CreateObject("WScript.Shell")
Set oNetwork = CreateObject("WScript.Network")
sSkriptPath=left(wscript.scriptfullname,len(wscript.scriptfullname)-len(wscript.scriptname))
Set oOldName = CreateObject("Scripting.Dictionary")
Set oNewName = CreateObject("Scripting.Dictionary")
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
(sSkriptPath & "changename.xls")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oSucessTextFile = oFSO.OpenTextFile _
(sSkriptPath & "sucess.txt", ForAppending, True)
Set oErrorTextFile = oFSO.OpenTextFile _
(sSkriptPath & "error.txt", ForAppending, True)
WScript.Sleep(sSleepTime)
'WScript.Echo "Waited for " & sWaitTime & " seconds. And " & sSleepTime 'Debugkod
'WScript.Echo sReboot & sPcRegKey 'Debugkod
i = 1
intRow = 2
on error resume next
Do Until objExcel.Cells(intRow,1).Value = ""
'wscript.echo introw
Set oOldName = objExcel.Cells(intRow,1)
Set oNewName = objExcel.Cells(intRow,2)
'wscript.echo oOldName & " will change name to " & oNewName 'Debugcode
WScript.Sleep(2000) 'Wits 2 sec for avoiding errors
'Checks if the computer is alive
Set oScriptExec = oShell.Exec("ping -n 2 -w 1000 " & oOldName)
strPingStdOut = LCase(oScriptExec.StdOut.ReadAll)
' Old pingstyle (for compability with pre win2k machines) could be be switched to win32 style ping if wanted
If InStr(strPingStdOut, "reply fr") Then
LoggedIn
Else
' WScript.Echo oOldName & ": Host unreachable" 'Debugkod
WriteError
End If
intRow = intRow + 1
Loop
objExcel.Quit
'==== Function Logged in check
'Checks if anyone is logged in to the puter (for deciding wich way the computer should be rebooted in)
Function Loggedin
on error resume next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& oOldName & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
IF IsNull(objComputer.UserName) then
' Wscript.Echo oOldName & " is alive and noone logged in!" 'Debugkod
RenameComp
RebootComp
WriteSucess
else
' Wscript.Echo oOldName & " is alive and " & objComputer.UserName & " is logged in." 'Debugkod
RenameComp
If sReboot = 6 Then
Set oScriptExec = oShell.Exec("shutdown -r -m \\" & oOldName & " -t 600 -f -c " & Chr(34) & "Your computer will now be restarted for a namechange, plz close all open files and save them"& Chr(34) )
End If
WriteSucess
end if
next
End Function
'============
'==== Function Write Sucess
function WriteSucess
oSucessTextFile.WriteLine(oOldName & " was sucessfully renamed to " & oNewName)
End Function
'============
'==== Function Write Error
function WriteError
oErrorTextFile.WriteLine(oOldName & " was not renamed to " & oNewName)
End Function
'============
'==== Function RenameComp
function RenameComp
'WScript.Echo "ReNameing.." 'Debugkod
Set oScriptExec = oShell.Exec("netdom renamecomputer " & oOldName & " /NewName:" & oNewName & " /UserD:<domain>\" & sAdminName & " /PasswordD:" & sAdminPwd & " /UserO:<domain>\" & sAdminName & " /PasswordO:" & sAdminPwd & " /Force")
' WScript.Echo "netdom renamecomputer " & oOldName & " /NewName:" & oNewName & " /UserD:<domain>\" & sAdminName & " /PasswordD:" & sAdminPwd & " /UserO:<domain>\" & sAdminName & " /PasswordO:" & sAdminPwd & " /Force"
End Function
'============
'==== Function RebootComp
function RebootComp
on error resume Next
If sReboot = 6 Then
WScript.Sleep(10000)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
oOldName & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
'err.clear ' Debugcode
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Reboot()
Next
End If
End Function
'============
objTextFile.Close
set i = Nothing
wscript.echo "Done!"[/more]