简体   繁体   English

如何使用 VBScript 打开记事本并在其中粘贴当前日期?

[英]How to use VBScript to open notepad and paste current date in it?

How to use VBScript to open notepad and paste current date in it?如何使用 VBScript 打开记事本并在其中粘贴当前日期?

This is all I have for now:这就是我现在所拥有的:

Set WshShell = WScript.CreateObject("WScript.Shell")
Call WshShell.Run("%windir%\system32\notepad.exe")
Dim aDate
aDate = Date()
WScript.Sleep 2000

Now, how do I paste the date?现在,如何粘贴日期?

Use SendKeys to send keystrokes to the active window.使用SendKeys将击键发送到活动窗口。

Usage:用法:

WshShell.SendKeys aDate

You may need to ensure that the focus is in the window you want to send keystrokes to.您可能需要确保焦点位于要向其发送击键的窗口中。 For this, use AppActivate method.为此,请使用AppActivate方法。

Using window title in this case:在这种情况下使用窗口标题:

WshShell.AppActivate "Untitled - Notepad"

你也可以使用

WshShell.SendKeys "{F5}"

I know i am late, but try the following code, it works:我知道我迟到了,但试试下面的代码,它可以工作:

Set wshshell = wscript.CreateObject("WScript.Shell")
Wshshell.run "Notepad"
wscript.sleep 100
dim aDate
aDate = Date()
wscript.sleep 2000
wshshell.sendkeys aDate
wscript.sleep 1000

Make sure the extension of the file is ".vbs"确保文件的扩展名是“.vbs”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM