Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.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
Google chrome 使用PowerShell中的停止进程关闭特定网站_Google Chrome_Powershell - Fatal编程技术网

Google chrome 使用PowerShell中的停止进程关闭特定网站

Google chrome 使用PowerShell中的停止进程关闭特定网站,google-chrome,powershell,Google Chrome,Powershell,我想知道是否有人知道如何关闭用户在谷歌浏览器中打开的特定网站 到目前为止,我已经让谷歌浏览器打开了一个用户输入的网站。该站点已分配给$QUISE变量,您将在下面看到该变量: $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

我想知道是否有人知道如何关闭用户在谷歌浏览器中打开的特定网站

到目前为止,我已经让谷歌浏览器打开了一个用户输入的网站。该站点已分配给$QUISE变量,您将在下面看到该变量:

$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打开该网站后,是否有一种方法,我也可以关闭它

我知道

停止进程-进程名称

但这将使Chrome全部关闭。我正在寻找一种方法,只关闭我为他们打开的网站

如有任何建议,我们将不胜感激


提前谢谢

我相信这很难。似乎当Chrome启动时,它会产生各种其他进程,最终成为窗口/选项卡,而您实际启动的进程只会促进这一点,然后退出。我认为可以强制它在一个新窗口中打开并跟踪程序的PID,但是返回的PID很快就消失了

我还认为可以查看ProcessStartInfo信息,看看是否可以传递任何参数,以便以后查询,但是当启动流程时,它会执行需要执行的操作,然后消失,参数不会传递给派生的流程

值得一提的是,我已经走了这么远:

[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#
虽然这确实创建了一个新窗口,但正如您所看到的,返回的进程7332不存在,并且任何其他chrome进程的
StartInfo.Arguments
为空

除此之外,您还可以通过使用一个简单的正则表达式大大简化“是/否”的回答逻辑:

($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