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