Users currently sharing an executable?

Posted on 2004-03-29
Last Modified: 2010-05-02
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.

Question by:NO_CARRIER
  • 2
LVL 48

Expert Comment

ID: 10709616
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
LVL 76

Accepted Solution

David Lee earned 280 total points
ID: 10710365
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.

Author Comment

ID: 10725554
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?
LVL 76

Expert Comment

by:David Lee
ID: 10728206
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

820 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