1
0

Add Readme

This commit is contained in:
glax 2023-03-31 15:22:07 +02:00
parent 81a6bda175
commit 89350ee4e2
4 changed files with 62 additions and 59 deletions

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# How to run
Change PCIe paths in file
Execute switchGPU.ps1 in powershell

View File

@ -1,2 +1,2 @@
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit } if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
pnputil /disable-device "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041" #disable iGPU pnputil /disable-device "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041" #disable iGPU

View File

@ -1,2 +1,2 @@
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit } if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
pnputil /enable-device "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041" #enable iGPU pnputil /enable-device "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041" #enable iGPU

View File

@ -1,57 +1,57 @@
param([String]$working=$pwd, [String]$desktop = [Environment]::GetFolderPath("Desktop")) param([String]$working=$pwd, [String]$desktop = [Environment]::GetFolderPath("Desktop"))
$folderPath = "C:\.gpu" $folderPath = "C:\.gpu"
$gpuTask = Join-Path $working GPU.xml $gpuTask = Join-Path $working 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 -desktop $desktop" -Verb RunAs; exit } if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -working $pwd -desktop $desktop" -Verb RunAs; exit }
$scriptOld = Join-Path $working "*" $scriptOld = Join-Path $working "*"
$linkEnableOrig = Join-Path $folderPath "enableigpu.ps1" $linkEnableOrig = Join-Path $folderPath "enableigpu.ps1"
$linkEnableDesk = Join-Path $desktop "Enable-iGPU" $linkEnableDesk = Join-Path $desktop "Enable-iGPU"
$linkDisableOrig = Join-Path $folderPath "disableigpu.ps1" $linkDisableOrig = Join-Path $folderPath "disableigpu.ps1"
$linkDisableDesk = Join-Path $desktop "Disable-iGPU" $linkDisableDesk = Join-Path $desktop "Disable-iGPU"
Write-Output "Testing if files exist" Write-Output "Testing if files exist"
if(-Not (Test-Path $folderPath)){ if(-Not (Test-Path $folderPath)){
Write-Output "Creating Directory $folderPath" Write-Output "Creating Directory $folderPath"
New-Item $folderPath -Type Directory New-Item $folderPath -Type Directory
attrib +h $folderPath attrib +h $folderPath
Copy-Item $scriptOld $folderPath Copy-Item $scriptOld $folderPath
New-Item -ItemType SymbolicLink -Path $linkEnableDesk -Target $linkEnableOrig New-Item -ItemType SymbolicLink -Path $linkEnableDesk -Target $linkEnableOrig
New-Item -ItemType SymbolicLink -Path $linkDisableDesk -Target $linkDisableOrig New-Item -ItemType SymbolicLink -Path $linkDisableDesk -Target $linkDisableOrig
} }
Write-Output "Checking if task already exists" Write-Output "Checking if task already exists"
if(Get-ScheduledTask | Where-Object{$_.TaskName -eq "GPU"}) if(Get-ScheduledTask | Where-Object{$_.TaskName -eq "GPU"})
{ {
Write-Output "Task exists" Write-Output "Task exists"
}else }else
{ {
Register-ScheduledTask -TaskName "GPU" -Xml (Get-Content $gpuTask | Out-String) Register-ScheduledTask -TaskName "GPU" -Xml (Get-Content $gpuTask | Out-String)
} }
Write-Output "Waiting 5 Seconds" Write-Output "Waiting 5 Seconds"
Start-Sleep 5 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"}) 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" 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"}) 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" Write-Output "Disabling iGPU"
pnputil /disable-device "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041" #disable iGPU pnputil /disable-device "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041" #disable iGPU
}else }else
{ {
Write-Output "iGPU already disabled" Write-Output "iGPU already disabled"
} }
}else }else
{ {
Write-Output "dGPU not plugged in" 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"}) 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" Write-Output "iGPU already enabled"
}else }else
{ {
Write-Output "Enabling iGPU" Write-Output "Enabling iGPU"
pnputil /enable-device "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041" #enable iGPU pnputil /enable-device "PCI\VEN_1002&DEV_1681&SUBSYS_380117AA&REV_C1\4&33381BD1&0&0041" #enable iGPU
} }
} }