Created
April 8, 2022 18:19
-
-
Save Osmiogrzesznik/c2371d551dafd81f444743d6d72cf034 to your computer and use it in GitHub Desktop.
toggles the touch screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To allow script to be executed on double click | |
# https://stackoverflow.com/a/30644946/1366368 | |
# To sign script | |
# https://adamtheautomator.com/how-to-sign-powershell-script/ | |
# To automatically elevate script to admin privs, I used this code fromn https://superuser.com/a/532109/222708 | |
param([switch]$Elevated) | |
function Test-Admin { | |
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent()) | |
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) | |
} | |
if ((Test-Admin) -eq $false) { | |
if ($elevated) { | |
# tried to elevate, did not work, aborting | |
} else { | |
# Removed -noexit as it will force the powershell instance to keep running after finishing | |
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition)) | |
} | |
exit | |
} | |
# If Status of touch screen is Error, then it is off. | |
$result = (Get-PnpDevice|Where-Object {$_.FriendlyName -like '*touch screen*'}|Select -ExpandProperty 'Status') | |
if ($result -eq 'Error') { | |
Write-Host "Enabling touch screen" | |
Get-PnpDevice|Where-Object {$_.FriendlyName -like '*touch screen*'}|Enable-PnpDevice -Confirm:$false | |
} else { | |
Write-Host "Disabling touch screen" | |
Get-PnpDevice|Where-Object {$_.FriendlyName -like '*touch screen*'}|Disable-PnpDevice -Confirm:$false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment