Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

VBScript for WinPE Network Speed

Featured Replies

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


Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.