הנה תוכנה קטנה ממש (GPT ּ ג'מיני), שרצה ברקע ושומרת שבעת עבודה על אוצריא - המסך לא יכבה.
היא נמצאת במגש, ואפשר בכל רגע נתון לכבות ולסגור אותה משם, או ממנהל המשימות.
בכבוד!
[image: 1768444936242-309e238d-1cb9-48eb-948e-ee02a085832f.jpg]
אוצריא - שומר מסך.exe
התוכנה מזהה אם אוצריא פתוח ברקע, אם כן - המסך לא נכבה בכלל, אם לא - המסך עובד כרגיל.
יש אפשרות להפעיל ולכבות את התוכנה, גם בלי לסגור אותה.
יש אפשרות שהתוכנה תפעל עם עליית המחשב - באופן אוטומטי.
יש בועת מידע אם התוכנה מופעלת/נכבית - בכדי שתדעו בדיוק מה הסטטוס שלה.
התוכנה רצה ברקע, ופועלת משורת המשימות.
אשמח להערות!
קוד פאוורשיל - למי שמעניין אותו איך זה עובד:
# 1. הגדרות וטעינת ספריות
$ErrorActionPreference = 'SilentlyContinue'
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
# מניעת הרצה כפולה
if ((Get-Process -Name ([System.Diagnostics.Process]::GetCurrentProcess().Name)).Count -gt 1) { exit }
# פונקציית המערכת למניעת שינה
$sig = '[DllImport("kernel32.dll")] public static extern uint SetThreadExecutionState(uint esFlags);'
$win32 = Add-Type -MemberDefinition $sig -Name "Win32Sleep" -Namespace "Win32" -PassThru
# משתני מצב
$script:ManualOverride = $true
$ExePath = [System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName
$RegPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
$AppName = "OtzariaNoSleep"
$FullTitle = "אוצריא - שומר מסך"
# 2. יצירת ה-Tray Icon
$notifyIcon = New-Object System.Windows.Forms.NotifyIcon
$notifyIcon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($ExePath)
$notifyIcon.Visible = $true
$notifyIcon.Text = $FullTitle
# 3. פונקציית עדכון מצב - שקטה לחלוטין
function Update-SleepState {
param($ForceOff = $false)
$IsRunning = Get-Process -Name "otzaria" -ErrorAction SilentlyContinue
if ($ForceOff -or (-not $script:ManualOverride) -or (-not $IsRunning)) {
[void][Win32.Win32Sleep]::SetThreadExecutionState([uint32]2147483648)
} else {
[void][Win32.Win32Sleep]::SetThreadExecutionState([uint32]2147483651)
}
}
# 4. תפריט קליק ימני - הודעות מפורשות לשינוי ידני
$contextMenu = New-Object System.Windows.Forms.ContextMenu
$toggleMenu = New-Object System.Windows.Forms.MenuItem("מניעת שינה פעילה", {
$script:ManualOverride = -not $script:ManualOverride
$this.Checked = $script:ManualOverride
Update-SleepState
if ($script:ManualOverride) {
$notifyIcon.ShowBalloonTip(3000, $FullTitle, "מניעת שינה הופעלה.", [System.Windows.Forms.ToolTipIcon]::Info)
} else {
$notifyIcon.ShowBalloonTip(3000, $FullTitle, "מניעת שינה כובתה - המחשב יחזור לישון.", [System.Windows.Forms.ToolTipIcon]::Warning)
}
})
$toggleMenu.Checked = $true
$startupMenu = New-Object System.Windows.Forms.MenuItem("הפעל עם עליית המחשב", {
if ($this.Checked) { Remove-ItemProperty $RegPath $AppName }
else { Set-ItemProperty $RegPath $AppName "`"$ExePath`"" }
$this.Checked = -not $this.Checked
})
$startupMenu.Checked = $null -ne (Get-ItemProperty $RegPath $AppName -ErrorAction SilentlyContinue)
$exitMenu = New-Object System.Windows.Forms.MenuItem("יציאה", {
Update-SleepState -ForceOff $true
$notifyIcon.Visible = $false
Stop-Process -Id $PID -Force
})
[void]$contextMenu.MenuItems.Add($toggleMenu)
[void]$contextMenu.MenuItems.Add($startupMenu)
[void]$contextMenu.MenuItems.Add("-")
[void]$contextMenu.MenuItems.Add($exitMenu)
$notifyIcon.ContextMenu = $contextMenu
# 5. טיימר בדיקה שקט
$timer = New-Object System.Windows.Forms.Timer -Property @{Interval = 10000}
$timer.Add_Tick({ Update-SleepState })
$timer.Start()
# 6. לוגיקת הודעת הפעלה - תיקון
# אם עברו יותר מ-60 שניות מאז שהווינדוס עלה, סימן שהפעלת את זה ידנית
$BootTime = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
$SecondsSinceBoot = (New-TimeSpan -Start $BootTime -End (Get-Date)).TotalSeconds
if ($SecondsSinceBoot -gt 60) {
$notifyIcon.ShowBalloonTip(3000, $FullTitle, "התוכנה הופעלה ומוכנה.", [System.Windows.Forms.ToolTipIcon]::Info)
}
Update-SleepState
[System.Windows.Forms.Application]::Run()