Solved

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

Posted on 2006-06-15
8
253 Views
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

Thanks

George
0
Comment
Question by:rgford
  • 4
  • 3
8 Comments
 
LVL 8

Accepted Solution

by:
Here2Help earned 500 total points
Comment Utility
Hey.

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:

nbtscan 192.168.0.1-4  

^this scans IP addresses 192.168.0.1-192.168.0.4 and displays logged on user names for each machine.
E.G.
==============================================
IP address       NetBIOS Name     Server    User             MAC address
------------------------------------------------------------------------------
192.168.1.2      MYCOMPUTER                 JDOE             00-a0-c9-12-34-56
192.168.1.5      WIN98COMP    <server>  RROE             00-a0-c9-78-90-00
192.168.1.123    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.

=======================

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

::Place in the IP address range of your network
nbtscan 192.168.0.1-4 >%HomePath%\Workstations.txt
CLS
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

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

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

:EOF
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!

0
 
LVL 8

Expert Comment

by:Here2Help
Comment Utility
By the way to test it just change %username% to any specific username that already exists.
0
 

Author Comment

by:rgford
Comment Utility
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?
0
 
LVL 8

Expert Comment

by:Here2Help
Comment Utility
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:
http://www.grc.com/stm/shootthemessenger.htm

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.


ECHO OFF
nbtscan 192.168.0.1-4 >C:\Workstation.txt
CLS
Findstr /I  "%Username%" C:\Workstation.txt >>C:\Founditems.txt

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

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

:Loggedin

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%
Echo.
Pause

:EOF
Del C:\Workstation.txt
Del C:\Founditems.txt
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:rgford
Comment Utility
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.
0
 

Author Comment

by:rgford
Comment Utility
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:

\\machine-1
\\machine-2
\\server2

etc.
0
 
LVL 8

Expert Comment

by:Here2Help
Comment Utility
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 192.168.0.1 etc here is a sneaky time saving shortcut that already comes with nbtscan.  Run this command.

nbtscan -e 192.168.0.1-244 >>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 192.168.0.1-4 >>C:\Workstation.txt
to
nbtscan -f C:\IP.txt >>C:\Workstation.txt

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

Expert Comment

by:Steve Knight
Comment Utility
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
:message
 net send %computername% "%lastlogin%.  Current PC is %computername%."
:next
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
0

Featured Post

The problems with reply email signatures

Do you wish that you could place an email signature under a reply? Well, unfortunately, you can't. That great Exchange/Office 365 signature you've created will just appear at the bottom of an email chain. What a pain! Is there really no way to solve this? Well, there might be...

Join & Write a Comment

Suggested Solutions

Several part series to implement Internet Explorer 11 Enterprise Mode
The use of stolen credentials is a hot commodity this year allowing threat actors to move laterally within the network in order to avoid breach detection.
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…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now