berkeberk Posted May 24, 2013 Share Posted May 24, 2013 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 More sharing options...
guinness Posted May 24, 2013 Share Posted May 24, 2013 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
berkeberk Posted May 24, 2013 Author Share Posted May 24, 2013 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 More sharing options...
guinness Posted May 24, 2013 Share Posted May 24, 2013 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
jdelaney Posted May 24, 2013 Share Posted May 24, 2013 (edited) This vbs can be converted to autoit...you would loop through until found adapter type like ethernet..else not connected expandcollapse popupOn 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 May 24, 2013 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 More sharing options...
berkeberk Posted May 24, 2013 Author Share Posted May 24, 2013 I think I can make that work! Thank you. I will post the Autoit code early next week! Link to comment Share on other sites More sharing options...
jdelaney Posted May 24, 2013 Share Posted May 24, 2013 edit: added autit script above...not sure if you saw it. 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 More sharing options...
berkeberk Posted May 28, 2013 Author Share Posted May 28, 2013 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 More sharing options...
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