0

좋아요. 그래서 안개가있는 PC를 이미징하는 중입니다. 내 상사는 모든 것을 수동으로 설정하는 사람입니다. 프린터 서버를 사용하여 프린터를 관리하지 못하게 할 것입니다 ...VBS의 목록에서 IP 주소를 설정하십시오.

어쨌든 긴 이야기를 짧게하기 위해 나는 많은 것을 작성하여 큰 발전을 이루었습니다. 프린터 설치 스크립트 및 몇 가지 다른 작은 모니터링 및 기타 스크립트.

이제 정상적인 AD \ DHCP ezmode없이 정적으로 설정해야하는 IP 주소를 설정합니다.

그래서 저는 Frankensteined와 함께이 새로운 스크립트에 대한 도움을 받기를 희망했습니다.

이 스크립트

  1. 그것은 (대부분 작업) 네트워크 공유
  2. 구문 분석 ComputerList.csv에 (워킹!)
  3. 열기 Computerlist.csv에서 실행있어 호스트 이름을 읽기 "해야"을 찾고 호스트 이름 (대개는 작동하지만 대소 문자는 구분합니다.)
  4. 호스트 이름에 대해 나열된 정보를 가져 와서 변수를 설정합니다 (끌어 올 때 풀림).
  5. 이러한 변수를 사용하여 네트워크 연결을 구성합니다. (위의 # 4 때문에 문제가 있음)

나는 실제로 이것을하기 위해 이미 구축 된 스크립트를 Google 검색 할 수 없다는 것에 놀랐다.

여기는 내가 지금까지 함께 자갈을 쌌어 꽤 가까운 것 같지만 뭔가 잘못 놓치고 그냥 그것을 밖으로 정렬 할 수 없습니다.

option explicit 

Dim WshShell 
Dim ObjShell 
Dim objSysInfo 
Dim strComputerName 
Dim strFile 

Set WshShell = WScript.CreateObject("WScript.Shell") 
If WScript.Arguments.length = 0 Then 
Set ObjShell = CreateObject("Shell.Application") 
ObjShell.ShellExecute "wscript.exe", """" & _ 
WScript.ScriptFullName & """" &_ 
" RunAsAdministrator", , "runas", 1 
Else 
end if 

'* Pulls Computer name and sets it to variable 
Set objSysInfo = CreateObject("WinNTSystemInfo") 
strComputerName = objSysInfo.ComputerName 

'* Loop through CSV file, read entries, store them in an array 
dim CONNECTION : set CONNECTION = CreateObject("ADODB.CONNECTION") 
dim RECORDSET : set RECORDSET = CreateObject("ADODB.RECORDSET") 

CONNECTION.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\carmichaels\e\PCSetup\IPchanger\;Extended Properties=""text;HDR=YES;FMT=Delimited""" 

RECORDSET.Open "SELECT * FROM ComputerList.csv WHERE ComputerName = '" & strComputerName & "'", CONNECTION, 3, 3 

' //// For testing \\\\ 
WScript.Echo RECORDSET.Source 
' \\\\ For testing //// 

if RECORDSET.EOF then 
    WScript.Echo "Record not found" 
    WScript.Quit 
else 
    dim strIPAddress : strIPAddress = RECORDSET("IPAddress") & "" 
    dim strSubnetMask : strSubnetMask = RECORDSET("SubnetMask") & "" 
    dim strGateway : strGateway = RECORDSET("Gateway") & "" 
    dim intGatewayMetric : intGatewayMetric = 1 
    dim strDns1 : strDns1 = RECORDSET("Dns1") & "" 
    dim strDns2 : strDns2 = RECORDSET("Dns2") & "" 
    dim strDns3 : strDns3 = RECORDSET("Dns3") & "" 
    WScript.Echo strIPAddress 
end if 

'* Set IP address information stored in variables 
Set objShell = WScript.CreateObject("Wscript.Shell") 
objShell.Run "netsh interface ip set address name=""Local Area Connection"" static " & strIPAddress & " " & strSubnetMask & " " & strGateway & " " & intGatewayMetric, 0, True 
objShell.Run "netsh interface ip set dns name=""Local Area Connection"" static "& strDns1, 0, True 
objShell.Run "netsh interface ip add dns name=""Local Area Connection"" addr="& strDns2, 0, True 
objShell.Run "netsh interface ip add dns name=""Local Area Connection"" addr="& strDns3, 0, True 
Set objShell = Nothing 

내 문제는 내가이 스크립트를 실행할 때, 그것은 선 (28) CHR 1 (32 비트 시스템에서) 파일을 열 수 없습니다 주장이다. 그것을 통해 실행

그리고 64 비트 시스템에

가 ([IPchanger.vbs이 \의 % windir % \ SysWOW64와 \에서 cscript \ 서버 \ 공유 \ 폴더 \ 폴더] 난이 (가) 박쥐에 다음과 같이 실행)하지만, IP 주소에 점이 누락되었습니다. 전의. 10.1.0.57은 내 테스트 창에서 10.1057로 나타나며 파일이 열려 있거나 잠겨 있다고 주장하여 다시 실행되지 않습니다.

여기 라인 (28) 저를 들어, CSV는

ComputerName,IPAddress,SubnetMask,Gateway,Dns1,Dns2,Dns3 
CLONE2,10.1.0.57,255.255.255.0,10.1.0.1,10.1.0.18,10.1.0.13,10.1.0.12 

답변

0

그나마 당신의 파일 열기 오류에 대해 알고 파일입니다입니다

Set objShell = WScript.CreateObject("Wscript.Shell") 

그러나 제트 OLEDB 텍스트 필터를 사용하여 점으로 문제를 방지하기 위해, csv에 대한 Schema.ini 파일을 정의해야합니다. http://msdn.microsoft.com/en-us/library/windows/desktop/ms709353%28v=vs.85%29.aspx

제트는 IP가 10 진수가 아닌 텍스트 인 것으로 생각합니다.