2012-03-08 11 views
-1

私は、テキストファイル(C:\ textfile.txt)の内容をとり、Windowsイベントログに書き込むvbスクリプトを作成しました。私はC:\ textfile.txtからテキストを "プル"する変数 "strContents"の問題があります。誰もこの変数を書く方法を知っていますか?vbスクリプト内の変数

ありがとうございます。

CONST INFORMATION = 4 
    Const ForReading = 1 

    Set WshShell = WScript.CreateObject("WScript.Shell") 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objFile = objFSO.OpenTextFile("C:\textfile.txt", ForReading) 
     strContents = objFile.ReadAll 
    objFile.Close 


    wscript.echo strContents 
    strCommand = "eventcreate /T Information /ID 100 /L Application /SO     eventlog /D " "strContents" 
    WshShell.Run strcommand 
+0

prevous投稿で[VBS]を除外してください。 – trancer

+0

'[vbs]'とは何ですか?そしてなぜあなたは変数に代入できませんか?あなたが知っている、 'strContents = ...' –

答えて

2
strCommand = "eventcreate /T Information /ID 100 /L Application /SO eventlog /D """ & strContents & """" 
'                    ^^   ^^ 
' This becomes one double quote -------------------------------------------------+ |    | | 
' This is the string concatenation operator ----------------------------------------+    | | 
' This is the string concatenation operator ------------------------------------------------------+ | 
' This becomes one double quote ---------------------------------------------------------------------+ 

' Another way to execute "command-line" commands 
' that displays errors and output of the command 

dim WSE 
set WSE = WshShell.Exec(strCommand) 
WScript.Echo "======== STDERR ========" 
do until WSE.StdErr.AtEndOfStream 
    WScript.Echo WSE.StdErr.ReadLine 
loop 
WScript.Echo "======== STDOUT ========" 
do until WSE.StdOut.AtEndOfStream 
    WScript.Echo WSE.StdOut.ReadLine 
loop 
+0

もう一度、私は自分のコードでchengedしているが、それはテキストから値を書き込みません、これだけイベントログに書き込まれます:strContents – trancer

+0

こんにちは、私は自分のコードでchenged strContents – trancer

+0

'wscript.echo strCommand'を実行したときに表示されるものを投稿できますか?私は '/ D'パラメタの後ろの文字列を二重引用符で囲むべきだと思っています(編集済みの解答を参照) –

関連する問題