Mapping users to workstations in AD

XOR != OR

[H]F Junkie
Joined
Jun 17, 2003
Messages
11,547
Has anybody solved this particular problem? I have thoughts about writing a system tray app that would upload username/computername sets to a database server somewhere so I can do a quick look up and see who's where ( in case user X calls in, I can quickly find their computer ).

I can't be the first one to come across this problem.
 
Sysinternals PsLoggedIn tool should do the trick.
 
While sysinternals is cool, that tool is problematic for a few reasons. First, it takes a while to return results. Second, it's flaky ( at least on the networks I want to use it on ).

Instead, I threw this together;
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package identsql;

import java.sql.*;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.awt.*;
import java.awt.event.*;


/**
 *
 * @author skennedy
 */
public class identSQL implements Runnable {
            // TODO code application logic here
        Statement stmt = null;
        ResultSet rs = null;
        Connection con = null;
        int sleepTime = 1000 * 60 * 5; // 5 minutes between username/computername refresh
        String dbUsername = null;
        String dbPassword = null;
        String dbDatabase = null;
        String dbServer   = null;
        Thread t;

        public identSQL() {
            t = new Thread(this);
            t.start();

            dbUsername = "username";
            dbPassword = "password";
            dbDatabase = "database";
            dbServer   = "server";

            //System.out.println("Hi there!");

            final TrayIcon trayIcon;

if (SystemTray.isSupported()) {

    SystemTray tray = SystemTray.getSystemTray();
    Image image = Toolkit.getDefaultToolkit().getImage("displays.ico");

    MouseListener mouseListener = new MouseListener() {

        public void mouseClicked(MouseEvent e) {
 
        }

        public void mouseEntered(MouseEvent e) {
 
        }

        public void mouseExited(MouseEvent e) {
 
        }

        public void mousePressed(MouseEvent e) {
 
        }

        public void mouseReleased(MouseEvent e) {
 
        }
    };

    ActionListener exitListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            
            System.exit(0);
        }
    };

    PopupMenu popup = new PopupMenu();
    MenuItem defaultItem = new MenuItem("Exit");
    defaultItem.addActionListener(exitListener);
    popup.add(defaultItem);

    trayIcon = new TrayIcon(image, "IdentSQL", popup);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            trayIcon.displayMessage("Action Event",
                "An Action Event Has Been Performed!",
                TrayIcon.MessageType.INFO);
        }
    };

    trayIcon.setImageAutoSize(true);
    trayIcon.addActionListener(actionListener);
    trayIcon.addMouseListener(mouseListener);

    try {
        tray.add(trayIcon);
    } catch (AWTException e) {
        System.err.println("TrayIcon could not be added.");
    }

} else {

    //  System Tray is not supported

}
            

        }

        public void run() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String connectionUrl = "jdbc:mysql://" + dbServer +"/"+ dbDatabase +"?"+
                                   "user="+ dbUsername +"&password="+dbPassword;
            con = DriverManager.getConnection(connectionUrl);
        } catch (SQLException e) {
            System.out.println("SQL Exception: " + e.toString() );
        } catch (ClassNotFoundException e) {
            System.out.println("Class Not Found Exception: " + e.toString() );
        }




        try {
            stmt = con.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        Map<String,String> env = System.getenv();
        String computername = env.get("COMPUTERNAME");
        String username = env.get("USERNAME");
        String userSQL = null;

        do{

        String checkUserSQL = String.format( "SELECT count(*) FROM ident WHERE username='%s' AND computername='%s'", username, computername );
        try {
            rs = stmt.executeQuery(checkUserSQL);
            rs.next();
            int recordExist = rs.getInt("count(*)" );
            if( recordExist == 1 ) {
                // Record exists, update
                userSQL = String.format( "Update ident SET ts=CURRENT_TIMESTAMP() WHERE username='%s' AND computername='%s'", username, computername );
            } else {
                userSQL = String.format( "INSERT into ident ( computername, username ) VALUES ( '%s', '%s' )", computername, username );
            }
           // System.out.println( userSQL );
            stmt.executeUpdate(userSQL);

        } catch (SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
            try {
                Thread.sleep( sleepTime );
            } catch (InterruptedException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        } while(true);
        }



    }

The idea intrigued me, so I went ahead and prototyped it. Essentially, this lives in the system tray and reports username/computername to a mysql server every 5 minutes. This has the benefit of letting me get results immediately, plus I think I might code up a screen where I can get a list and launch vncviewer automatically if I need to.
 
we use LANDesk for that kinda stuff.

but I would usually just have the user get me the name of the computer, since it's only a couple clicks
 
but I would usually just have the user get me the name of the computer, since it's only a couple clicks
Ah...I think we might be talking about two different kinds of users. This is how that would play out,

me: "Ok, can you tell me the name of your computer? It's on the desktop, labeled something like p11-" ( naming convention based off of location )
user: "What?"
me: "I need to know which computer you are logged in to so I can log in remotely and help. The computer name is on your desktop, it starts with p11-"
user: "Uh...hmm..is it <name of random word document>< which doesn't start with p11->"
me: "No, it'd start with p11-"
user: "Should I reboot?" ( already having clicked the reboot button )
me: "no, I just need the name of the computer."
after a minute or so, the computer is back up and ready to be logged in
user: "Ok, it's ready to login, go ahead"
me: "I'll just head over, hang tight"

I wish I were making that up.
 
Since we are a call center, and personnel move around day to day from computer to computer, we use a login script that grabs the computer name, username, time, logon, logoff, reboot, dirty logon, dirty log off and inserts it into a database. Then if someone says "Joe Smith's computer is broken" we can look at the web interface (or other interface) put in Joe Smith's name and BOOM it tells me who logs in.

We also use SMS, but that data is not update to date as it is a day behind.
 
Ah...I think we might be talking about two different kinds of users. This is how that would play out,

me: "Ok, can you tell me the name of your computer? It's on the desktop, labeled something like p11-" ( naming convention based off of location )
user: "What?"
me: "I need to know which computer you are logged in to so I can log in remotely and help. The computer name is on your desktop, it starts with p11-"
user: "Uh...hmm..is it <name of random word document>< which doesn't start with p11->"
me: "No, it'd start with p11-"
user: "Should I reboot?" ( already having clicked the reboot button )
me: "no, I just need the name of the computer."
after a minute or so, the computer is back up and ready to be logged in
user: "Ok, it's ready to login, go ahead"
me: "I'll just head over, hang tight"

I wish I were making that up.

well... I dunno. I've worked with some VERY un-savvy people. And I have had some people VERY close to this!
Along with the ones who don't understand you when you say
"Ok, right-click on the My Computer icon on the Windows Desktop"
user: "huh?"

something else you could do if you wanted...
bginfo
You could use it to display computer name and IP, and place a shortcut to it in the Start Menu where it would be easy for the user to find (ie, above Microsoft/Windows Update), then make it part of your base image for PC deployment (if you do it that way, anyway).
 
Ah...I think we might be talking about two different kinds of users. This is how that would play out,

me: "Ok, can you tell me the name of your computer? It's on the desktop, labeled something like p11-" ( naming convention based off of location )
user: "What?"
me: "I need to know which computer you are logged in to so I can log in remotely and help. The computer name is on your desktop, it starts with p11-"
user: "Uh...hmm..is it <name of random word document>< which doesn't start with p11->"
me: "No, it'd start with p11-"
user: "Should I reboot?" ( already having clicked the reboot button )
me: "no, I just need the name of the computer."
after a minute or so, the computer is back up and ready to be logged in
user: "Ok, it's ready to login, go ahead"
me: "I'll just head over, hang tight"

I wish I were making that up.

Because group policy and forcing something on like bginfo is out of the question?

I did that a while after we had a new director and tech start. I was the only person who knew my way around that place.

What is the name of your machine? It's in the top right hand corner of the screen with your username and ip address.

If you want I'm pretty sure i still have the .bgi settings i used for it if you want it zipped up and sent your way
 
Because group policy and forcing something on like bginfo is out of the question?
Yes and no. Yes, it's out of the question to change the user's background. But no, bginfo isn't out of the question entirely. It seems it can be used to log information to a remote server, which would be ideal, without any graphic notification to the user.

You have to understand, what I posted up there isn't one of my "greatest support calls of all times". It was merely the most recent example I had in memory. You know those stories about cdroms being used as drink holders? Not fake. My users' strongest skills lay in customizing the look and feel of their workstations, and for all they don't know, they DO know when an icon has been moved. I will connect up via VNC, and due to how it's configured the background will go away. No matter how many times I do this, it's always new to them and I always have to assure them that yes, it will come back once I disconnect.

I still shudder about the day we forced out the XP start menu style ( last year ).

So less is more here. bginfo looks like it may cover what we were after, but I will admit I'm a little sad about not using my java. :)
 
The way I worked something similar was to use VBScript in the login script to get the computer and username from WMI and then write it to a SQL database. It's not fool proof but you could knock out the VBScript in a couple of hours and it would get most of your users.
 
There is a network inventory program that I've mentioned a few times, called LANSweeper.
The basic version is free..and it provides an incredible amount of information.
You can do a search by username, and it will show you the last computer they've logged in on. Very quickly and easily.
It's easy to deploy, just runs on a server with some version of SQL (even express), and IIS. You deploy a little executable via GPO, and all members of the AD will be reporting in.
 
Do they have a personal folder on a server? If so you can get the info there. In the Computer Management menu you go to shares and under it you got a Session menu. As long as they have the folder mapped at login, you will see their username and ip/comp there.

a dumb solution but it works
 
These are all excellent suggestions, but they don't quite fit what we're after. Is LANSweeper capable of telling you if a user is logged in to more than one workstation?
 
These are all excellent suggestions, but they don't quite fit what we're after. Is LANSweeper capable of telling you if a user is logged in to more than one workstation?

Probably...I'll have to test that next week.
Seriously, it gives you a wealth of data which IT can find useful.
Make/model of computer, hardware specs, amount of freespace on drive, when the PC was joined to your domain (useful for estimating when to cycle out old rigs), full software audit, etc.
 
Use a vb script to determine if a user is logged in. Or just RDC to the computer, and it will let you know if someone if logged in with a message box.
 
Back
Top