Kungfus0n Posted January 18, 2011 Posted January 18, 2011 (edited) 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 stuffDim WshShell, oExec, filesys, ID, CardSpeed, NetworkUP, TMPSet WshShell = CreateObject("WScript.Shell")Set filesys=CreateObject("Scripting.FileSystemObject")WScript.Echo "***Configurating Network For Optimal Speeds - Auto Network Script***"'Copy Down Devcon to enable filesIf filesys.FileExists("Y:\HII\Tools\Network\devcon.exe") Then filesys.CopyFile "Y:\HII\Tools\Network\devcon.exe", "X:\TEMP\" WScript.Echo "Copying Files.."End IfCall GetNetworkID()'Disable Network CardCall DisableNetwork(ID)'Set Card to 10Full FirstCall ChangeNetworkSpeed("2")'Enable CardCall EnableNetworkCard(ID)'Check Network SpeedCall CheckNetwork()If NetworkUP = 1 Then'If true then Card is fine at 10 Full WScript.Echo "Card is Set to 10 Full" WScript.Quit 10Else 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 IfEnd IfSub GetNetworkID()'Get Device IDSSet 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 1000LoopSet 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 IfLoop If ID = "" Then WScript.Echo "No Network Device ID Found" WScript.Quit 2End IfEnd SubSub DisableNetwork(ID)If ID = "" Then WScript.Echo "No ID Returned" Exit SubElse '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 LoopEnd IfEnd SubSub EnableNetworkCard(ID)If ID = "" Then WScript.Echo "No ID Returned" Exit SubElse '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 LoopEnd IfEnd SubSub 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 SubEnd ifSet 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 1000LoopDo While oExec.StdOut.AtEndOfStream <> True if instr(oExec.StdOut.ReadLine,"successfully") Then WScript.Echo "Registry Entries Changed" End IfLoopEnd SubSub CheckNetwork()Set oExec = WshShell.Exec("ping -n 5 ushsdistribs1")WScript.Echo "Checking Network Connectivity..."Do While oExec.Status = 0 WScript.Echo "." WScript.Sleep 1000LoopDo While oExec.StdOut.AtEndOfStream <> True if instr(oExec.StdOut.ReadAll,"Received = 5") Then NetworkUP = 1 Else NetworkUP = 0 End IfLoopEnd Sub Edited January 18, 2011 by Kungfus0n
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now