Wednesday, November 01, 2006

Changing Network Provider order in Windows

Problem: I needed to put the "Microsoft Windows Network" network provider on top of the other (Novell Netware) providers. This is to get rid of the 15 second delay the Novell client does when trying to access a Windows file server.

This is pretty easy to do manually (Network Connections->Advanced->Advanced Settings->Provider Order), but a little more difficult to do manually. The registry key "HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order\ProviderOrder" lists the providers as a comma separated string, for example "NetwareWorkstation,RDPNP,LanmanWorkstation,WebClient"

Unfortunately, the installed providers aren't really predictable. For example, if the computer has PointSec drive encryption installed, a provider named "PssoCM32" is listed somewhere in the end of the string.

Solution: Read the string from the registry, split it up, create a new string beginning with "LanmanWorkstation" (which of course is the "Microsoft Windows Network" provider), attach the rest of the providers to the new string, in the same order they were originally listed.

VBScript Code (successfully made unreadable by blogger.com, but is copy-pasteable to Notepad):

'
' ChangeProviderOrder.vbs, by Anders Olsson, Kentor Teknik AB, 2006-10-31
'
' Reads the "Network provider order" from the registry and reorders it putting
' the "Microsoft Windows Networking" provider on top.
'
' Example: Before - "NCredMgr,NetwareWorkstation,RDPNP,LanmanWorkstation,WebClient"
' would become "LanmanWorkstation,NCredMgr,NetwareWorkstation,RDPNP,WebClient" after
' running this script.
'

Set WshShell = WScript.CreateObject("WScript.Shell")

' Read the reg value of the providers
strKey = WshShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order\ProviderOrder")

' Split the strings up using comma (ASCII #44) as the delimiter
arrProvs = Split(strKey, chr(44), -1, 1)

' If LanmanWorkstation is already first, we don't have to do anything
If arrProvs(0) = "LanmanWorkstation" Then
Wscript.Quit(0)
end if

' "LanmanWorkstation" should always start the string
strNewProvs = "LanmanWorkstation"

' Loop through the old provider strings, and add them to the new string. Don't
' write LanmanWorkstation, since it's already written at the start of the string.
For Each strProv In arrProvs
Select Case strProv
Case "LanmanWorkstation"
Case Else strNewProvs = strNewProvs & "," & strProv
End Select
Next

' Write the new string back to the registry
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order\ProviderOrder", strNewProvs, "REG_SZ"

19 Comments:

Anonymous Anonymous said...

Thank You!!!

28 September, 2007 10:54  
Anonymous Anonymous said...

Thanks, that proved useful. I added the following code to detect machines where LanmanWorkstation was not installed.

' Check if LanmanWorkstation is a configured provider and quit if not configured
If InStr(strKey,"LanmanWorkstation")= 0 Then
WScript.Quit(0)
End If

11 April, 2008 08:14  
Blogger Unknown said...

Thanks so much dude, super script!

30 May, 2008 07:43  
Blogger gabriellus said...

I copy and paste the code into a .vbs text file in XP, and when I double-click the saved file, it does nothing. In Task Manager, wscript.exe pops up and closes after a moment. Also, the changes are not occurring. What's going on here? Is there something in this code that has been deprecated?

21 April, 2009 11:07  
Blogger Anders Olsson said...

Try running it from a command window and see if it returns any error messages.

21 April, 2009 11:38  
Anonymous Anonymous said...

copy-paste-run-worked... thanks for the script!

08 May, 2009 09:25  
Anonymous Impish said...

Great work Thanks !

30 September, 2009 00:42  
Anonymous Anonymous said...

How would you do the opposite of moving a specific entry down to the bottom(last) if found in the provider list?

18 November, 2009 12:43  
Anonymous Anonymous said...

A slight modification that bypasses the error checking and makes it easier to customize:

For Each strProv In arrProvs
Select Case strProv
Case "LanmanWorkstation" strFirst = strProv
Case "Some Other Provider" strSecond = "," & strProvider
Case Else strTail = strTail & "," & strProv
End Select
Next
strNewProvs = strFirst & strSecond & strTail

12 March, 2010 14:15  
Anonymous Anonymous said...

thank you so much, ran into same problem with Novell here!

06 April, 2010 06:34  
Blogger Reinhard en Tanita said...

Hi,

Thank you, this works GREAT on Windows XP.

I tried it on Windows 7 as well and the very same VB Script gives an error:

Line 38 Char 117
Error: Expoected end of statement
Code: 800A0401
Source: Microsoft VB Script compilation error

Any ideas if VB Script on Win 7 needs to look different or have something extra in it to work?

Thanks a million,
Reinhard

05 May, 2011 02:09  
Blogger Reinhard en Tanita said...

Awesome, thanks ! Worked brilliantly !!

05 May, 2011 02:16  
Anonymous Anonymous said...

Does anyone know what RDPNP is?

15 July, 2011 07:53  
Anonymous Scott said...

Anyone got a powershell script that can do this

Im getting stuck with splitting the stirng once i have it in the array (the easy part:)

21 February, 2012 21:31  
Anonymous Anonymous said...

Worked great, thank you!

29 February, 2012 11:30  
Blogger Unknown said...

Thanks for sharing..

' 2012-07-11 DS - Per http://support.microsoft.com/kb/832161
' Added logic to support additional load order priorities, if exist

' 2012-07-11 DS - Per http://technet.microsoft.com/en-us/library/cc959369.aspx
' Added logic to verify Service Key and NetworkProvider group membership for each element

11 July, 2012 20:39  
Anonymous Anonymous said...

Even today I used this on XP pc's, years after posting.

Thanks a million!!

15 November, 2013 03:29  
Anonymous Anonymous said...

This really saved us with our Novell to Active Directory migration. Thanks a ton!

19 March, 2014 08:53  
Blogger Darklurker said...

Here is a batch file that will do this as well. Took me the better part of the day to work out all of the FOR loops and get it down. It seems to work fine on XP, but UAC interferes on Win7/8 (probably Vista too).
I went the batch file route because I was afraid some of our computers would start throwing up weird warnings if I asked my users to run a VBS. Too bad UAC causes similar problems. But eh, OK.
I'm still working on a way around UAC.

@echo off

setlocal EnableDelayedExpansion

echo.

set basekey=hklm\system\currentcontrolset\control\networkprovider\order
set regquery=reg query %basekey% /v providerorder
set ms=LanmanWorkstation

rem We use a for loop to execute the "reg query" and loop through each line of output.
rem We are assuming that the last line from the reg output is the only one we want.
rem The FOR loop overwrites instring each time, so only the last one gets kept
for /F "delims=" %%i in ('%regquery%') do set instring=%%i

rem put each word in the string into a variable, and keep count of their number
set wordcount=1
For %%j in (%instring%) Do (
set w!wordcount!=%%j
Set /A wordcount+=1
)

rem NOTE: at this point, the words from the registry value are in the "w" variables
rem starting at w3. W1 and w2 contain "ProviderOrder" and "REG_SZ", which we don't
rem need.

rem a quick check - if mslanmanclient is already word #3, we don't need to do anything
if /I %w3%==%ms% (
echo Your computer already has the Microsoft provider in spot 1. Exiting now...
goto end
)

rem subtract one to allow for the extra increment before we exited the for %%j loop above.
rem this is for the for /L loop below, so it doesn't run off the end of the tracks...
set /A wordcount-=1

set outstring=%ms%

rem I thought this would be the easy part... ;)
rem how to explain this? eh, loop through each word starting at w3.
rem If the word does not equal mslanmanclient, add it to outstring.
rem have to delayexpand outstring below, or it only grabs the last word.
for /L %%k in (3,1,%wordcount%) do (
if /I not "!w%%k!"=="%ms%" set outstring=!outstring!,!w%%k!
)

echo outstring is %outstring%

rem now run reg to update the value
rem this is where Windows UAC will bite you in the buttocks. Runs fine on XP though...
reg add %basekey% /v providerorder /d %outstring%

echo Finished

23 April, 2014 14:16  

Post a Comment

<< Home