Dim strFlag
Dim regmode

strValueToRemove = "Mvfs"

Set objShell = CreateObject("WScript.Shell")

If Wscript.Arguments.Count > 0 Then
strFlag = Wscript.arguments.Item(0)
End If

If IsEmpty(strFlag) Then Wscript.quit 'No arguments have been received

'objShell.Popup strFlag,0,"args are","48"

If strFlag = "/u" Then regmode = "remove"
If strFlag = "/i" Then regmode = "add"

'Read the registry keys into variables
strCurrentValue_HwOrder = objShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder\ProviderOrder")
strCurrentValue_Order = objShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order\ProviderOrder")

'Split the value to an array and go through each one looking for the "value to remove". If found, exclude it from the new value.
arrHwOrder = Split(strCurrentValue_HwOrder, ",", -1, 1)
For x = 0 to UBound(arrHwOrder)
If arrHwOrder(x) <> strValueToRemove Then strNewValue_HwOrder = strNewValue_HwOrder & "," & arrHwOrder(x)
arrOrder = Split(strCurrentValue_Order, ",", -1, 1)
For x = 0 to UBound(arrOrder)
If arrOrder(x) <> strValueToRemove Then strNewValue_Order = strNewValue_Order & "," & arrOrder(x)

If regmode = "add" Then
strNewValue_HwOrder = strValueToRemove & strNewValue_HwOrder
strNewValue_Order = strValueToRemove & strNewValue_Order
'objShell.Popup strNewValue_HwOrder,0,"Add Hardware order","48"
'objShell.Popup strNewValue_Order,0,"Add order","48"
'Write the new registry values. This way if removing.
objShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder\ProviderOrder", strNewValue_HwOrder, "REG_SZ"
objShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order\ProviderOrder", strNewValue_Order, "REG_SZ"
End If

If regmode = "remove" Then
'Write the new registry values. This way if removing.
'objShell.Popup Mid(strNewValue_HwOrder, 2),0,"Remove Hardware order","48"
'objShell.Popup Mid(strNewValue_Order, 2),0,"Remove order","48"
objShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\HwOrder\ProviderOrder", Mid(strNewValue_HwOrder, 2), "REG_SZ"
objShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order\ProviderOrder", Mid(strNewValue_Order, 2), "REG_SZ"
End If
0 Comments   [ + ] Show Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.



- No 'Option Explicit'
- Zero error-handling (never mind, everything always works 100%, right?)
- Code repetition (registry key strings)
- Superfluous code, e.g.:If strFlag = "/u" Then regmode = "remove"
If strFlag = "/i" Then regmode = "add"
If regmode = "remove" Then
Answered 12/01/2011 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity