找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 16924|回复: 4

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

[复制链接]
发表于 2014-2-23 20:14:30 | 显示全部楼层 |阅读模式
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
发表于 2014-2-23 21:59:24 | 显示全部楼层
进程id=pid
窗口句柄 一般才简称句柄。
 楼主| 发表于 2014-2-24 08:56:37 | 显示全部楼层
回复 2# PowerShell


    由此可见,你没有理解英文原文的标题 Keeping a Handle to a Process
 楼主| 发表于 2014-2-24 08:57:59 | 显示全部楼层
回复 2# PowerShell


    不只是窗口句柄,文件句柄也简称句柄,句柄多了去了啊啊啊啊啊。
发表于 2014-2-24 18:51:02 | 显示全部楼层
嗯,你说的对
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-16 22:03 , Processed in 0.018596 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表