[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[转载代码] [PowerShell每日技巧]保留指向进程的句柄(20140221)

When you launch an EXE file, PowerShell will happily start it, then continue and not care about it anymore:
PS C:\> notepad
PS C:\>


If you'd like to keep a handle to the process, for example to find out its process ID, or to be able to check back later how the process performs, or to kill it, use Start-Process and the –PassThru parameter. This returns a process object:
PS C:\> $process = Start-Process -FilePath notepad -PassThru
PS C:\> $process.Id
5936
PS C:\> 'You just launched process {0}.' -f $process.Id
You just launched process 5936.
PS C:\> 'CPU consumption in seconds so far: {0}.' -f $process.CPU
CPU consumption in seconds so far: 0.1092007.
PS C:\> $process.CloseMainWindow()
True
PS C:\>


http://powershell.com/cs/blogs/tips/archive/2014/02/21/keeping-a-handle-to-a-process.aspx

回复 2# PowerShell


    由此可见,你没有理解英文原文的标题 Keeping a Handle to a Process

TOP

回复 2# PowerShell


    不只是窗口句柄,文件句柄也简称句柄,句柄多了去了啊啊啊啊啊。

TOP

返回列表