Jump to content

Exit script if not connected with Ethernet


Recommended Posts

Hi All,

We are looking for a way to exit a script if the PC is not connected via an Ethernet connection.  We don't want the script to run if it detects it is connected to Wireless or VPN.  All PC's will be running Windows 7.  If anyone could point me in the right direction, it would be much appreciated!

Link to comment
Share on other sites

As you're new would you mind adding as to the reason you would need something like this? Surely connecting to the network by any means is a good thing?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Sure, thanks for the fast response.  The script actually removes the PC from the domain, reboots, logs in as a local admin, joins another domain, reboots again ready to login to new domain.  We want to deploy via SCCM, but need to find a way to ensure the script doesn't execute when not connected via Ethernet!

Link to comment
Share on other sites

OK. This is a little out of my jurisdiction I'm afraid.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

This vbs can be converted to autoit...you would loop through until found adapter type like ethernet..else not connected

On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter")

Set objFSO=CreateObject("Scripting.FileSystemObject")

outFile="c:\test.txt"
Set objFile = objFSO.CreateTextFile(outFile,True)


For Each objItem in colItems
    objFile.Write "Adapter Type: " & objItem.AdapterType & Chr(9)
 
    Select Case objItem.AdapterTypeID
        Case 0 strAdapterType = "Ethernet 802.3" 
        Case 1 strAdapterType = "Token Ring 802.5" 
        Case 2 strAdapterType = "Fiber Distributed Data Interface (FDDI)" 
        Case 3 strAdapterType = "Wide Area Network (WAN)" 
        Case 4 strAdapterType = "LocalTalk" 
        Case 5 strAdapterType = "Ethernet using DIX header format" 
        Case 6 strAdapterType = "ARCNET" 
        Case 7 strAdapterType = "ARCNET (878.2)" 
        Case 8 strAdapterType = "ATM" 
        Case 9 strAdapterType = "Wireless" 
        Case 10 strAdapterType = "Infrared Wireless" 
        Case 11 strAdapterType = "Bpc" 
        Case 12 strAdapterType = "CoWan" 
        Case 13 strAdapterType = "1394"
    End Select
 
    objFile.Write "Adapter Type Id: " & strAdapterType & Chr(9)
    objFile.Write"AutoSense: " & objItem.AutoSense & Chr(9)
    objFile.Write "Description: " & objItem.Description & Chr(9)
    objFile.Write "Device ID: " & objItem.DeviceID & Chr(9)
    objFile.Write "Index: " & objItem.Index & Chr(9)
    objFile.Write "MAC Address: " & objItem.MACAddress & Chr(9)
    objFile.Write "Manufacturer: " & objItem.Manufacturer & Chr(9)
    objFile.Write "Maximum Number Controlled: " & objItem.MaxNumberControlled & Chr(9)
    objFile.Write "Maximum Speed: " & objItem.MaxSpeed & Chr(9)
    objFile.Write "Name: " & objItem.Name & Chr(9)
    objFile.Write "Net Connection ID: " & objItem.NetConnectionID & Chr(9)
    objFile.Write "Net Connection Status: " & objItem.NetConnectionStatus & Chr(9)
    For Each strNetworkAddress in objItem.NetworkAddresses & Chr(9)
        objFile.Write "NetworkAddress: " & strNetworkAddress & Chr(9)
    Next
    objFile.Write "Permanent Address: " & objItem.PermanentAddress & Chr(9)
    objFile.Write "PNP Device ID: " & objItem.PNPDeviceID & Chr(9)
    objFile.Write "Product Name: " & objItem.ProductName & Chr(9)
    objFile.Write "Service Name: " & objItem.ServiceName & Chr(9)
    objFile.Write "Speed: " & objItem.Speed & Chr(9)
    objFile.Write Chr(13) & Chr(10)
Next

try:

$strComputer = "."
$objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
$ocolItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapter")

$bIsEthernet = False

For $objItem In $ocolItems
    $iAdapterID = $objItem.AdapterTypeID
    ConsoleWrite($iAdapterID & @CRLF)
    If StringLen($iAdapterID) = 0 Then $iAdapterID = -1
    Switch $iAdapterID
        Case 0,1,3,5; all applicable cases...i'm guessing
            $bIsEthernet = True
            ExitLoop
    EndSwitch
Next

MsgBox(1,1,"$bIsEthernet=" & $bIsEthernet)
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Thank you.  However, it appears both the NIC card and WiFi card are reporting as 802.3.  See below...

Wifi connection

Adapter Type: Ethernet 802.3 Adapter Type Id: Ethernet 802.3 AutoSense:  Description: Intel® WiFi Link 5300

LAN:

Adapter Type: Ethernet 802.3 AutoSense:  Description: Intel® 82567LM Gigabit Network Connection

So Case 0 is always true whether connected to NIC card or WiFi.   

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
 Share

  • Recently Browsing   0 members

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