1
我想從VBScript輸出到記事本/寫字板實時。什麼是最好的方法來做到這一點?我知道sendkeys,但它需要我解析輸入的特殊命令。VBScript到記事本/寫字板
我想從VBScript輸出到記事本/寫字板實時。什麼是最好的方法來做到這一點?我知道sendkeys,但它需要我解析輸入的特殊命令。VBScript到記事本/寫字板
的SendKeys是寫在實時第三方應用程序的唯一方法。爲什麼不使用CScript並將其寫入標準輸出?這就是它的意思。
' Force the script to run in the CScript engine
If LCase(Right(WScript.FullName, 11)) <> "cscript.exe" Then
strPath = WScript.ScriptFullName
strCommand = "%comspec% /k cscript " & Chr(34) & strPath & chr(34)
CreateObject("WScript.Shell").Run(strCommand)
WScript.Quit
End If
For i = 1 to 10
For j = 0 to 25
WScript.StdOut.WriteLine String(j, " ") & "."
WScript.Sleep 50
Next
For j = 24 to 1 Step - 1
WScript.StdOut.WriteLine String(j, " ") & "."
WScript.Sleep 50
Next
Next
試試這個
Const fsoForWriting = 2
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Open the text file
Dim objTextStream
Set objTextStream = objFSO.OpenTextFile("C:\SomeFile.txt", fsoForWriting, True)
'Display the contents of the text file
objTextStream.WriteLine "Hello, World!"
'Close the file and clean up
objTextStream.Close
Set objTextStream = Nothing
Set objFSO = Nothing
爲什麼不使用filesystemobject創建文本流? – Fionnuala 2012-02-22 00:10:43
解析特殊字符並不是真正的火箭科學。使用像Regex.Replace(myString,「([\ + \^\%\〜\ {\} \ [\] \(\)])」,「{$ 1}」)'這樣的正則表達式應該可以做到。也許你會想要替換'Tab'和'Newline'字符,這會變成像'Regex.Replace(myString,「\ t」,「{TAB}」)'和'Regex.Replace(myString,「 \ r \ n「,」{ENTER}「)'。這些是您必須替換的唯一字符,因爲所有其他特殊輸入都是鍵盤輸入,如「{SHIFT}」,「{F1}」等。 – AutomatedChaos 2012-02-23 06:45:47