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"
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:
Thank You!!!
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
Thanks so much dude, super script!
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?
Try running it from a command window and see if it returns any error messages.
copy-paste-run-worked... thanks for the script!
Great work Thanks !
How would you do the opposite of moving a specific entry down to the bottom(last) if found in the provider list?
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
thank you so much, ran into same problem with Novell here!
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
Awesome, thanks ! Worked brilliantly !!
Does anyone know what RDPNP is?
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:)
Worked great, thank you!
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
Even today I used this on XP pc's, years after posting.
Thanks a million!!
This really saved us with our Novell to Active Directory migration. Thanks a ton!
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
Post a Comment
<< Home