简体   繁体   English

如何根据对MessageBox的响应阻止用户注销或使用Powershell锁定工作站?

[英]How can I stop a user from logging out or locking a workstation using Powershell based on the response to a MessageBox?

I am trying to create a Powershell script that would pop up a message box whenever a user logs in, logs out, shuts down, or locks their workstation. 我正在尝试创建一个Powershell脚本,该脚本将在用户登录,注销,关闭或锁定其工作站时弹出一个消息框。 Based on the response, I want to allow the users action to continue, or interrupt the users action. 根据响应,我希望允许用户继续操作或中断用户操作。 This is an example of what I have so far: 这是到目前为止我所拥有的一个例子:

$msgBoxInput = [System.Windows.MessageBox]::Show('Have you clocked in/out?','Reminder','YesNo','Error')

switch  ($msgBoxInput) {

'Yes' {

## Continue with user action (ie. lock computer, logout, shutdown)

}

'No' {

## Stop user action (ie. lock computer, logout, shutdown, but not login action)

## Open clock in/out web page
[Diagnostics.Process]::Start('chrome.exe', 'https://url.to.web page')

}

}

Thanks in advance for any help you can provide! 预先感谢您提供的任何帮助!

You have to trap for each event type, interrupt it and have a scheduled task to fire your script actions or use a WMI event watcher for similar effort. 您必须捕获每种事件类型,将其中断,并安排一个计划任务来激发您的脚本操作或使用WMI事件观察器进行类似的工作。

See this discussion on the similar topic, it's of course talking shutdowns, but the same type of approach is needed for the two you are after. 看到关于类似主题的讨论,这当然是关闭,但是您要使用的两种方法都需要使用相同类型的方法。

PowerShell window preventing shutdown 防止关机的PowerShell窗口

...it looks like you can set up a Event watcher using Register-ObjectEvent using [microsoft.win32.systemevents] and watching for either SessionEnding or SessionEnded. ...看起来您可以使用[microsoft.win32.systemevents]使用Register-ObjectEvent设置事件观察程序,并监视SessionEnding或SessionEnded。 I haven't had time to test this out, but you could look at using something like this: $sysevent = [microsoft.win32.systemevents] Register-ObjectEvent -InputObject $sysevent -EventName "SessionEnding" -Action {"Shutdown/Logoff detected.";Get-Process -Name Powershell | 我还没有时间进行测试,但是您可以使用以下代码:$ sysevent = [microsoft.win32.systemevents] Register-ObjectEvent -InputObject $ sysevent -EventName“ SessionEnding” -Action {“关机/注销检测到。”; Get-Process -Name Powershell | Stop-Process -Force} 停止过程-强制}

https://serverfault.com/questions/379830/powershell-window-preventing-shutdown https://serverfault.com/questions/379830/powershell-window-preventing-shutdown

Remember, one can just hard shut down the system just by hitting the power button or pulling the cord. 请记住,只要按一下电源按钮或拉电源线,就可以硬关闭系统。 The is no software approach to stop that. 没有阻止这种情况的软件方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 SSH 远程解锁 Windows 工作站? - How can I remotely unlock a Windows workstation using SSH? 如何使用PowerShell在IIS中停止和启动各个网站? - How can I stop and start individual websites in IIS using PowerShell? 阻止用户使用 PowerShell 打开已经存在的程序 - Stop user from opening an already program using PowerShell 如何停止Windows Server锁定文件? - How to stop Windows server from locking a file? 如何过滤掉 powershell 中的信息? - How can i filter out information in powershell? Windows powershell 使用 Ansible 的消息框 - Windows powershell messagebox using Ansible 如何添加基于时间的限制以防止Windows用户登录? - How to add time based restrictions to prevent a Windows user from logging in? 防止Windows工作站(桌面)在运行WPF程序时锁定 - Prevent Windows workstation (desktop) from locking while running a WPF program 如何从SYSTEM帐户向登录的用户显示MessageBox? - How to display a MessageBox to the logged on user from SYSTEM account? 如何使用 powershell 在本地用户上设置“环境”>“登录时启动以下程序”属性? - How can I set the “Environment” > “Start the following program at logon” property on a local user using powershell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM