Jump to content

VBScript for WinPE Network Speed


Recommended Posts

So I am trying to create a Network Speed scrpt that auto detects the netork speed in WinPE and sets accordingly. All of our production switches are hard coded to either 10/100 Full. It is a mixture of Devcon and some registry changed.

The problem is that when I run this script automatically in startup in PE it doesnt appear to work, the disable part works but it will never re-enable the card. If i call the script manually, everything works fine.

EDIT: a big problem is that devcon doesnt seem to want to work with stdout so it doesnt write to a text file for enable/disable and i cant pull out any errors from the stream with vbscript. The enable passes way too fast when automated.

Here is the code:

Any ideas?


'Setup Prelim stuff
Dim WshShell, oExec, filesys, ID, CardSpeed, NetworkUP, TMP
Set WshShell = CreateObject("WScript.Shell")
Set filesys=CreateObject("Scripting.FileSystemObject")
WScript.Echo "***Configurating Network For Optimal Speeds - Auto Network Script***"
'Copy Down Devcon to enable files
If filesys.FileExists("Y:\HII\Tools\Network\devcon.exe") Then
filesys.CopyFile "Y:\HII\Tools\Network\devcon.exe", "X:\TEMP\"
WScript.Echo "Copying Files.."
End If

Call GetNetworkID()
'Disable Network Card
Call DisableNetwork(ID)
'Set Card to 10Full First
Call ChangeNetworkSpeed("2")
'Enable Card
Call EnableNetworkCard(ID)
'Check Network Speed
Call CheckNetwork()
If NetworkUP = 1 Then
'If true then Card is fine at 10 Full
WScript.Echo "Card is Set to 10 Full"
WScript.Quit 10
Else
Call DisableNetwork(ID)
Call ChangeNetworkSpeed("4")
Call EnableNetworkCard(ID)
Call CheckNetwork()
If NetworkUP = 1 Then
WScript.Echo "Card is Set to 100 Full"
WScript.Quit 100
Else
Call DisableNetwork(ID)
Call ChangeNetworkSpeed("0")
Call EnableNetworkCard(ID)
Call CheckNetwork()
If NetworkUP = 1 Then
WScript.Echo "Card is Set to Auto"
WScript.Quit 5
Else
WScript.Echo "No Network Access - Please Contact Engineers"
WScript.Quit 1
End If
End If
End If



Sub GetNetworkID()
'Get Device IDS
Set oExec = WshShell.Exec("CMD /C ""X:\TEMP\devcon.exe listclass net >> X:\TEMP\devcon.txt""")
WScript.Echo "Capturing Network Device ID...."
Do While oExec.Status = 0
WScript.Echo "."
WScript.Sleep 1000
Loop
Set objTextFile = filesys.OpenTextFile("X:\TEMP\devcon.txt", 1, False)
Do Until objTextFile.AtEndOfStream
strLine = objTextFile.Readline
if instr(strLine,"PCI") > 0 Then
arrDev = Split(strLine, ":")
ID = trim(arrDEV(0))
ID = CStr(ID)
WScript.Echo "The ID is " & ID
'filesys.DeleteFile("X:\TEMP\devcon.txt")
Exit Sub
End If
Loop
If ID = "" Then
WScript.Echo "No Network Device ID Found"
WScript.Quit 2
End If
End Sub

Sub DisableNetwork(ID)
If ID = "" Then
WScript.Echo "No ID Returned"
Exit Sub
Else
'Disable Network Card
Set oExec = WshShell.Exec("CMD /C ""X:\TEMP\devcon.exe disable "&Trim(ID)&" >> X:\TEMP\devcon.txt""")
WScript.Echo "Disabling Network Card..."
Do While oExec.Status = 0
WScript.Echo "."
WScript.Sleep 1000
Loop
End If
End Sub

Sub EnableNetworkCard(ID)
If ID = "" Then
WScript.Echo "No ID Returned"
Exit Sub
Else
'Enable Network Card
Set oExec = WshShell.Exec("CMD /C ""X:\TEMP\devcon.exe enable "&Trim(ID)&"""")
WScript.Echo "Enabling Network Card..."
Do While oExec.Status = 0
WScript.Echo "."
WScript.Sleep 3000
Loop
End If
End Sub

Sub ChangeNetworkSpeed(CardSpeed)
If CardSpeed = "2" Then
WScript.Echo "Setting Network Card to 10 Full"
ElseIf CardSpeed = "4" Then
WScript.Echo "Setting Network Card to 100 Full"
ElseIf CardSpeed = "0" Then
WScript.Echo "Setting Network Card to AUTO"
Else
WScript.Echo "No Network Speed Given"
Exit Sub
End if
Set oExec = WshShell.Exec("REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0000 /v *SpeedDuplex /t REG_SZ /d "&CardSpeed&" /F")
Do While oExec.Status = 0
WScript.Echo "."
WScript.Sleep 1000
Loop
Do While oExec.StdOut.AtEndOfStream <> True
if instr(oExec.StdOut.ReadLine,"successfully") Then
WScript.Echo "Registry Entries Changed"
End If
Loop
End Sub


Sub CheckNetwork()
Set oExec = WshShell.Exec("ping -n 5 ushsdistribs1")
WScript.Echo "Checking Network Connectivity..."
Do While oExec.Status = 0
WScript.Echo "."
WScript.Sleep 1000
Loop
Do While oExec.StdOut.AtEndOfStream <> True
if instr(oExec.StdOut.ReadAll,"Received = 5") Then
NetworkUP = 1
Else
NetworkUP = 0
End If
Loop
End Sub

Edited by Kungfus0n
Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...