SHARE
TWEET

OculusUSBfix.ps1

a guest Dec 20th, 2016 250 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Requires -Version 3.0
  2. #Requires -RunAsAdministrator
  3.  
  4. # This script will disable all USB power saving settings on the system, in particular those associated with the Oculus Rift or Fresco Logic controllers.
  5. # It should run fine on Windows 8, Windows 8.1 and Windows 10. Windows 7 may work if you update Powershell.
  6.  
  7. # To run:
  8. # Save the script as 'OculusUSBfix.ps1' somewhere. Open the file's properties and check 'Unblock' and click Apply.
  9. # Go to Start, Windows Powershell, right click and select 'Run as administrator'.
  10. # Type 'Set-ExecutionPolicy RemoteSigned' once to be able to run PowerShell scripts (Or 'Set-ExecutionPolicy Unrestricted' if you did not unblock the file.)
  11. # Go to the folder where you saved the script and run it.
  12.  
  13. # These are the USB hardware IDs that we want to disable the 'Allow the computer to turn off this device to save power' setting on.
  14. # If you want to disable another USB devices power management, go to device manager, the properties of the device, details tab, Device ID / instance path, and copy the 'VID_nnnn&PID_nnnn' (Vendor ID and Product ID) to the following list. VID_2833 is Oculus VR LLC.
  15. $DeviceIDs = (
  16. "VID_2833&PID_0211", # Oculus Rift Sensor
  17. "VID_2833&PID_0330", # Oculus Rift HMD
  18. "VID_2833&PID_0031", # Oculus Rift HMD
  19. "ROOT_HUB_FL30" # Fresco Logic xHCI (USB3) Root Hub
  20. )
  21.  
  22.  
  23. # The script starts here.
  24. Write-Output "Starting script to check Oculus Rift and Fresco Logic USB problems."
  25. Write-Output "This script will not check USB driver versions or fix any issues related to cabling. Ensure you have known good drivers and test without USB and HDMI extension cables if problems persist."
  26.  
  27. # To track if we make changes anywhere.
  28. $ChangesMade = $False
  29. $IsRebootRequired=$False
  30.  
  31. # Initiate a CIM session to use in the following CIM commands.
  32. Try {
  33.     $CIM_Session = New-CimSession -ErrorAction Stop
  34. } catch {
  35.     Throw "Could not establish a CIM session. The script cannot run."
  36. }
  37.  
  38. # Get the currently active power plan.
  39. $PowerPlan = Get-CimInstance -CimSession $Cim_Session -ClassName Win32_PowerPlan -Namespace "root\cimv2\power" | Where-Object { $_.IsActive }
  40.  
  41. # Get the currently configured 'USB selective suspend setting' under power options.
  42. $FilterString = "%$(($PowerPlan.InstanceID).SubString(($PowerPlan.InstanceID).Length-38))%AC%{48e6b7a6-50f5-4782-a5d4-53bb8f07e226}"
  43. $USBSuspendSetting = Get-CimInstance -CimSession $Cim_Session -ClassName Win32_PowerSettingDataIndex -Namespace "root\cimv2\power" -Filter "InstanceID like '$FilterString'"
  44.  
  45. # If 'USB selective suspend setting' is currently enabled.
  46. If ( $USBSuspendSetting.SettingIndexValue -ne 0 ) {
  47.     Write-Output "Changing 'Power Options', '$($PowerPlan.ElementName)', 'Change (current) plan settings', 'Change advanced power settings', 'USB settings', 'USB selective suspend setting' to Disabled."
  48.     $USBSuspendSetting  | Set-CimInstance -CimSession $Cim_Session -Property @{SettingIndexValue = 0}
  49.     Write-Output "Reactivating power plan $($PowerPlan.ElementName) to ensure our change is applied right now."
  50.     $return = Invoke-CimMethod -CimSession $Cim_Session -InputObject $PowerPlan -MethodName Activate -ErrorAction SilentlyContinue
  51.     If ( !$return.ReturnValue ) {
  52.         Throw "There was an error while applying the power policy change."
  53.     }
  54.     # We made a change. Track this.
  55.     $ChangesMade = $True
  56. }
  57.  
  58. # Get a list of all the USB devices in the system so we can find user friendly names.
  59. $USBDevices = Get-CimInstance -ClassName Win32_PnPEntity -Namespace "root\cimv2"
  60.  
  61. # Get a list of all devices with power management in the system.
  62. $PowerDevices = Get-CimInstance -CimSession $Cim_Session -ClassName "MSPower_DeviceEnable" -Namespace "root\wmi"
  63.  
  64. # For each device with power management in the system.
  65. Foreach ( $PowerDevice in $PowerDevices ) {
  66.     # Check against the entire list of DeviceIDs defined at the beginning of the script.
  67.     Foreach ( $DeviceID in $DeviceIDs ) {
  68.         $PowerDeviceUpperCase = $PowerDevice.InstanceName.ToUpper()
  69.         $DeviceIDUpperCase = $DeviceID.ToUpper()
  70.         # Find where the USB device is the power device.
  71.         If ( "$PowerDeviceUpperCase" -like "*$DeviceIDUpperCase*" ) {
  72.             # If 'Allow the computer to turn off this device to save power' is enabled.
  73.             If ( $PowerDevice.Enable ) {
  74.                 # Retrieve the name of the USB device so we can display a user friendly name.
  75.                 $USBDevice = $USBDevices | Where-Object { $_.DeviceID -eq ($PowerDevice.InstanceName -replace "_0$") }
  76.                 $USBDeviceName = $USBDevice.Name
  77.                 Write-Output "Disabling 'Allow the computer to turn off this device to save power', under 'Device Manager', '$USBDeviceName', 'Properties'."
  78.                 $PowerDevice | Set-CimInstance -CimSession $Cim_Session -Property @{Enable = $False}
  79.                 # We made a change. Track this.
  80.                 $ChangesMade = $True
  81.             }
  82.         }
  83.     }
  84. }
  85.  
  86. # If a driver for a Fresco Logic FL1xxx USB controller is installed.
  87. If ( Test-Path -Path Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\FLxHCIc\Parameters ) {
  88.     # If the U1U2LowPower registry setting does not exist or is not set to disabled (0).
  89.     If ( (Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\FLxHCIc\Parameters).U1U2LowPower -ne 0 ) {
  90.         Write-Output "Adding registry key 'HKLM\SYSTEM\CurrentControlSet\Services\FLxHCIc\Parameters\U1U2LowPower' to disable low power states for Fresco Logic USB controllers."
  91.         Try {
  92.             New-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\FLxHCIc\Parameters -Name U1U2LowPower -PropertyType DWORD -Value 0 -Force | Out-Null
  93.         } catch {
  94.             Throw "Could not create registry key."
  95.         }
  96.         # We made a change. Track this.
  97.         $ChangesMade = $true
  98.         # A registry setting change will not be picked up by the driver until the computer is rebooted. Track this.
  99.         $IsRebootRequired = $true
  100.     }
  101.     # If the BulkInRingBuffers does not exist is not set to decimal 256.
  102.     If ( (Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\FLxHCIc\Parameters).BulkInRingBuffers -ne 256 ) {
  103.         Write-Output "Adding registry key 'HKLM\SYSTEM\CurrentControlSet\Services\FLxHCIc\Parameters\BulkInRingBuffers' to increase buffers for Fresco Logic USB controllers."
  104.         Try {
  105.         New-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\FLxHCIc\Parameters -Name BulkInRingBuffers -PropertyType DWORD -Value 256 -Force | Out-Null
  106.             } catch {
  107.             Throw "Could not create registry key."
  108.         }
  109.         # We made a change. Track this.
  110.         $ChangesMade = $true
  111.         # A registry setting change will not be picked up by the driver until the computer is rebooted. Track this.
  112.         $IsRebootRequired = $true
  113.     }
  114. }
  115.  
  116. # If we made any change.
  117. If ( $ChangesMade ) {    
  118.     If ( $IsRebootRequired ) {
  119.         Write-Output "Changes were applied. Due to changes in the registry for the Fresco Logic USB controller driver a REBOOT IS REQUIRED before the changes take effect."
  120.     } Else {        
  121.         Try {
  122.             Write-Output "Restarting the Oculus VR Runtime Service to ensure it works okay."
  123.             # We restart the Oculus VR Runtime only if a reboot of the computer isn't required.
  124.             Get-Service -Name "OVRService" | Restart-Service -ErrorAction Stop
  125.         } catch {
  126.             Throw "Could not restart the Oculus VR Runtime Service."
  127.         }
  128.         Write-Output "Changes were applied. No reboot is required."
  129.     }
  130. } Else {
  131.     Write-Output "No changes were needed."
  132. }
  133.  
  134. # Close the CIM session.
  135. Remove-CimSession -CimSession $CIM_Session -ErrorAction SilentlyContinue
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top