我想知道是否还有使用PowerShell识别锁定屏幕并强制注销?我在下面的脚本工作,但不是在屏幕锁定时。
情况是我们有几台会议计算机,用户忘记注销,我想在这些机器上本地运行这些脚本,以检查空闲时间并注销空闲用户。任何帮助,将不胜感激。我的脚本如下。
$idle_timout = New-TimeSpan -minutes 1
Add-Type @'
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace PInvoke.Win32 {
public static class UserInput {
[DllImport("user32.dll", SetLastError=false)]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
[StructLayout(LayoutKind.Sequential)]
private struct LASTINPUTINFO {
public uint cbSize;
public int dwTime;
}
public static DateTime LastInput {
get {
DateTime bootTime = DateTime.UtcNow.AddMilliseconds(-Environment.TickCount);
DateTime lastInput = bootTime.AddMilliseconds(LastInputTicks);
return lastInput;
}
}
public static TimeSpan IdleTime {
get {
return DateTime.UtcNow.Subtract(LastInput);
}
}
public static int LastInputTicks {
get {
LASTINPUTINFO lii = new LASTINPUTINFO();
lii.cbSize = (uint)Marshal.SizeOf(typeof(LASTINPUTINFO));
GetLastInputInfo(ref lii);
return lii.dwTime;
}
}
}
}
'@
$loggedOff = 0
do
{
$idle_time = [PInvoke.Win32.UserInput]::IdleTime
if (($loggedOff -eq 0) -And ($idle_time -gt $idle_timout))
{
shutdown.exe -l
$loggedOff = 1
}
if ($idle_time -lt $idle_timout)
{
$loggedOff = 0
}
}
while (1 -eq 1)