Users currently sharing an executable?

My application is on a shared network drive.  Anyone in the department can open / access it.

However, sometimes in the evenings when I want to put a new build on the network there is a sharing violation.  Some users lock their computer with the application open.

I'd like to be able to track which users are currently using the application.  Perhaps a text file of some type with a time-stamp, and is updated every 5 minutes or so... (timer), if it's not updated it times out and removes the user from the list?

Is there another method to do this?  I'd just like to track which users have it open.. so if necessary I can unlock / reboot their systems.

Who is Participating?
David LeeCommented:
How about using a timer control in the application itself so that after a certain amount of inactivity the program shuts itself down?  That sounds like a safer approach to me than trying to maintain a list of who has the program open.  The problem I see with the list approach is that there are probably situations that could arise where the text file was not updated yet the program was still running on someone's PC.  An inactivity timer would cause the program to shut itself down without any intervention.  Another approach would be to add a routine that'd allow you to shut the application down remotely.  For example, you could have the program check periodically for a certain file or for a value in a file or database.  On finding that file or value all instances of the application would close themselves out.  For example, you could create a file called Configuration.Ini.  Write a routine that checks that file periodically and reads a value called ForceShutdown.  If ForceShutdown is set to True, then the application shuts itself down.  Otherwise it goes about its business.  You could expand on that concept some to control access to the program as certain times.  Say you need to apply a patch during the business day, when staff are most likely to be using the app.  Instead of ForceShutdown lets say the value is called OperatingMode.  When OperatingMode is set to Production, then the app runs like normal.  But, when you set OperatingMode to Administrative, then not only do active instances of the program shut down, but anyone who tries to start the app will receive a polite little pop-up telling them the app is currently unavailable.  In addition to the routine that check for the OperatingMode periodically, you'd also need to write a little code that'd check the value as the app starts up.  Both would be very simple to do.
If there is a database attached to it you can have your program looking for a field (every minute) yes/no if yes then shutdown  and when you wanna update then just update that field
NO_CARRIERAuthor Commented:
yes, the exe is currently hooked up to a database... (does not connect at runtime though.)
Forcing to shut down is an option, but it could become annoying to some of the rep's here.

Would there be a problem of simply adding their lanID to a text file when the open the application, and remove their name on unload?
David LeeCommented:
Adding the LAN ID to a text file when the app starts and removing it when it unloads presumes that the app will always shut down gracefuly.  What happens when it doesn't?  There are any number of situations that could bypass a graceful shut down.  Things like a the PC losing power, an OS crash, an employee terminating the app via task manager, etc.  Any time the app didn't go through a normal shut down, then that LAN ID would still be there in the text file leaving you to believe that the app was still running on some PC.  How would you handle startup if for some reason the app couldn't write to the file holding the LAN IDs?  That's probably less of an issue than the app not shutting down properly, but it is still a possibility.

I'd think the second option I discussed would be the best.  Add a timer control and check for a given file or an entry in a file periodically (i.e. some triggering option).  If the app sees the trigger, then it pops a nice notice up on screen telling the user that it's going to shut down in a certain amount of time, then goes through an orderly shutdown.  The code for this is very simple.  Here's an example:

Dim objFSO as FileSystemObject

Private Sub Timer1_Timer()
    If objFSO.FileExists("C:\KillApp.Txt") Then
        'Shutdown code goes here.
    End If
End Sub

Private Sub Form_Load()
    Set objFSO = New FileSystemObject
    Timer1.Interval = 60000    'Check for the file once a minute
End Sub
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.