My WiFi driver sometimes crashes in the morning when trying to connect to my school’s Eduroam network. At first I restarted my laptop and it solved the problem. I found out that it's possible to restart your driver in Device Manager, but that takes too much time to do (a whole minute). So I decided to write a script that would reset the driver in a click. You can use this method to restart any driver.

The method that didn’t work out for me:

At first I needed to install the Device Manager PowerShell Cmdlets

You can download it from here.

Unzip it Start PowerShell CD to the directory Import-Module .\DeviceManagement.psd1 –Verbose

Now it’s possible to get a list of all devices by typing Get-Device

Find the name of the driver you want to reset and take a piece of the name that’s unique. In my case it’s Ultimate-N 6300.

With this command it’d be possible to disable my WLAN driver:

Get-Device | Where-Object -Property Name -Like 'Ultimate-N 6300' | Disable-Device



Unfortunately I got an error. After spending some time on Google I couldn’t find any solution. I read that the error was probably due to a x64/x32 bit mismatch. After that I tried to find a different way.

The method that worked for me

Download DevCon: 32bit / 64bit Place devcon.exe in c:\windows\system32

(the \ia64\devcon.exe won’t work) Find the name of the driver you want to reset and take a piece of the name that’s unique.

You can get a list of all devices by typing devcon find *

It returned all devices including my WiFi adapter:

PCI\VEN_8086&DEV_4238&SUBSYS_11118086&REV_35\0024D7FFFF1755E000: Intel(R) Centrino(R) Ultimate-N 6300 AGN devcon disable *DEV_4238

devcon enable *DEV_4238

That’s it!

Making it into a script

I found this piece of code, which makes PowerShell ask for Admin privileges (UAC thingy)

The last line closes the current PowerShell session.

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 {

Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))

}

exit

}

devcon disable *DEV_4238

devcon enable *DEV_4238

stop-process -Id $PID



Copy paste it in a text editor and save it as a .ps1 file.

Or download it here: restartDriver.ps1

Now you can double click the file to restart your driver(s) :)

Oh no!! ERROR



To solve that you’ll have to type this line in PowerShell:

Set-ExecutionPolicy RemoteSigned

Thanks for reading!

This is one of my hobbies :P trying computer stuff!