【发布时间】:2013-10-09 13:38:21
【问题描述】:
好的,我正在使用 Fog 对一堆 PC 进行成像。我的老板是一个手动设置一切的坚持者,他甚至不让我使用打印服务器来管理打印机......
总之,长话短说,我通过编写一堆打印机安装脚本和一些其他小型监控和其他脚本取得了长足的进步。
所以现在归结为设置 IP 地址,通常必须将其设置为静态,而不使用正常的 AD\DHCP ezmode。
所以我希望能就我一起编写的这个新剧本获得一些帮助。
这个脚本“应该”
- 读取运行它的主机名(正在运行!)
- 在网络共享上打开 Computerlist.csv(大部分工作)
- 解析 ComputerList.csv,查找主机名(通常有效,但区分大小写)
- 获取列出的主机名信息,并设置变量(拉动时会松开 .'s)
- 使用这些变量来配置网络连接。 (因为上面的#4有问题)
我真的很惊讶我无法在谷歌上搜索一个已经为此而构建的脚本。
这是我到目前为止拼凑起来的,看起来很接近,但我错过了一些错误,我无法解决。
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 行第 1 行无法打开文件(在 32 位机器上)。
在 64 位机器上,(我在 .bat [%windir%\SysWoW64\cscript \server\share\folder\folder\IPchanger.vbs] 中使用以下内容运行它)它贯穿但IP地址缺少点。前任。 10.1.0.57 在我的测试窗口中显示为 10.1057,并且将无法再次运行声称文件已打开或锁定。
这是 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
【问题讨论】:
标签: networking file-io vbscript setup-deployment static-ip-address