Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 获取分钟数并使用SendKeys输出_Powershell_Sendkeys_Getdate - Fatal编程技术网

Powershell 获取分钟数并使用SendKeys输出

Powershell 获取分钟数并使用SendKeys输出,powershell,sendkeys,getdate,Powershell,Sendkeys,Getdate,这是我第一次编写脚本,我想从小做起。 我的目标很简单:获取当前时间(get Date-Format mm)并用SendKeys作为击键输出该2位数字 问题是,我不知道如何将2位数的输出转换为“SendKeys”输出的对象。不确定这里的完整要求是什么,但您可以将分钟发送到记事本,如下所示 Add-Type -AssemblyName microsoft.VisualBasic Add-Type -AssemblyName System.Windows.Forms $secs = Get-Date

这是我第一次编写脚本,我想从小做起。 我的目标很简单:获取当前时间(get Date-Format mm)并用SendKeys作为击键输出该2位数字


问题是,我不知道如何将2位数的输出转换为“SendKeys”输出的对象。

不确定这里的完整要求是什么,但您可以将分钟发送到记事本,如下所示

Add-Type -AssemblyName microsoft.VisualBasic
Add-Type -AssemblyName System.Windows.Forms
$secs = Get-Date -Format mm
notepad

start-sleep -Milliseconds 500

[Microsoft.VisualBasic.Interaction]::AppActivate("notepad")

[System.Windows.Forms.SendKeys]::SendWait($secs)

不确定这里的完整要求是什么,但您可以将会议记录发送到记事本,如下所示

Add-Type -AssemblyName microsoft.VisualBasic
Add-Type -AssemblyName System.Windows.Forms
$secs = Get-Date -Format mm
notepad

start-sleep -Milliseconds 500

[Microsoft.VisualBasic.Interaction]::AppActivate("notepad")

[System.Windows.Forms.SendKeys]::SendWait($secs)

首先使用
ToString()
方法将日期时间结果转换为字符串如果您在发送时遇到问题,下面是将其发送到记事本的完整示例:

## Find all Active Windows Titles
$windows=Get-Process | Where-Object {$_.MainWindowTitle -ne ""} | Select-Object MainWindowTitle
## Find Specific name 
$WindowTitle=($windows | ? {$_ -match "Notepad"} ).MainWindowTitle
## Add Type and Focus Activate the Window
$wshell = New-Object -ComObject wscript.shell
$wshell.AppActivate($WindowTitle)
## Send Keys
$wshell.SendKeys((Get-Date -Format mm).ToString())

首先使用
ToString()
方法将日期时间结果转换为字符串如果您在发送时遇到问题,下面是将其发送到记事本的完整示例:

## Find all Active Windows Titles
$windows=Get-Process | Where-Object {$_.MainWindowTitle -ne ""} | Select-Object MainWindowTitle
## Find Specific name 
$WindowTitle=($windows | ? {$_ -match "Notepad"} ).MainWindowTitle
## Add Type and Focus Activate the Window
$wshell = New-Object -ComObject wscript.shell
$wshell.AppActivate($WindowTitle)
## Send Keys
$wshell.SendKeys((Get-Date -Format mm).ToString())