Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why not use simply displayswicth #1

Open
greenmerlin opened this issue Nov 17, 2024 · 0 comments
Open

Why not use simply displayswicth #1

greenmerlin opened this issue Nov 17, 2024 · 0 comments

Comments

@greenmerlin
Copy link

greenmerlin commented Nov 17, 2024

https://ss64.com/nt/displayswitch.html is implemented in windows since version 7.

Simply use that :
`

Log definition

function Write-Log {
param (
[Parameter(Mandatory=$true)]
[string]$Message,
[string]$LogFile = "C:\Logs\DisplaySwitch.log"
)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logMessage = "$timestamp - $Message"
Write-Output $logMessage
try {
Add-Content -Path $LogFile -Value $logMessage
} catch {
Write-Output "error wil writing in file : $LogFile"
}
}
function Switch-DisplayMode {
param (
[Parameter(Mandatory=$true)]
[ValidateSet("Internal", "Clone", "Extend", "External")]
[string]$Mode
)
$modeSwitch = @{
"Internal" = "/internal"
"Clone" = "/clone"
"Extend" = "/extend"
"External" = "/external"
}
$command = "displayswitch.exe"
$arguments = $modeSwitch[$Mode]
Write-Log -Message "Exécution de la commande : $command $arguments"
try {
Start-Process -FilePath $command -ArgumentList $arguments -NoNewWindow -Wait
Write-Log -Message "Changement d'affichage réussi en mode : $Mode"
} catch {
Write-Log -Message "Erreur lors de l'exécution de displayswitch.exe : $_"
}
}
#usage:
#Switch to clone
Switch-DisplayMode -Mode "Clone"
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant