如何使用Powershell确定何时使用特定应用程序?

时间:2017-09-10 15:38:46

标签: powershell

我正在尝试在PowerShell中编写一个脚本,该脚本启动应用程序并在上次使用此应用程序时在弹出窗口中显示用户。好吧,为了启动应用程序,我只使用了一个简单的命令,这是有效的,但我不知道它是否长期有效:

start 'C:\Riot Games\League of Legends\LeagueClient.exe'

并在它启动后应用程序和弹出窗口应该告诉我,我上次启动应用程序的时间是什么时候。这是我现在的目标。

1 个答案:

答案 0 :(得分:2)

您可以使用

打开程序
start 'C:\Riot Games\League of Legends\LeagueClient.exe'

弹出像......

#First you want to set your variable for the date and time
#Get-ItemProperty is self explanatoy
#select-object gets the LastAccesTime property and -expand isolates that property in a string versus a table
$lastusetime = Get-ItemProperty "C:\Riot Games\League of Legends\LeagueClient.exe" | select-object -expandproperty LastAccessTime

#set the com object for a window and give it a variable
$wshell = New-Object -ComObject Wscript.Shell

#use that variable and the "Pop Up" property of windows shell to set the Windows details. VOID disables any outputs in the powershell window
[void]$wshell.Popup("Last Open $Lastusetime",0,"Program Details",0x1)

要获取有关Wscript.Shell对象的更多信息,您可以转到this link

可能有其他方法可以做到这一点,但这就是我选择这样做的方式。