Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I find user name by using IP or machine name? 1

Status
Not open for further replies.

UGrad

Programmer
Oct 15, 2002
40
0
0
CA
I am trying to write a simple VB program to run on my INTRANET. All I want is I input the IP or machine name of a remote computer, then the program will return the user who is currently logged on that computer.
Can anyone help me out?
 
You can use WMI for this. See for detailed info on WMI and the requirements to run it.

Here is a solution using WMI:

Code:
Dim CompSystem As Object
Dim Comp As Object

Set CompSystem = GetObject("winmgmts:{impersonationLevel=impersonate}//your_computer_name").ExecQuery("select * from Win32_ComputerSystem")


For Each Comp In CompSystem
    'there will only be one
    Debug.Print Comp.UserName
Next
 
Hi bjd4jc,
Thanks for the reply. It worked.
 
I was also looking for something like this...why do I get a Message "Access Denied" ?

 
Because you probably do not have administrator rights on the target machine... did you read the msdn articel that I pointed UGrad to?
 
Hi bjd4jc,
It works fine in VB and I can use it to get all the user names on my LAN.
I am trying to compile this code into a dll and run it in ASP pages.
What I get is this error msg:
---------------------------------------------
NetworkTool error '80041003'
Automation error
/survey/report/imnu.asp, line 24
---------------------------------------------
NetworkTool is the dll object.
Can you help me out?
 
You will not be able to have Anonymous security on your Virtual Directory. I have it working with a COM DLL and ASP here is my code:

ActiveX DLL Project Called NetworkTool
Class Called UserNames

Code in Class UserNames:

Code:
Public Function ReturnNetworkName(ComputerName As String) As String
    Dim CompSystem As Object
    Dim Comp As Object
    
    Set CompSystem = GetObject("winmgmts:{impersonationLevel=impersonate}//" & ComputerName).ExecQuery("select * from Win32_ComputerSystem")
    
    ReturnNetworkName = ""
    For Each Comp In CompSystem
        'there will only be one
        ReturnNetworkName = Comp.UserName
    Next
End Function

Compile DLL. Make sure it is registered on Web Server (BTW what is your web server??)

Code in the asp Page
Code:
<%    Dim NetTool
    
    Set NetTool = CreateObject("NetworkTool.UserNames")
    
    Response.Write NetTool.ReturnNetworkName("ComputerName")
%>

This works. I haven't tested it from anything but my XP Machine though.
 
tested on W2K server and it works there too.
 
Hi bjd4jc,
I found out where the problem is, just as you said, it has something to do with the security.
I changed the file security for my asp page and it's working now.

Thanks agian =)
 
I m running exe on client machine but its database is on server machine.i want the path of my application which is on server.Can anyone help me out?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top