From 95c9f6ca03057b5901e2e83ea01b3182a74b8e91 Mon Sep 17 00:00:00 2001 From: unknown <13404778+C9Glax@users.noreply.github.com> Date: Fri, 31 Mar 2023 14:41:56 +0200 Subject: [PATCH] initial commit --- GPU.xml | Bin 0 -> 3546 bytes switchGPU.ps1 | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 GPU.xml create mode 100644 switchGPU.ps1 diff --git a/GPU.xml b/GPU.xml new file mode 100644 index 0000000000000000000000000000000000000000..fd3fa310d706793b10ccc2a0e8e0152c90c6912f GIT binary patch literal 3546 zcmb`K+iwy<6vof9iT?xP!KeurX}u#&wbhb%sTSgc`hbN((*g~Be9HNgp!BUY%mU3O#6RUA0#2OKE?2xKFPidJE zKjA*Xvg+83v7I|cecI>r)~o^Jx^44T=e_29Q=aL9Re8a)1iz+zAj%Mgg#H;8Deua@ z&3(d~&q=o4e$UwqXjhzuZIOT7{cfQ{hr2-zTg2CI1D+3QyKj%(??WQiEXR;uIrgqy z5`RS08ThXllOAJJ;VJc}jL+0Q|85sj>=C1N$*m2JJPxhvB4=%xr7$*EKqEUtpCOm8 zl%hJXVL0TT6f9#qujD>fJ^Sji>%&v}UxF)6#lDQM_pI4wahl+$rYB&>%>O4J&*=#6 zUtQfwp^M*j)UsP-nA%f&@3NcOci8)SyM1{Omh)RX1`iM}tfxxfOZW0)5u?6}3~ftk%9*H-D}N;l;I*P@5S}6Gb(?S_?JGJ+uz{ zeJw28l(6>W8P3>nC6cH2?t-YYN;HrC8c_5IQDw25Q>e;y{h=;RH}+cL{q7O=`K;f-S@T4yika45@l}l-^FM*X zlpgH^-_fNFcddyt`rdNST^@gn5@)#wdg8|P9OOBi6@SKWo4w#2@t*TvS!jGt9jg{S zz6!jO|ArCsP~0gxDC#TTyk@K7hwJ9wdB#z9QP<~v;Ii&B50t0&Uai#1I$otW^N6G5 zntpUU{DeL13Ut+Dwi^^R-OMMB^Ad=`4rCz;e06e#hwRLU7t%QgrXjCU+lMB8JQwQly#Od=1256gGq<_^j<}*>nvi7 zeNKzo`E`o)r`Qh9F>Ts4HIGyBJS4_FJ6N2vHt~p~_?|$Pr7{(Q^ U<=oU7E9Uc7dxt90msiVv0T&-NUjP6A literal 0 HcmV?d00001 diff --git a/switchGPU.ps1 b/switchGPU.ps1 new file mode 100644 index 0000000..5f1f4a1 --- /dev/null +++ b/switchGPU.ps1 @@ -0,0 +1,53 @@ +param([String]$working=$pwd) +$folderPath = "C:\.gpu" +$gpuTask = Join-Path $folderPath GPU.xml +if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -working $pwd" -Verb RunAs; exit } + +Write-Output "Testing if files exist" +if(-Not (Test-Path $folderPath)){ + Write-Output "Creating Directory $folderPath" + New-Item $folderPath -Type Directory +} +$scriptOld = Join-Path $working "switchGPU.ps1" +$scriptNew = Join-Path $folderPath "switchGPU.ps1" +if(-Not (Test-Path $scriptNew)){ + Write-Output "Copying script to $folderPath" + Copy-Item $scriptOld $scriptNew +} + + +Write-Output "Checking if task already exists" +if(Get-ScheduledTask | Where-Object{$_.TaskName -eq "GPU"}) +{ + Write-Output "Task exists" +}else +{ + Register-ScheduledTask -TaskName "GPU" -Xml (Get-Content $gpuTask | Out-String) +} + + +Write-Output "Waiting 5 Seconds" +Start-Sleep 5 +if(Get-PnpDevice | Where-Object{$_.InstanceId -eq "PCI\VEN_10DE&DEV_1B80&SUBSYS_85AA1043&REV_A1\6&5c8cf2c&0&00080019"} | Where-Object{$_.Status -eq "OK"}) +{ + Write-Output "dGPU plugged in" + if(Get-PnpDevice | Where-Object{$_.InstanceId -eq "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041"} | Where-Object{$_.Status -eq "OK"}) + { + Write-Output "Disabling iGPU" + pnputil /disable-device "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041" #disable iGPU + }else + { + Write-Output "iGPU already disabled" + } +}else +{ + Write-Output "dGPU not plugged in" + if(Get-PnpDevice | Where-Object{$_.InstanceId -eq "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041"} | Where-Object{$_.Status -eq "OK"}) + { + Write-Output "iGPU already enabled" + }else + { + Write-Output "Enabling iGPU" + pnputil /enable-device "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041" #enable iGPU + } +}