Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Tue, 3 Jun 2008 22:46:56 -0400,    group: microsoft.public.win32.programmer.wmi        back       


How can I obtain the MAC address of a remote machine via a WMI Script?   
Gurus,

Running Windows Server 2003 SP2.  How can I obtain the MAC address of a 
remote machine via a WMI Script?  The script would need to create a WMI 
object and then access the Win32_NetworkAdapter class, which has a property 
that returns the MAC address.  I< unfortunately, haven't a clue on how to 
write one.

--
Spin
date: Tue, 3 Jun 2008 22:46:56 -0400   author:   Spin

Re: How can I obtain the MAC address of a remote machine via a WMI Script?   
Hi,
We've all been through this..
Google 'WMI code creator'
Anyway here's your script (in vbscript)
<code>
strComputer = "domain\name"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\CIMV2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_NetworkAdapter",,48)
For Each objItem in colItems
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_NetworkAdapter instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "MACAddress: " & objItem.MACAddress
Next
</code>
The script needs to have the proper rights on the machine it queries
Running on my machine it lists 12 instances, and 4 different MAC
addresses.

Have fun with that ;)

Rob'

On Jun 4, 4:46 am, "Spin"  wrote:
> Gurus,
>
> Running Windows Server 2003 SP2.  How can I obtain the MAC address of a
> remote machine via a WMI Script?  The script would need to create a WMI
> object and then access the Win32_NetworkAdapter class, which has a property
> that returns the MAC address.  I< unfortunately, haven't a clue on how to
> write one.
>
> --
> Spin
date: Wed, 4 Jun 2008 00:37:04 -0700 (PDT)   author:   RD

Re: How can I obtain the MAC address of a remote machine via a WMI Script?   
Does this VB script make a Windows API call to obtain the remote MAC 
address?  I can't tell by the code.  Forgive my ignorance!

"RD"  wrote in message 
news:8b819a9d-6434-4ccf-a77f-68e8df2ac686@e39g2000hsf.googlegroups.com...
> Hi,
> We've all been through this..
> Google 'WMI code creator'
> Anyway here's your script (in vbscript)
> <code>
> strComputer = "domain\name"
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
> \CIMV2")
> Set colItems = objWMIService.ExecQuery( _
>    "SELECT * FROM Win32_NetworkAdapter",,48)
> For Each objItem in colItems
>    Wscript.Echo "-----------------------------------"
>    Wscript.Echo "Win32_NetworkAdapter instance"
>    Wscript.Echo "-----------------------------------"
>    Wscript.Echo "MACAddress: " & objItem.MACAddress
> Next
> </code>
> The script needs to have the proper rights on the machine it queries
> Running on my machine it lists 12 instances, and 4 different MAC
> addresses.
>
> Have fun with that ;)
date: Wed, 4 Jun 2008 07:44:35 -0400   author:   Spin

Re: How can I obtain the MAC address of a remote machine via a WMI Script?   
It's a simple WQL request (SQL like for WMI) to list all instances of
Win32_NetworkAdapter class
then, for each of the results, it prints the MACAddress property.
So it's all WMI, works on any remote computer provided you have the
proper user rights (that is admin) on the account that runs the
script.
If you want to logon as another user, google or msdn search for
Management.ManagementScope (I use that in VB.NET)

Hope this helps.

Rob'
On 4 juin, 13:44, "Spin"  wrote:
> Does this VB script make a Windows API call to obtain the remote MAC
> address?  I can't tell by the code.  Forgive my ignorance!
>
> "RD"  wrote in message
>
> news:8b819a9d-6434-4ccf-a77f-68e8df2ac686@e39g2000hsf.googlegroups.com...
>
> > Hi,
> > We've all been through this..
> > Google 'WMI code creator'
> > Anyway here's your script (in vbscript)
> > <code>
> > strComputer = "domain\name"
> > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
> > \CIMV2")
> > Set colItems = objWMIService.ExecQuery( _
> >    "SELECT * FROM Win32_NetworkAdapter",,48)
> > For Each objItem in colItems
> >    Wscript.Echo "-----------------------------------"
> >    Wscript.Echo "Win32_NetworkAdapter instance"
> >    Wscript.Echo "-----------------------------------"
> >    Wscript.Echo "MACAddress: " & objItem.MACAddress
> > Next
> > </code>
> > The script needs to have the proper rights on the machine it queries
> > Running on my machine it lists 12 instances, and 4 different MAC
> > addresses.
>
> > Have fun with that ;)
date: Wed, 4 Jun 2008 05:49:57 -0700 (PDT)   author:   RD

Re: How can I obtain the MAC address of a remote machine via a WMI Script?   
"RD"  wrote in message 
news:76faf4d4-d409-4f98-bc21-a9ef3c8ad05d@a70g2000hsh.googlegroups.com...
>It's a simple WQL request (SQL like for WMI) to list all instances of
>Win32_NetworkAdapter class
>then, for each of the results, it prints the MACAddress property.
>So it's all WMI, works on any remote computer provided you have the
>proper user rights (that is admin) on the account that runs the
>script.
>If you want to logon as another user, google or msdn search for
>Management.ManagementScope (I use that in VB.NET)

It definitely worked.  It picked up the remote MAC address of the machine 
for which I intended it.  It also picked up some other MAC addresses as well 
which was kind of weird.

What I did was alter line 1 of the script changing it to:
strComputer = "DC1"

which resulted in it displaying the MAC of machine DC1 (DC1 has only 1 NIC, 
no other NICs present at all).  However the script also displayed a MAC of 
50:50:54:50:30:30. Kinda weird, huh?
date: Wed, 4 Jun 2008 11:40:25 -0400   author:   Spin

Re: How can I obtain the MAC address of a remote machine via a WMI Script?   
On Jun 4, 5:40 pm, "Spin"  wrote:
> "RD"  wrote in message
>
> news:76faf4d4-d409-4f98-bc21-a9ef3c8ad05d@a70g2000hsh.googlegroups.com...
>
> >It's a simple WQL request (SQL like for WMI) to list all instances of
> >Win32_NetworkAdapter class
> >then, for each of the results, it prints the MACAddress property.
> >So it's all WMI, works on any remote computer provided you have the
> >proper user rights (that is admin) on the account that runs the
> >script.
> >If you want to logon as another user, google or msdn search for
> >Management.ManagementScope (I use that in VB.NET)
>
> It definitely worked.  It picked up the remote MAC address of the machine
> for which I intended it.  It also picked up some other MAC addresses as well
> which was kind of weird.
>
> What I did was alter line 1 of the script changing it to:
> strComputer = "DC1"
>
> which resulted in it displaying the MAC of machine DC1 (DC1 has only 1 NIC,
> no other NICs present at all).  However the script also displayed a MAC of
> 50:50:54:50:30:30. Kinda weird, huh?

I know. tested it on two computers (both running win xp pro, both with
only one NIC) and on both it reports 10+ instances, with 3 differant
mac addresses.. I don't know what the others are though..
So to be sure, you can change the request to "SELECT * FROM
Win32_NetworkAdapter WHERE DeviceID=1"
If I remember correctly the mac address of the first device listed is
the good one.
Glad it helped.
date: Wed, 4 Jun 2008 12:25:58 -0700 (PDT)   author:   RD

Re: How can I obtain the MAC address of a remote machine via a WMI Script?   
I see that exact number show up on a hardware
listing script that I use. Maybe there are particular
MAC address constants that represent  various
hardware/protocols? I don't know. But in case it's
of use, here's the return of network adapters that was
spit out by an HP PC:

-------------------------------------------------
Description: Intel(R) PRO/100 VE Network Connection
Name: Intel(R) PRO/100 VE Network Connection
Manufacturer:
MAC Address:

Description: RAS Async Adapter
Name: RAS Async Adapter
Manufacturer:
MAC Address:

Description: Packet Scheduler Miniport
Name: Packet Scheduler Miniport
Manufacturer: Microsoft
MAC Address:

Description: WAN Miniport (L2TP)
Name: WAN Miniport (L2TP)
Manufacturer: Microsoft
MAC Address:

Description: WAN Miniport (PPTP)
Name: WAN Miniport (PPTP)
Manufacturer: Microsoft
MAC Address: 50:50:54:50:30:30

Description: WAN Miniport (PPPOE)
Name: WAN Miniport (PPPOE)
Manufacturer: Microsoft
MAC Address: 33:50:6F:45:30:30

Description: Direct Parallel
Name: Direct Parallel
Manufacturer: Microsoft
MAC Address:

Description: WAN Miniport (IP)
Name: WAN Miniport (IP)
Manufacturer: Microsoft
MAC Address:

Description: Packet Scheduler Miniport
Name: Packet Scheduler Miniport
Manufacturer: Microsoft
MAC Address: CC:F6:20:52:41:53

Description: Intel(R) PRO/100 VE Network Connection
Name: Intel(R) PRO/100 VE Network Connection
Manufacturer: Intel
MAC Address: 00:E0:18:4F:E3:E0

Description: Packet Scheduler Miniport
Name: Packet Scheduler Miniport
Manufacturer: Microsoft
MAC Address: 00:E0:18:4F:E3:E0

Description: 1394 Net Adapter
Name: 1394 Net Adapter
Manufacturer: Microsoft
MAC Address: 32:9F:90:F8:37:79
----------------------------------------

Your number is in there under WAN Miniport.

   I also noticed that a number of items were
returned twice, but only once with a MAC
address. The first item returned was the actual
ethernet card, but its MAC address was only
included with the second instance.

   I have no idea of what the explanation is
for that.

> >It's a simple WQL request (SQL like for WMI) to list all instances of
> >Win32_NetworkAdapter class
> >then, for each of the results, it prints the MACAddress property.
> >So it's all WMI, works on any remote computer provided you have the
> >proper user rights (that is admin) on the account that runs the
> >script.
> >If you want to logon as another user, google or msdn search for
> >Management.ManagementScope (I use that in VB.NET)
>
> It definitely worked.  It picked up the remote MAC address of the machine
> for which I intended it.  It also picked up some other MAC addresses as
well
> which was kind of weird.
>
> What I did was alter line 1 of the script changing it to:
> strComputer = "DC1"
>
> which resulted in it displaying the MAC of machine DC1 (DC1 has only 1
NIC,
> no other NICs present at all).  However the script also displayed a MAC of
> 50:50:54:50:30:30. Kinda weird, huh?
>
>
date: Wed, 4 Jun 2008 19:49:02 -0400   author:   mayayana

Re: How can I obtain the MAC address of a remote machine via a WMI Script?   
"RD"  wrote in message 
news:14e3e0b7-336f-4213-8b44-d41bb022a107@79g2000hsk.googlegroups.com...
> On Jun 4, 5:40 pm, "Spin"  wrote:
>> "RD"  wrote in message
> I know. tested it on two computers (both running win xp pro, both with
> only one NIC) and on both it reports 10+ instances, with 3 differant
> mac addresses.. I don't know what the others are though..
> So to be sure, you can change the request to "SELECT * FROM
> Win32_NetworkAdapter WHERE DeviceID=1"
> If I remember correctly the mac address of the first device listed is
> the good one.
> Glad it helped.

That worked nicely.
date: Wed, 4 Jun 2008 22:47:32 -0400   author:   Spin

Re: How can I obtain the MAC address of a remote machine via a WMI Script?   
Good info on the WAN Miniports, I verified and it makes sense.  I never have 
really understood what WAN Miniports really were for but I know they have 
something to do with remote networking.

"mayayana"  wrote in message 
news:%23q5Z51pxIHA.4864@TK2MSFTNGP06.phx.gbl...
>  I see that exact number show up on a hardware
> listing script that I use. Maybe there are particular
> MAC address constants that represent  various
> hardware/protocols? I don't know. But in case it's
> of use, here's the return of network adapters that was
> spit out by an HP PC:
>
> -------------------------------------------------
> Description: Intel(R) PRO/100 VE Network Connection
> Name: Intel(R) PRO/100 VE Network Connection
> Manufacturer:
> MAC Address:
>
> Description: RAS Async Adapter
> Name: RAS Async Adapter
> Manufacturer:
> MAC Address:
>
> Description: Packet Scheduler Miniport
> Name: Packet Scheduler Miniport
> Manufacturer: Microsoft
> MAC Address:
>
> Description: WAN Miniport (L2TP)
> Name: WAN Miniport (L2TP)
> Manufacturer: Microsoft
> MAC Address:
>
> Description: WAN Miniport (PPTP)
> Name: WAN Miniport (PPTP)
> Manufacturer: Microsoft
> MAC Address: 50:50:54:50:30:30
>
> Description: WAN Miniport (PPPOE)
> Name: WAN Miniport (PPPOE)
> Manufacturer: Microsoft
> MAC Address: 33:50:6F:45:30:30
>
> Description: Direct Parallel
> Name: Direct Parallel
> Manufacturer: Microsoft
> MAC Address:
>
> Description: WAN Miniport (IP)
> Name: WAN Miniport (IP)
> Manufacturer: Microsoft
> MAC Address:
>
> Description: Packet Scheduler Miniport
> Name: Packet Scheduler Miniport
> Manufacturer: Microsoft
> MAC Address: CC:F6:20:52:41:53
>
> Description: Intel(R) PRO/100 VE Network Connection
> Name: Intel(R) PRO/100 VE Network Connection
> Manufacturer: Intel
> MAC Address: 00:E0:18:4F:E3:E0
>
> Description: Packet Scheduler Miniport
> Name: Packet Scheduler Miniport
> Manufacturer: Microsoft
> MAC Address: 00:E0:18:4F:E3:E0
>
> Description: 1394 Net Adapter
> Name: 1394 Net Adapter
> Manufacturer: Microsoft
> MAC Address: 32:9F:90:F8:37:79
> ----------------------------------------
>
> Your number is in there under WAN Miniport.
>
>   I also noticed that a number of items were
> returned twice, but only once with a MAC
> address. The first item returned was the actual
> ethernet card, but its MAC address was only
> included with the second instance.
>
>   I have no idea of what the explanation is
> for that.
date: Wed, 4 Jun 2008 22:48:40 -0400   author:   Spin

Re: How can I obtain the MAC address of a remote machine via a WMI   
"Spin" wrote:

> "RD"  wrote in message 
> news:14e3e0b7-336f-4213-8b44-d41bb022a107@79g2000hsk.googlegroups.com...
> > On Jun 4, 5:40 pm, "Spin"  wrote:
> >> "RD"  wrote in message
> > I know. tested it on two computers (both running win xp pro, both with
> > only one NIC) and on both it reports 10+ instances, with 3 differant
> > mac addresses.. I don't know what the others are though..
> > So to be sure, you can change the request to "SELECT * FROM
> > Win32_NetworkAdapter WHERE DeviceID=1"
> > If I remember correctly the mac address of the first device listed is
> > the good one.
> > Glad it helped.
> 
> That worked nicely. 
> 
> 


I think it is safer not to rely on network adapter device id. You can use 
Win32_NetworkAdapterConfiguration with IPEnabled = true


strComputer = "ComputerName"

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

Set colAdapters = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration " _
& "Where IPEnabled = True")
 
For Each objAdapter in colAdapters
WScript.Echo objAdapter.MACAddress
Next

-- 
urkec
date: Thu, 5 Jun 2008 12:12:01 -0700   author:   urkec

Re: How can I obtain the MAC address of a remote machine via a WMI   
That worked nicely also.  Why do you say "safer", btw?
date: Thu, 5 Jun 2008 16:23:03 -0400   author:   Spin

Re: How can I obtain the MAC address of a remote machine via a WMI   
"Spin"  wrote in message 
news:6ar09cF381ra5U1@mid.individual.net...
> That worked nicely also.  Why do you say "safer", btw?

Second question is, one has to directly modify the script on line 1 to enter 
the computer who's remotye MAC addres I want to find.  How can this script 
be modifued such that it prompts you for the name of the remote computer, 
you enter it in and hit OK and then it finishes out normally?
date: Fri, 6 Jun 2008 00:30:25 -0400   author:   Spin

Re: How can I obtain the MAC address of a remote machine via a WMI   
On 6 juin, 06:30, "Spin"  wrote:
> "Spin"  wrote in message
>
> news:6ar09cF381ra5U1@mid.individual.net...
>
> > That worked nicely also.  Why do you say "safer", btw?
>
> Second question is, one has to directly modify the script on line 1 to enter
> the computer who's remotye MAC addres I want to find.  How can this script
> be modifued such that it prompts you for the name of the remote computer,
> you enter it in and hit OK and then it finishes out normally?

cpu = Wscrpit.stdin.readline  'that is to read user input
Now if you want to ensure the input is, at least syntaxically, a
correct computer name, that'a a whole other story.

Rob'
date: Thu, 5 Jun 2008 23:49:55 -0700 (PDT)   author:   RD

Re: How can I obtain the MAC address of a remote machine via a WMI   
>
cpu = Wscrpit.stdin.readline  'that is to read user input
Now if you want to ensure the input is, at least syntaxically, a
correct computer name, that'a a whole other story.
>
  That assumes that Spin is using console,
but he mentioned clicking "OK". If you're going
to only give the console method it might be a good
idea to point that out, since it's not typical usage.
For normal VBS it would be:

cpu = InputBox("Enter name of remote computer.")
date: Fri, 6 Jun 2008 08:59:21 -0400   author:   mayayana

Re: How can I obtain the MAC address of a remote machine via a WMI   
"Spin" wrote:

> That worked nicely also.  Why do you say "safer", btw? 
> 
> 
> 

Because there is no guarantee that Win32_NetworkAdapter.DeviceId will always 
be equal to 1. As far as I can remember it normally is, but if you select IP 
enabled network adapters, you don't have to worry about device id.


-- 
urkec
date: Fri, 6 Jun 2008 06:26:02 -0700   author:   urkec

Re: How can I obtain the MAC address of a remote machine via a WMI   
How would that work in a script?  The below doesn't quite work, I get an 
error on line 4. :(

'Begin Script
cpu = InputBox("Enter name of remote computer.")
strComputer = "computername"

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

Set colAdapters = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration " _
& "Where IPEnabled = True")

For Each objAdapter in colAdapters
WScript.Echo objAdapter.MACAddress
Next
'End Script
date: Fri, 6 Jun 2008 09:30:44 -0400   author:   Spin

Re: How can I obtain the MAC address of a remote machine via a WMI   
On 6 juin, 14:59, "mayayana"  wrote:
> cpu = Wscrpit.stdin.readline  'that is to read user input
> Now if you want to ensure the input is, at least syntaxically, a
> correct computer name, that'a a whole other story.
>
>   That assumes that Spin is using console,
> but he mentioned clicking "OK". If you're going
> to only give the console method it might be a good
> idea to point that out, since it's not typical usage.
> For normal VBS it would be:
>
> cpu = InputBox("Enter name of remote computer.")

Woops.. I read his message a bit fast (and answered with equal
celerity) and I was sure he wrote "and hit enter"

Rob', ashamed to learn that 'normal' VBS isn't console -_-'
date: Fri, 6 Jun 2008 06:40:40 -0700 (PDT)   author:   RD

Re: How can I obtain the MAC address of a remote machine via a WMI   
Rob', ashamed to learn that 'normal' VBS isn't console -_-'

   I guess that depends on one's point of view.
If this were a Linux group I would have been
set upon by a pack of feral geeks for what I wrote. :)
date: Fri, 6 Jun 2008 10:31:40 -0400   author:   mayayana

Re: How can I obtain the MAC address of a remote machine via a WMI   
On 6 juin, 15:30, "Spin"  wrote:
> How would that work in a script?  The below doesn't quite work, I get an> error on line 4. :(
>
> 'Begin Script
> cpu = InputBox("Enter name of remote computer.")
> strComputer = "computername"
>
> Set objWMIService = GetObject _
> ("winmgmts:{impersonationLevel=impersonate}!\\" _
> & strComputer & "\root\cimv2")
>
> Set colAdapters = objWMIService.ExecQuery _
> ("Select * From Win32_NetworkAdapterConfiguration " _
> & "Where IPEnabled = True")
>
> For Each objAdapter in colAdapters
> WScript.Echo objAdapter.MACAddress
> Next
> 'End Script

Erm.. That would be
'Begin Script
strComputer = InputBox("Enter name of remote computer.")

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

Set colAdapters = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration " _
& "Where IPEnabled = True")

For Each objAdapter in colAdapters
WScript.Echo objAdapter.MACAddress
Next
'End Script

And you're done!
date: Fri, 6 Jun 2008 07:33:01 -0700 (PDT)   author:   RD

Re: How can I obtain the MAC address of a remote machine via a WMI   
> How would that work in a script?  The below doesn't quite work, I get an
> error on line 4. :(
>
> 'Begin Script
> cpu = InputBox("Enter name of remote computer.")
> strComputer = "computername"
>
> Set objWMIService = GetObject _
> ("winmgmts:{impersonationLevel=impersonate}!\\" _
> & strComputer & "\root\cimv2")
>

  I'm afraid I don't have any experience with remote
WMI. If strcomputer should be the name of your
remote PC then you want:

strcomputer = InputBox("Enter name of remote computer.")

  Then error-trap that to make sure that a name
was actually entered. strcomputer will return whatever
was in the InputBox prompt:

 If Len(strcomputer) = 0 then
   MsgBox "Error. Remote computer name is required."
... etc.

  So if your remote PC is named, say,
Harry, then hopefully strcomputer contains "Harry"
after InputBox returns.

  Then if
\\Harry\root\cimv2
is valid then you're all set.
date: Fri, 6 Jun 2008 10:36:53 -0400   author:   mayayana

Re: How can I obtain the MAC address of a remote machine via a WMI   
That worked!  You ROCK THE HOUSE!!!
date: Fri, 6 Jun 2008 10:55:23 -0400   author:   Spin

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us