Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Warn users when they are logged in on two machines (or more) together (multiple concurrent logins)

Posted on 2006-06-15
Medium Priority
Last Modified: 2013-12-28
I am looking for a way of warning users when they are logged in on more than one machine. I don't need them to be logged off automatically, jujst sent a netmsg telling them that they are already logged on at <machinename>

However, I haven't used net messages since the days on NT4, and I think the service that runs them on XP (we run a50-node XPSP2 network with WS2k3 domain) is stopped by default after Service Pack 2.

Could I do this using a batch file to check if a user is logged on?

Any suggestions appreciated


Question by:rgford
  • 4
  • 3

Accepted Solution

Here2Help earned 2000 total points
ID: 16916578

Maybe you could use a central login .bat script (or call a bat script from within a users normal login script) so that when a user logs in it checks through all your workstations for the name of the user that is trying to login.  Then if it finds a match you can give them a warning box (or log them off!).

I thought I'd give your question a try seen as there hasn't been any posts and this is the closest I've got (there probabily is an easier way out there).

I downloaded a commandline program called 'NBTSCAN' from http://www.inetcat.org/software/nbtscan.html

and ran this command at the prompt:


^this scans IP addresses and displays logged on user names for each machine.
IP address       NetBIOS Name     Server    User             MAC address
------------------------------------------------------------------------------      MYCOMPUTER                 JDOE             00-a0-c9-12-34-56      WIN98COMP    <server>  RROE             00-a0-c9-78-90-00    DPTSERVER    <server>  ADMINISTRATOR    08-00-09-12-34-56

Then basically I created a batch to search for the %Username% from the command to see if could be found.  If the %username% is found then you know that the user is logged in else where.  If no user name is found then you know it's OK.

The only problems with this batch I've created is:

-Users have to have unique usernames.
-The user's name can't be the same as a machine name.

Here is what I've came up with:

-Place the 2 files downloaded from the website on to your server and make sure you put in the full path for the nbtscan command.
-This would be part of the users login script.


If Exsist %HomePath%\Workstations.txt del %HomePath%\Workstations.txt

::Place in the IP address range of your network
nbtscan >%HomePath%\Workstations.txt
Find /I "%Username%" %HomePath%\Workstations.txt

::Checks to see if the user is alread present on the network
If %Errorlevel% == 1 goto Notloggedin
If %Errorlevel% == 0 goto Loggedin

::Carry on with other commands
Echo Not logged in anywhere else!
goto EOF

::Enter Message to say user is already logged in elsewhere.
Echo *Please note you are already logged in to the above Workstation(s)*

Del %HomePath%\Workstations.txt


Copy the above (between the ==) into notepad and save it as something like 'Userlogins.bat'

It *probably* wont work 100% but it's worth playing around with (great way to learn).  I havn't really had the chance to test it so much..maybe you can have a try and see how it goes.

 It's not going to popup a windows style dialogue box with a message but instead displays all the info in the DOS box which isn't too glamorous I know!

There might be some pitfalls to this method but I've enjoyed it any ways!


Expert Comment

ID: 16916597
By the way to test it just change %username% to any specific username that already exists.

Author Comment

ID: 16930218
Here2help, that's great, thankyou. I love classic batch scripts as well!

There are no machine names the same as user names and no duplicate usernames, so that's not a problem. However, I really do need to have a dialog/windows error box pop-up. These are are really inexperienced and anything without pretty symbols scares them.

It seems a shame for your thorough solution to fall at this hurdle though...can't a warning dialo with a custom message somehow be triggered from a command line?
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Expert Comment

ID: 16930534
OK. I've managed to create a Windows Popup for you to display the message but requires Windows Messenger service to be running on all the machines.  Some people use the Windows Messenger service to send spam or advertise to your PC, although it's not harmful but can be annoying if you do get advertised at.

This site has more info:

If you don't want Windows Messenger Service to be running, then we'll have to find a different solution.

This batch only alerts the user they're already logged on to one other PC, even if they could be logged onto multiple PC's!!!

If you want to try it out here is the code.

nbtscan >C:\Workstation.txt
Findstr /I  "%Username%" C:\Workstation.txt >>C:\Founditems.txt

If %Errorlevel% == 1 goto Notloggedin
If %Errorlevel% == 0 goto Loggedin

::Carry on with other commands
Echo Not logged in anywhere!
goto EOF


FOR /F " tokens=1* delims= " %%I in (C:\Founditems.txt) do (Set IP=%%I)
FOR /F " tokens=2* delims= " %%M in (C:\Founditems.txt) do (Set PC=%%M)

::Friendly Message
Net Send %Computername% Please note you are already logged on at PC: %PC% IP Address: %IP%

Del C:\Workstation.txt
Del C:\Founditems.txt

Author Comment

ID: 16979479
here2help, thanks - I'll try that this week. Not a problem to have Messenger running, as long as I can enable it through group policy. We have a firewall which should get rid of the spam.

Author Comment

ID: 16979581
Works a treat!

Setting service options in group policy is a cinch too.

One small thing....scanning the list of IPs takes a bit of time (say 10-15) seconds, and logon times with roaming profiles are lengthy anyway. the main problem is scanning loads of IPs that are assigned to printers etc, and they "wake up" before rejecting the request. Is there any way of telling the script to look in a file for the UNC names of the machines? I ask because I already have a file with such a list used by another script to reboot certain machine every night - and it's these machines I want to check. The file looks like:



Expert Comment

ID: 16983216
Do your workstations have static IP's or are they dished out by DHCP?  The reason I'm asking is that the nbtscan program can only scan IP addresses not Hostnames.  So yes, a file containing all the IP addresses of machines you want to scan can be created and fed into nbtscan.  If DHCP is being used for IP addressing chances are Hostname to IP address are going to change day by day and you'll end up scanning machines that you dont want to scan.

However if you do have Static IP's that's a bonus.  To save you time changing \\machine-1 to etc here is a sneaky time saving shortcut that already comes with nbtscan.  Run this command.

nbtscan -e >>C:\Host2IP.txt

-Change the IP address range to the one of your network.
-The output file of the Host2IP.txt will be placed on to C: , change if applicable.
-This scan WILL "wake up" your Printers.

Now all you have to do is open up C:\Host2IP.txt in notepad, select all the IP's that need to be scanned, get rid of IP's you don't need and simply select and delete all the Hostnames.

Once you've got all the IP's you want to scan, save the file as IP.txt or anything of your choosing and place the file in the same dir as nbtscan.exe

You only need to edit this line:
nbtscan >>C:\Workstation.txt
nbtscan -f C:\IP.txt >>C:\Workstation.txt

Make sure you put in the correct path to the IP.txt file.
LVL 43

Expert Comment

by:Steve Knight
ID: 17039343
How about creating a file in the user's home drive which contains their last login details then shows it to the user if they have already logged in?

In login script (roughly, change the home drives etc. ):

net use h: \\server\home\%username%
if not exist h:\lastlogin.txt goto next
 for /f "tokens=*" %%a in (h:\lastlogin.txt) do set lastlogin=%%a &goto message
 net send %computername% "%lastlogin%.  Current PC is %computername%."
echo Last login for %username% was on %computername% at %date% %time% > h:\lastlogin.txt
In logout script

del h:\lastlogin.txt
net use H: /delete

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension . This reminded me of questions that come up here at EE along the lines of, "How can I tell the type of file from its cont…
In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question