Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Resolving hostname error

$
0
0

I used the example by UEZ 2011 to resolve hostname using IP. It works great, but I just notice that if it's not a computer; I get the error:

 

Line 65 (File Location):   $colItems = $objWMIService.ExecQuery("SELECT SystemName FROM Win32_NetworkAdapter WHERE NetConnectionStatus=2", "WQL", 0x30)   Error: Missing right bracket ')' in expression.

 

I don't think I missed a bracket.

 

Here's the script:

AutoIt         
Func WMI_GetHostName($host) ;Formula to resolve hostname;     Local $HostNameWMI, $colItems, $colItem, $ping     $ping = Ping($host)     If $ping Then         $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $host & "\root\cimv2")         $colItems = $objWMIService.ExecQuery("SELECT SystemName FROM Win32_NetworkAdapter WHERE NetConnectionStatus=2", "WQL", 0x30)         If IsObj($colItems) Then             For $objItem In $colItems                 If $objItem.SystemName = "" Then Return SetError(3, 0, "")                 Return $objItem.SystemName             Next             Return SetError(0, 0, $HostNameWMI)         Else             Return SetError(2, 0, "")         EndIf     Else         Return SetError(1, 0, "")     EndIf EndFunc Func ObjErrorHandler() ;Error handling resolving hostname;     ConsoleWrite(   "A COM Error has occured!" & @CRLF  & @CRLF & _                                 "err.description is: "    & @TAB & $oErrorHandler.description    & @CRLF & _                                 "err.windescription:"     & @TAB & $oErrorHandler & @CRLF & _                                 "err.number is: "         & @TAB & Hex($oErrorHandler.number, 8)  & @CRLF & _                                 "err.lastdllerror is: "   & @TAB & $oErrorHandler.lastdllerror   & @CRLF & _                                 "err.scriptline is: "     & @TAB & $oErrorHandler.scriptline     & @CRLF & _                                 "err.source is: "         & @TAB & $oErrorHandler.source         & @CRLF & _                                 "err.helpfile is: "       & @TAB & $oErrorHandler.helpfile       & @CRLF & _                                 "err.helpcontext is: "    & @TAB & $oErrorHandler.helpcontext & @CRLF _                             ) EndFunc

 

So if anyone knows a way to have it - if not pc, msgbox shows "Not a PC"


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>