本文介绍了在PowerShell中使用Stop-Process关闭特定网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人知道关闭用户在Google Chrome中打开的特定网站的方法?

I was wondering if anyone is aware of a way to close a specific website that the user has open in Google Chrome?

截至目前,我已经在Google Chrome浏览器中打开了用户输入的网站.该网站已分配给$ question变量,您将在下面看到该变量:

As of right now, I have Google Chrome opening up to a website that the user types in. The site is assigned to the $question variable that you will see below:

$question2 = Read-Host "Would you like to copy $question back to the server?"
if( ($question2 -eq 'yes') -or ($question2 -eq 'YES') -or ($question2 -eq 'Yes') -or ($question2 -eq 'Ye') -or ($question2 -eq 'Y') -or ($question2 -eq 'y') ) {
    start chrome.exe http://$question.website.org/
}

我想知道Chrome打开该网站后是否有办法也可以将其关闭.

I am wondering if there is a way after Chrome opens to that website, that I can also close it as well.

我知道

但这将同时关闭Chrome.我正在寻找一种方法来仅关闭我为他们打开的网站.

but that will close Chrome all together. I am looking for a way to only close the website that I opened up for them.

任何建议都将不胜感激.

Any suggestions are greatly appreciated.

预先感谢!

推荐答案

我认为非常困难.似乎Chrome启动时会产生各种其他过程,最终成为Windows/标签页,而您实际启动的过程只会助长此过程,然后退出.我认为可能有可能迫使它在新窗口中打开并跟踪该程序的PID,但是迅速返回的PID消失了.

Very difficult I believe. It seems that when Chrome starts it spawns various other process that end up being the windows/tabs and the process that you actually start only facilitates this and then exits. I thought it might be possible to force it to open in a new window and track the PID of that program, but the PID that gets returned rapidly disappears.

我还认为,可以查看ProcessStartInfo信息以查看是否可以传递任何参数,以供以后查询,但是再次启动该过程时,它需要执行的操作随后消失了,并且这些参数不再存在.不会传递给生成的进程.

I also thought it might be possible to look at the ProcessStartInfo information to see if you could pass any arguments through that you can later query, but again when you launch the process it does what it needs to then disappears and the arguments aren't passed to the spawned processes.

对于它的价值,这是我走了多远:

For what it's worth, this is how far I got:

[PS] 118# $a = new-object system.diagnostics.process
[PS] 119# $a.startinfo.filename = "C:\program files (x86)\Google\chrome\application\chrome.exe"
[PS] 120# $a.startinfo.arguments = "--new-window http://google.com"
[PS] 121# $a.startinfo.useshellexecute = $false
[PS] 122# $a.startinfo.verb = "test"
[PS] 123# $a.start()
True
[PS] 124# $a

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
              0        0          0     0     0.08   7332


[PS] 125# get-process | ? {$_.id -eq 7332}
[PS] 126# get-process | ? {$_.name -eq 'chrome'} | % {$_.startinfo.arguments}











[PS] 127#

尽管这样做确实使用 http://google.com 创建了一个新窗口,但您可以看到返回的7332不存在,并且其他任何chrome进程的 StartInfo.Arguments 为空

Although this did create a new window with http://google.com, as you can see the process that was returned, 7332, doesn't exist and the StartInfo.Arguments of any other chrome processes are blank

除了无法正常工作外,您还可以使用简单的正则表达式大大简化您的回答逻辑:是/否:

As an aside to not getting this working, you can vastly simplify your answer logic for yes/no by using a simple regular expression:

($question2 -imatch "^y(es)?$")
($question2 -imatch "^no?$")

证明:

[PS] 404> $("y" -imatch "y(es)?$")
True
[PS] 405> $("YES" -imatch "y(es)?$")
True
[PS] 406> $("N" -imatch "^no?$")
True
[PS] 407> $("nn" -imatch "^no?$")
False

这篇关于在PowerShell中使用Stop-Process关闭特定网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 00:46