Re-Ordering Network Provider order in Windows - Modify a VB Script

I have used this script by Anders Olsson to Chang Network Provider order in Windows.. It works very well.

I would like to modify it to where "LanmanWorkstation" will be first and "NCredMgr" to be last. The once in between does not matter the order.
eg.  "LanmanWorkstation, NetwareWorkstation, RDPNP, WebClient, NCredMgr"


Andres Olsson Script: (I am attaching it as well)

'
' 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"
Network_provider_Order.txt
petrosygAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it_saigeDeveloperCommented:
Should be as simple as something like (this is untested):
'
' 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 and NCredMgr is already last, 
' we don't have to do anything
If arrProvs(0) = "LanmanWorkstation" And arrProvs(UBound(arrProvs)) = "NCredMgr" 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.
' Also, don't write NCredMgr as we will write it at the end of the string when we
' exit the loop.
For Each strProv In arrProvs
	Select Case strProv
		Case "LanmanWorkstation"
		Case "NCredMgr"
		Case Else strNewProvs = strNewProvs & "," & strProv
	End Select
Next

' "NCredMgr" should always end the string
strNewProvs = strNewProvs & "," & "NCredMgr"

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

Open in new window

-saige-
0
petrosygAuthor Commented:
it_saige,

Thank you for the quick response .... I was so close but I see the mistakes that I had on my code .... Let me test it quickly  but the logic looks perfect.

Petros
0
petrosygAuthor Commented:
it_saige,

I run the script and it errors--- Invalid root in Registry key ....

Just to let you know, Not all devices have the NCredMgr in their list .... could that be causing the issue?

I should have specified first, my initial attempt was  to put "LanmanWorkstation" first and if "NCredMgr" exist, to put it last.

Thank you for any input.
error-message-.JPG
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

it_saigeDeveloperCommented:
If thats the case then we can just implement a method to check for the existence of NCredMgr; perhaps something like (Edited - this is now tested) -
'
' 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 and NCredMgr is already last, 
' we don't have to do anything
If arrProvs(0) = "LanmanWorkstation" And (HasProvider("NCredMgr", arrProvs) And arrProvs(UBound(arrProvs)) = "NCredMgr") 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.
' Also, don't write NCredMgr as we will write it at the end of the string when we
' exit the loop.
For Each strProv In arrProvs
	Select Case strProv
		Case "LanmanWorkstation"
		Case "NCredMgr"
		Case Else strNewProvs = strNewProvs & "," & strProv
	End Select
Next

' If "NCredMgr" is a provider, it should always end the string
If HasProvider("NCredMgr", arrProvs) Then
	strNewProvs = strNewProvs & "," & "NCredMgr"
End If

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

Function HasProvider(name, providers)
	Dim result
	result = False
	For Each provider In providers
		If provider = name Then
			result = True
		End If
	Next
	HasProvider = result
End Function

Open in new window

Produces the following results -Provider order before script runsProvider order after script runs.-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
petrosygAuthor Commented:
Thanks, let me give it a try!
0
petrosygAuthor Commented:
Great logic ... appreciate it works perfectly sofar
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.