0

わかりましたので、Fog を使用して多数の PC をイメージングしています。私の上司は、すべてを手動で設定することに固執し、プリント サーバーを使用してプリンターを管理することさえ許可しません...

とにかく、長い話を手短に言うと、たくさんのプリンタ インストール スクリプトといくつかの小さな監視スクリプトとその他のスクリプトを書くことで、私は大きな進歩を遂げました。

IP アドレスの設定は、通常の AD\DHCP ezmode を使用せずに静的に設定する必要があります。

だから私は一緒にフランケンシュタインを作ったこの新しいスクリプトについて助けを得たいと思っていました.

このスクリプトは「すべき」

  1. 実行されているホスト名を読み取ります (動作中!)
  2. ネットワーク共有で Computerlist.csv を開きます (ほとんど動作しています)
  3. ComputerList.csv を解析し、ホスト名を探します (通常は機能しますが、大文字と小文字が区別されます)
  4. ホスト名にリストされている情報を取得し、変数を設定します(プルすると . が失われます)
  5. これらの変数を使用して、ネットワーク接続を構成します。(上記#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 chr 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
4

1 に答える 1

0

あなたのファイルオープンエラーについては知りません。私にとっては28行目です

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

ただし、ドットの問題を回避するには、Jet OLEDB テキスト フィルターを使用して、csv の Schema.ini ファイルを定義する必要があります。http://msdn.microsoft.com/en-us/library/windows/desktop/ms709353%28v=vs.85%29.aspxを参照してください。

Jet は、IP がテキストではなく 10 進数であると想定していると思います。

于 2013-10-14T16:15:35.777 に答える