Results 1 to 6 of 6

Thread: MAC address of server returns "Access Denied"

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    170

    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.  
    4. Try
    5.                 Dim cls As New ManagementClass("\\" & hostName & "\root\cimv2", "Win32_NetworkAdapter", _
    6.                     New ObjectGetOptions(Nothing, TimeSpan.MaxValue, False))
    7.                 Dim col As Object
    8.                 col = cls.GetInstances()
    9.  
    10.                 Dim obj As ManagementObject
    11.                 For Each obj In col
    12.                     If Not obj.Properties("MACAddress").Value Is Nothing Then
    13.                         msgbox(obj.Properties("MACAddress").Value.ToString().Replace(":", "-"))
    14.                     End If
    15.                 Next
    16.             Catch ex As Exception
    17.                 msgbox(ex.Message)
    18.             End Try

    Thanks in advance

    Simon

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    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."

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    170

    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

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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 09:44 AM.

  6. #6
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    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."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width