Page 1 of 2 12>
Topic Options
#147212 - 2005-09-06 05:48 PM Works but not works ?!ス#?!
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Trying to get the first MAC for an IP.
The code below will print the first MAC as i want it, but also en error: unexpected command! - pointing on the last empty line of the script.

What Im donig wrong?

$IP = "192.168.10.10"

$MACz = WMIQuery("MACAddress","Win32_NetworkAdapter",$IP)

For Each $MAC in $MACz
If $MAC>0 AND NOT InStr($MAC,"50:50:54")

$PMAC = $MAC[0]

? $PMAC

EndIf

Function WMIQuery($sWhat, $sFrom, Optional $sComputer, Optional $sWhere, Optional $x, Optional $root, Optional $sUserID, Optional $sUserPW)
Dim $sQuery, $objEnum, $sValue, $TMP, $SystemSet, $, $objInstance, $objLocator

$sComputer = Trim(Join(Split($sComputer,'\'),''))
If NOT $sComputer OR $sComputer = @wksta
$sComputer = '.'
EndIf
If NOT $root
$root = '\root\cimv2'
EndIf
$sQuery = 'Select ' + $sWhat + ' From '+ $sFrom
If $sWhere AND $x
$sQuery = $sQuery+" Where "+$sWhere+" = '"+$x+"'"
EndIf
If $sUserID AND $sUserPW AND $sComputer <> '.'
$objLocator = CreateObject('WbemScripting.SWbemLocator')
If @ERROR OR NOT $objLocator Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
$SystemSet = $objLocator.ConnectServer($sComputer, $root, $sUserID, $sUserPW)
If @ERROR OR NOT $SystemSet Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
$SystemSet.Security_.ImpersonationLevel = 3
Else
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$sComputer+$root)
If @ERROR OR NOT $SystemSet Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
EndIf
$objEnum = $SystemSet.ExecQuery($sQuery)
If @ERROR OR NOT $objEnum Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
For Each $objInstance In $objEnum
$=Execute(Chr(36) + 'sValue = ' + Chr(36) + 'objInstance.' + $sWhat)
If VarType($sValue) & 8192
$tmp = $tmp +'|' + Join($sValue,'|')
Else
$tmp = $tmp +'|' + $sValue
EndIf
Next
$WMIQuery = Split(SubStr($tmp,2),'|')
Exit Val("&"+Right(DecToHex(@ERROR),4))
EndFunction
_________________________
I will always look out from behind these eyes...

Top
#147213 - 2005-09-06 05:52 PM Re: Works but not works ?!ス#?!
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
missing next in "For Each $MAC in $MACz"
_________________________



Top
#147214 - 2005-09-06 06:04 PM Re: Works but not works ?!ス#?!
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
... no, I dont think thats why. :-(
Same error with "next" - pointing at the line where "next" is.

Its something else... doing something wrong. Dont know what...humm
_________________________
I will always look out from behind these eyes...

Top
#147215 - 2005-09-06 06:07 PM Re: Works but not works ?!ス#?!
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
and you placed 'next' after 'endif' and before 'function' ?
_________________________



Top
#147216 - 2005-09-06 06:09 PM Re: Works but not works ?!ス#?!
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
yeap ... no success
_________________________
I will always look out from behind these eyes...

Top
#147217 - 2005-09-06 06:09 PM Re: Works but not works ?!ス#?!
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Whoa hold it!

Got the error, $Mac inside the for loop is no longer an array but a string

replace :

Code:

$PMAC = $MAC[0]



with

Code:


$PMAC = $MAC



and don't forget the next
_________________________



Top
#147218 - 2005-09-06 06:16 PM Re: Works but not works ?!ス#?!
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
NOOO Jochen ...then it will print ALL MACz for found NIC interfaces...
I just want the first one... the mac in first line ... what 2 do?
_________________________
I will always look out from behind these eyes...

Top
#147219 - 2005-09-06 06:17 PM Re: Works but not works ?!ス#?!
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Post your code between code tags so that the indenting is preserved.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#147220 - 2005-09-06 06:21 PM Re: Works but not works ?!ス#?!
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Sorry Les, not sure I understand what u mean...
_________________________
I will always look out from behind these eyes...

Top
#147221 - 2005-09-06 06:24 PM Re: Works but not works ?!ス#?!
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
It is all explained in the FAQ. Look at Jochen's post and you will see he used code tags. You did not.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#147222 - 2005-09-06 06:36 PM Re: Works but not works ?!ス#?!
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Is it the tags for UBBCode?
Then I will use it.
_________________________
I will always look out from behind these eyes...

Top
#147223 - 2005-09-06 10:20 PM Re: Works but not works ?!ス#?!
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you didn't.
_________________________
!

download KiXnet

Top
#147224 - 2005-09-06 10:29 PM Re: Works but not works ?!ス#?!
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:


Then I will use it.



When?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#147225 - 2005-09-06 11:30 PM Re: Works but not works ?!ス#?!
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
doesn't look like he is gonna answer...
_________________________
!

download KiXnet

Top
#147226 - 2005-09-06 11:36 PM Re: Works but not works ?!ス#?!
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
hmmm sounds like he wants the first mac that passes his condition. But the condition to me seems a bit repetitive. I'm thinking something like this.

Note - see how i'm using the code tags

Code:

$PMAC=""
$MACz = WMIQuery("MACAddress","Win32_NetworkAdapter",$IP)
For Each $MAC in $MACz
If Not $PMAC and NOT InStr($MAC,"50:50:54")
$PMAC = $MAC
EndIf
Next
? $PMAC


Top
#147227 - 2005-09-07 12:42 AM Re: Works but not works ?!ス#?!
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
JazzM,

Did you get this working or not?

Also... you're not that much of a noob - posting for help with a title of Works but not works ?!ス#?! is not very intuitive on what help you're looking for.

Top
#147228 - 2005-09-07 04:14 AM Re: Works but not works ?!ス#?!
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Original Code
Code:

FOR EACH $mac IN $macz
IF $mac>0 AND NOT InStr($mac,"50:50:54")
$pmac = $mac[0]
? $pmac
ENDIF

;($begin)
;
; tue 06-sep-2005 18:53:58 (kix 4.20 vs 4.00e)
;
;Informative KIXSTRIP: input=12 output=12 skip=0
;
;Warning KIXSTRIP: 1 error in block structure. missing statement(s).
; - do:until [0:0]
; -ERROR- - for|each:in|to:step|next [1|1:1|0:0|0]
; - function:endfunction [0:0]
; - if:else:endif [1:0:1]
; - select:case:endselect [0:0:0]
; - while:loop [0:0]
;Warning KIXSTRIP: some lines contains errors or possible errors.
;Informative KIXSTRIP: 2 block_structures found.
;Informative KIXSTRIP: no UDF's found.
;Informative KIXSTRIP: no labels found.
;Summary KIXSTRIP: BREAK CALL DEBUG DISPLAY ENDFUNCTION EXECUTE EXIT FUNCTION GET GETS GOSUB GOTO OLExxx PLAY QUIT RETURN RUN SHELL SLEEP THEN USE
;
;($end)
;($begin)
;
;
;($end)



Changed and updated:
Code:

FOR EACH $mac IN $macz
IF $mac>0 AND NOT InStr($mac,"50:50:54")
$pmac = $mac[0]
? $pmac
ENDIF
NEXT

;($begin)
;
; tue 06-sep-2005 18:55:35 (kix 4.20 vs 4.00e)
;
;Informative KIXSTRIP: no errors found (input=10 output=10 skip=0).
;
;Summary KIXSTRIP: block structures
; - do:until [0:0]
; - for|each:in|to:step|next [1|1:1|0:0|1]
; - function:endfunction [0:0]
; - if:else:endif [1:0:1]
; - select:case:endselect [0:0:0]
; - while:loop [0:0]
;Informative KIXSTRIP: 2 block_structures found.
;Informative KIXSTRIP: no UDF's found.
;Informative KIXSTRIP: no labels found.
;Summary KIXSTRIP: BREAK CALL DEBUG DISPLAY ENDFUNCTION EXECUTE EXIT FUNCTION GET GETS GOSUB GOTO OLExxx PLAY QUIT RETURN RUN SHELL SLEEP THEN USE
;
;($end)



HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#147229 - 2005-09-07 09:56 AM Re: Works but not works ?!ス#?!
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Still, $mac is not an array at this time
_________________________



Top
#147230 - 2005-09-07 11:10 AM Re: Works but not works ?!ス#?!
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Holly Jesus, what痴 going on here!. Lots of fingers on me. Sorry but I知 not that intelligence as u are.

Quote:

Lonkero:
you didn't.





I知 truly sorry Lonkero. Now when I know what/how, I sure will use it.

Quote:

Les:
when?





I知 truly sorry Les. Now when I know such thing as "tags" exist I will use it.
Hopefully I知 using it in this conversation

Quote:

Lonkero:

doesn't look like he is gonna answer...






Probably means that "he" is not online, busy on something else, gone home, eating pizza, have to go to funeral then wedding.
BUT it doesn稚 necessary means that he don稚 want to answer!


Quote:

maciep :

Note - see how I知 using the code tags.






Thanks maciep :-)

Quote:

NTDOC:

Did you get this working or not?

Also... you're not that much of a noob - posting for help with a title of Works but not works ?!ス#?! is not very intuitive on what help you're looking for.






Answer: No Doc, not yet. right now I知 busy answer all fingers on me. Will get back to u when I test the codes.
Plz, explain the word "noob" - my English is not that good.
"Works but not works" referring to my case which I explain in beginning: that I got the output I want, but I got also an error.
I知 open for any suggestions how to choose the headline for a topic :-)


___________________________________________________________________________

Now my dear friends if u don稚 mind, I will check the code and suggestion provided by you and get back to u ASAP.
And many thanks for your help. U R ALL GOOD
_________________________
I will always look out from behind these eyes...

Top
#147231 - 2005-09-07 11:41 AM Re: Works but not works ?!ス#?!
JazzM Offline
Getting the hang of it

Registered: 2004-04-23
Posts: 91
Maciep code rocks
What a star! 5 trillion star to Sir Maciep.
_________________________
I will always look out from behind these eyes...

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1644 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.077 seconds in which 0.048 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org