To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Display Modes
Old Jan 22nd, 2007, 08:33 PM   #1
lidds
Lively Member
 
Join Date: May 06
Posts: 124
lidds is an unknown quantity at this point (<10)
MAC address of server returns "Access Denied"

Can anyone help me please, I currently have a vb.net app that has an SQL database running on a companies server. I am currently trying to get the MAC address of the server using the below code. This code works fine for a networked computer but not for the server (I guess because it has additional security, which would make sense). Can anyone advise me on a better way to get this info or how I can solve my original code.

Note: I don't want to use a stored procedure (if this is possible) as people are able to tamper, and this is used for licensing of my app.

VB Code:
  1. ' this is the hostname of the server
  2. dim hostName as string = "server0001"
  3. Try
  4.                 Dim cls As New ManagementClass("\\" & hostName & "\root\cimv2", "Win32_NetworkAdapter", _
  5.                     New ObjectGetOptions(Nothing, TimeSpan.MaxValue, False))
  6.                 Dim col As Object
  7.                 col = cls.GetInstances()
  8.                 Dim obj As ManagementObject
  9.                 For Each obj In col
  10.                     If Not obj.Properties("MACAddress").Value Is Nothing Then
  11.                         msgbox(obj.Properties("MACAddress").Value.ToString().Replace(":", "-"))
  12.                     End If
  13.                 Next
  14.             Catch ex As Exception
  15.                 msgbox(ex.Message)
  16.             End Try

Thanks in advance

Simon
lidds is offline   Reply With Quote
Old Jan 23rd, 2007, 05:10 AM   #2
Asgorath
Frenzied Member
 
Asgorath's Avatar
 
Join Date: Sep 04
Location: Saturn
Posts: 2,036
Asgorath has a spectacular aura about (100+)Asgorath has a spectacular aura about (100+)
Re: MAC address of server returns "Access Denied"

The MAC address is stored in the registry Search key NetworkAddress.
Jorge
__________________
"The dark side clouds everything. Impossible to see the future is."
Asgorath is offline   Reply With Quote
Old Jan 23rd, 2007, 08:39 AM   #3
stanav
PowerPoster
 
stanav's Avatar
 
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,422
stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)
Re: MAC address of server returns "Access Denied"

Hi, try this function then... You can pass in either the host name or ip address and it'll spit out the MAC address for that machine.
VB Code:
  1. Private Function GetMACAddress(ByVal strHostNameOrIP As String) As String
  2.         Dim strIP As String = String.Empty
  3.         Dim IPHost As System.Net.IPHostEntry = Nothing
  4.         Dim outputResult As String = String.Empty
  5.         Dim psi As ProcessStartInfo = Nothing
  6.         Dim proc As Process = Nothing
  7.         Try
  8.             IPHost = System.Net.Dns.GetHostEntry(strHostNameOrIP)
  9.             strIP = IPHost.AddressList.GetValue(0).ToString
  10.             psi = New ProcessStartInfo()
  11.             psi.FileName = "nbtstat"
  12.             psi.RedirectStandardInput = False
  13.             psi.RedirectStandardOutput = True
  14.             psi.Arguments = "-A " & strIP
  15.             psi.UseShellExecute = False
  16.             psi.CreateNoWindow = True
  17.             proc = Process.Start(psi)
  18.             outputResult = proc.StandardOutput.ReadLine.Trim
  19.             While outputResult.ToUpper.IndexOf("MAC ADDRESS", 0) < 0
  20.                 outputResult = proc.StandardOutput.ReadLine.Trim
  21.             End While
  22.             proc.WaitForExit()
  23.         Catch ex As Exception
  24.             MsgBox(ex.Message)
  25.         End Try
  26.         Return outputResult
  27.     End Function
stanav is offline   Reply With Quote
Old Jan 23rd, 2007, 09:51 PM   #4
lidds
Lively Member
 
Join Date: May 06
Posts: 124
lidds is an unknown quantity at this point (<10)
Re: MAC address of server returns "Access Denied"

I have tried your code but unfortunately it does not seem to work on the server but does work on my computer, maybe it is another security issue.

It throws an error 'Object reference not set to an instance of an object'

Thanks

Simon
lidds is offline   Reply With Quote
Old Jan 24th, 2007, 08:34 AM   #5
stanav
PowerPoster
 
stanav's Avatar
 
Join Date: Jul 06
Location: Providence, RI - USA
Posts: 7,422
stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)stanav is a name known to all (1000+)
Re: MAC address of server returns "Access Denied"

Quote:
Originally Posted by lidds
I have tried your code but unfortunately it does not seem to work on the server but does work on my computer, maybe it is another security issue.

It throws an error 'Object reference not set to an instance of an object'

Thanks

Simon
I use this code to get the MAC address of the systems on my LAN (both servers and client PCs)... I works everytime. I never had any problem with it.
So I really don't know why it doesn't work for you.... Can you verify this: open command prompt and type in "nbtstat -a serverName" or "nbtstat -A xxx.xxx.xxx.xxx" (where xxx.xxx.xxx.xxx is the IP address of the server) then press enter key. If the command runs successfully then the problem is from somewhere else, not from the code I showed you.

Last edited by stanav; Jan 24th, 2007 at 08:44 AM.
stanav is offline   Reply With Quote
Old Jan 24th, 2007, 08:53 AM   #6
Asgorath
Frenzied Member
 
Asgorath's Avatar
 
Join Date: Sep 04
Location: Saturn
Posts: 2,036
Asgorath has a spectacular aura about (100+)Asgorath has a spectacular aura about (100+)
Re: MAC address of server returns "Access Denied"

It works fine on my computer. Can't you search the server's registry, it should be easy if you have a administrative account.
__________________
"The dark side clouds everything. Impossible to see the future is."
Asgorath is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:26 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.