mirror of
https://github.com/freedbygrace/WindowsNotifications.git
synced 2026-07-26 12:08:14 +00:00
Add PowerShell cmdlets and update project structure
This commit is contained in:
@@ -1,49 +1,24 @@
|
||||
# Example: Simple Notification
|
||||
# This script demonstrates how to show a simple notification
|
||||
|
||||
# Load the WindowsNotifications assembly
|
||||
# Import the module
|
||||
$modulePath = Join-Path -Path $PSScriptRoot -ChildPath "..\PowerShell\WindowsNotifications.psd1"
|
||||
Import-Module $modulePath -Force
|
||||
|
||||
# Initialize the notification system
|
||||
$dllPath = Join-Path -Path $PSScriptRoot -ChildPath "..\WindowsNotifications\bin\Release\WindowsNotifications.dll"
|
||||
if (Test-Path $dllPath) {
|
||||
$bytes = [System.IO.File]::ReadAllBytes($dllPath)
|
||||
$assembly = [System.Reflection.Assembly]::Load($bytes)
|
||||
}
|
||||
else {
|
||||
Write-Error "WindowsNotifications.dll not found at $dllPath. Please build the solution first."
|
||||
exit
|
||||
}
|
||||
|
||||
# Create a notification manager
|
||||
$notificationManager = New-Object WindowsNotifications.NotificationManager
|
||||
|
||||
# Check if running as SYSTEM
|
||||
$isSystem = $notificationManager.IsRunningAsSystem()
|
||||
Write-Host "Running as SYSTEM: $isSystem"
|
||||
|
||||
# Get interactive user sessions
|
||||
$sessions = $notificationManager.GetInteractiveUserSessions()
|
||||
Write-Host "Interactive user sessions found: $($sessions.Count)"
|
||||
foreach ($session in $sessions) {
|
||||
Write-Host " $session"
|
||||
}
|
||||
Initialize-WindowsNotifications -DllPath $dllPath
|
||||
|
||||
# Show a simple notification
|
||||
Write-Host "Showing simple notification..."
|
||||
$result = $notificationManager.ShowSimpleNotification("Simple Notification", "This is a simple notification from PowerShell")
|
||||
$result = Show-Notification -Title "Simple Notification" -Message "This is a simple notification." -TimeoutInSeconds 10
|
||||
|
||||
# Display the result
|
||||
Write-Host "Notification displayed: $($result.Displayed)"
|
||||
Write-Host "Notification ID: $($result.NotificationId)"
|
||||
|
||||
# If the notification was displayed, wait for interaction
|
||||
if ($result.Displayed) {
|
||||
Write-Host "Waiting for user interaction..."
|
||||
$result = $notificationManager.WaitForNotification($result.NotificationId, 30000)
|
||||
|
||||
if ($result -ne $null) {
|
||||
Write-Host "Notification was activated: $($result.Activated)"
|
||||
Write-Host "Notification was dismissed: $($result.Dismissed)"
|
||||
}
|
||||
else {
|
||||
Write-Host "Timed out waiting for user interaction"
|
||||
}
|
||||
# If the notification was interacted with, show the details
|
||||
if ($result.Activated) {
|
||||
Write-Host "Notification was activated"
|
||||
} elseif ($result.Dismissed) {
|
||||
Write-Host "Notification was dismissed"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user