2012-03-10 3 views
0

iniファイルの1行を編集しようとしています。 DeviceName = APPLEからDeviceName = "ユーザー入力"。私はインターネット上のビットとピースからほぼそこにそれを持っています。それは最終結果を除いて、私のファイルjwalk.iniはユーザ入力の後に正しいエントリであるが、iniファイルは.iniに改名され、iniの前にjwalkはない。私は何かを欠いているに違いない。ファイルjwalk.iniはすでに存在します。新しいユーザー入力でそれを編集し、同じ名前のファイルを残すだけです。スクリプトのヘルプにiniファイルの編集が必要

マイスクリプト:

Const ForReading = 1 
Const ForWriting = 2 
Const OpenAsASCII = 0 
Const CreateIfNotExist = True 

Set objFSO = CreateObject("Scripting.FileSystemObject") 
' Open existing file for read access. 
strInput = "c:\MyFolder\jwalk.ini" 
Set objInput = objFSO.OpenTextFile(strInput, ForReading) 

' Prompt for device name. 
strDeviceName = InputBox("Enter devicename", "JWalk PC Name or Session Name") 

' Specify the new file name. 
strOutput = "c:\MyFolder\" & strComputer & ".ini" 

' Create new file with write access. 
Set objOutput = objFSO.OpenTextFile(strOutput, _ 
ForWriting, CreateIfNotExist, OpenAsASCII) 

' Process input file. 
Do Until objInput.AtEndOfStream 
' Read next line of the input file. 
strLine = objInput.ReadLine 
' Search for line to be modified. 
' Make search case insensitive. 
If (InStr(LCase(strLine), "devicename=") > 0) Then 
' Replace the line. 
' You could also modify the line. 
strLine = "devicename=" & strDeviceName 
End If 
' Write line to the output file. 
objOutput.WriteLine strLine 
Loop 

' Clean up. 
objInput.Close 
objOutput.Close 

' Delete the original file. 
objFSO.DeleteFile(strInput) 

任意のアイデア?ありがとう。

答えて

1

あなたがOption Explicitを使用していただろう場合は、

strOutput = "c:\MyFolder\" & strComputer & ".ini" 

が未定義/初期化されていないstrComputer変数を使用していることを言われていると思います。

1

ここでは、VARとして「strComputer」を渡し、それが価値だ設定されることはありません:

' Specify the new file name. 
strOutput = "c:\MyFolder\" & strComputer & ".ini" 

コンピュータ名を取得しようとしている場合は、この検討することもでき:

' Specify the new file name. 
strOutput = "c:\MyFolder\" & GetComputerName() & ".ini" 

Function GetComputerName() 
    Dim ob 
    Set ob = Wscript.CreateObject("Wscript.Network") 
    GetComputerName = ob.ComputerName 
    Set ob = nothing 
End Function