|
-
Jan 22nd, 2007, 09:33 PM
#1
Thread Starter
Addicted Member
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:
' this is the hostname of the server
dim hostName as string = "server0001"
Try
Dim cls As New ManagementClass("\\" & hostName & "\root\cimv2", "Win32_NetworkAdapter", _
New ObjectGetOptions(Nothing, TimeSpan.MaxValue, False))
Dim col As Object
col = cls.GetInstances()
Dim obj As ManagementObject
For Each obj In col
If Not obj.Properties("MACAddress").Value Is Nothing Then
msgbox(obj.Properties("MACAddress").Value.ToString().Replace(":", "-"))
End If
Next
Catch ex As Exception
msgbox(ex.Message)
End Try
Thanks in advance
Simon
-
Jan 23rd, 2007, 06:10 AM
#2
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."
-
Jan 23rd, 2007, 09:39 AM
#3
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:
Private Function GetMACAddress(ByVal strHostNameOrIP As String) As String
Dim strIP As String = String.Empty
Dim IPHost As System.Net.IPHostEntry = Nothing
Dim outputResult As String = String.Empty
Dim psi As ProcessStartInfo = Nothing
Dim proc As Process = Nothing
Try
IPHost = System.Net.Dns.GetHostEntry(strHostNameOrIP)
strIP = IPHost.AddressList.GetValue(0).ToString
psi = New ProcessStartInfo()
psi.FileName = "nbtstat"
psi.RedirectStandardInput = False
psi.RedirectStandardOutput = True
psi.Arguments = "-A " & strIP
psi.UseShellExecute = False
psi.CreateNoWindow = True
proc = Process.Start(psi)
outputResult = proc.StandardOutput.ReadLine.Trim
While outputResult.ToUpper.IndexOf("MAC ADDRESS", 0) < 0
outputResult = proc.StandardOutput.ReadLine.Trim
End While
proc.WaitForExit()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return outputResult
End Function
-
Jan 23rd, 2007, 10:51 PM
#4
Thread Starter
Addicted Member
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
-
Jan 24th, 2007, 09:34 AM
#5
Re: MAC address of server returns "Access Denied"
 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.
-
Jan 24th, 2007, 09:53 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|