Vbscript 使用Sendkeys将变量写入文件

Vbscript 使用Sendkeys将变量写入文件,vbscript,sendkeys,inputbox,Vbscript,Sendkeys,Inputbox,我正在尝试使用vbs捕获输入框中的ID,然后将其输入到打开的文件中。我只学会了如何为这个特定的项目编写vbs脚本,所以下面所写的内容可能不符合犹太教义。我也不确定使用Sendkeys是否可行,主要是因为它还没有起作用。谢谢你的指点 Dim wshShell, ID ID=inputBox("Please Enter the ID") CreateObject("WScript.Shell").Run("file.sps") Set WshShell = WScript.CreateObjec

我正在尝试使用vbs捕获输入框中的ID,然后将其输入到打开的文件中。我只学会了如何为这个特定的项目编写vbs脚本,所以下面所写的内容可能不符合犹太教义。我也不确定使用Sendkeys是否可行,主要是因为它还没有起作用。谢谢你的指点

Dim wshShell, ID

ID=inputBox("Please Enter the ID")

CreateObject("WScript.Shell").Run("file.sps")
Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Sendkeys  "[the ID from above should go here]"
WshShell.Sendkeys "{Enter}"

避免像瘟疫一样发送密钥。。这很少是做某事的最佳方式。您只需要使用文件系统对象:

Option Explicit

Dim fso,file
Dim id

id = inputBox("Please Enter the ID")
Set fso = CreateObject("Scripting.FilesystemObject")

'open the file for appending (8) create it if it doesn't exist
Set file = fso.OpenTextFile("file.sps",8,True)

Call file.writeLine(id)
Call file.close

Set file = Nothing
Set fso = Nothing
WScript.Quit