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

Posted on 2006-06-15
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3

Accepted Solution

Here2Help earned 500 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

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?
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.


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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

628 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