얻기 Provider Can't be found
오류. 이 스크립트는 csv 파일에 이전 이름과 새 이름을 모두 기록하면서 도메인의 워크 스테이션 이름을 바꾸는 것입니다.
업데이트 : 스크립트가 완료된 것으로 보이지만 .csv에 아무것도 쓰지 않습니다. 또한 컴퓨터 이름을 바꾸지 않습니다.
' RenamePC.vbs - Windows Logon Script.
' VBScript - Rename Workstation and Log Change
' Author Chris Collins
' Version 1 - July 2018
' ----------------------------------------------------------'
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Dim sCmpName,sUserType
Dim sUser,sPassword,sDomain,sOU
Dim strComputer,strSN,objWMIService,objBIOS,colSMBIOS,objShell
sUser = "administrator"
sPassword = "Password123"
sDomain = "Domain"
sOU = "OU=New Computers,DC=Domain,DC=k12,DC=az,DC=us"
' ************** Setup **************
' Folder where CSV File is located
' CSV file should have 1st field = oldname, 2nd field = newname with no header row
strCSVFolder = "E:\VBScripts\TestFolder\"
' CSV filename
strCSVFile = "computerrename.csv"
' Additional parameters to pass to NetDom command
strNetDomParams = " /userd:"+sUser+" /passwordd:"+sPassword+" /usero:"+sUser+" /passwordo:"+sPassword+" /force "
'************************************
'Part 1 - Acquire serial/service tag number
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
' move the objShell creation to here to ensure it get created
Set objShell = CreateObject("Shell.Application")
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
strSN = objSMBIOS.SerialNumber
If strSN <> "" Then exit For
Next
'Part 2 - Ask for Campus
sCmpName = InputBox("Enter the Campus the computer is on (BB, DO, HCS, THS, WJM):", "Campus Name")
If sCmpName = "" Then
Wscript.Echo "Exiting script."
Wscript.Quit
End If
'Part 3 - Ask for Type
sUserType = InputBox("Enter the User Type (CR, LAB, LIB, LP, NB, STAFF, TH). Insert other tags as well (ie -RF):", "User Type")
If sUserType = "" Then
Wscript.Echo "Exiting script."
Wscript.Quit
End If
'Part 4 - Assign computer name to serial/service tag number
Dim oWMI, oCmp, oOS, sReturn
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
For Each oCmp in oWMI.InstancesOf("Win32_ComputerSystem")
strNewName = oCmp.Rename (+sCmpName+"-"+sUserType+"-"+strSN)
If sReturn <> 0 Then
Wscript.Echo "Rename failed. Error = " & Err.Number & _
vbcrlf & "Exiting script."
Else
Wscript.Echo "Rename successful."
strNewName = oCmp.JoinDomainOrWorkgroup(sDomain, sPassword, _
sDomain & "\" & sUser, sOU, JOIN_DOMAIN+ACCT_CREATE)
If strNewName <> 0 Then
Wscript.Echo "Join domain failed. Error = " & Err.Number & _
vbcrlf & "Exiting script."
Else
Wscript.Echo "Join domain successful."
'Part 4 - Setup ADO Connection to CSV file
SET objShell = wscript.CREATEOBJECT("wscript.shell")
SET cn = CREATEOBJECT("ADODB.Connection")
SET rs = CREATEOBJECT("ADODB.Recordset")
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & strCSVFolder & ";" & _
"Extended Properties=""text;HDR=NO;FMT=Delimited"""
rs.Open "SELECT * FROM [" & strCSVFile & "]", _
cn, adOpenStatic, adLockOptimistic, adCmdText
DO until rs.eof
strOldName = rs(0)
strNewName = rs(1)
strCmd = "cmd.exe /C netdom renamecomputer " & strOldName & " /newname:" & strNewName & strNetDomParams
intReturn = objShell.Run(strCmd,intWindowStyle,blnWait)
IF intReturn = 0 THEN
wscript.echo "Renamed '" & strOldName & "' to '" & strNewName & "'"
ELSE
wscript.echo "Error renaming '" & strOldName & "' to '" & strNewName & "'"
END IF
rs.movenext
Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
err = objComputer.Rename(strNewName)
Next
For Each oOS in oWMI.InstancesOf("Win32_OperatingSystem")
sReturn = oOS.Reboot
Next
Loop
End If
'Step 5 - Reboot Computer
Wscript.Echo "Rebooting computer..."
Dim oShell
Set oShell = CreateObject("WScript.Shell")
'restart, wait 0 seconds, force running apps to close
oShell.Run "%comspec% /c shutdown /r /t 0 /f", , TRUE
End If
Next
흥미롭게도 32 비트 cscript에서 스크립트를 호출하면 작동합니까? 64 비트 Windows를 사용한다고 가정하십니까? 예 : C : \ Windows \ SysWOW64 \ cscript.exe script.vbs
—
HelpingHand
예, 64 비트 시스템을 사용하고 있습니다. 어떻게 해야할지 모르겠습니다.
—
Christopher Collins
관리자 명령 프롬프트를 열면 다음을 실행할 수 있습니다.
—
HelpingHand
C:\Windows\SysWOW64\cscript.exe C:\pathto\RenamePC.vbs
나중에 오류없이 실행되었지만 CSV에 아무것도 기록하지 않았습니다.
—
Christopher Collins
Ok 디버깅을 실행했지만 아무것도 얻지 못했습니다. 스크립트가 완료된 것 같지만 .csv에 아무 것도 쓰지 않습니다. 원본 코드 업데이트
—
Christopher Collins