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

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


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
By the way to test it just change %username% to any specific username that already exists.
rgfordAuthor Commented:
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?
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

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
rgfordAuthor Commented:
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.
rgfordAuthor Commented:
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:


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.
Steve KnightIT ConsultancyCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.