$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;
}
}
}
}
'@
$userId = (Get-Process -PID $pid).SessionID
echo $userID
$loggedOff = 0
foreach ($user in $userid){
do
{
$idle_time = [PInvoke.Win32.UserInput]::IdleTime
if (($loggedOff -eq 0) -And ($idle_time -gt $idle_timout))
{
logoff $user
$loggedOff = 1
}
if ($idle_time -lt $idle_timout)
{
$loggedOff = 0
}
}
while (1 -eq 1)
}
嘿,我想知道是否有人可以幫我用這個腳本。在給定的空閒時間後,我正在嘗試在會議室中註銷所有用戶。我想要做的是找到所有會話ID並註銷所有活動會話。我不擔心失去工作,因爲這些會議室電腦。我遇到的問題是,我可以獲取當前登錄用戶的會話ID,但不能登錄所有用戶。如果有人有任何見解,將不勝感激。註銷多個空閒用戶
AHHH我看到非常感謝你 – goldenwest