【问题标题】:Use Sendkeys to write variables into file使用 Sendkeys 将变量写入文件
【发布时间】:2013-11-26 13:54:06
【问题描述】:

我正在尝试使用 vbs 在输入框中捕获 ID,然后将其输入到打开的文件中。我只学会了如何为这个特定的项目编写 vbs 脚本,所以下面写的可能不是 kosher。我也不确定使用 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}"

【问题讨论】:

    标签: vbscript sendkeys inputbox


    【解决方案1】:

    像瘟疫一样避免SendKeys。它很少是做某事的最佳方式。您只需要使用 FileSystem 对象:

    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
    

    【讨论】:

      猜你喜欢
      • 2013-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-29
      • 1970-01-01
      • 2020-11-04
      • 2015-06-06
      • 2013-10-03
      相关资源
      最近更新 更多