我创建了一个vb脚本,它接受文本文件(C:\ textfile.txt)的内容并将其写入Windows事件日志。我有一个变量“strContents”的问题,它假设从C:\ textfile.txt“拉”文本有谁知道如何写这个变量?
非常感谢。
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 :(得分: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