Determine who is executing a winform application on fileserver

Posted on 2012-08-22
Last Modified: 2012-08-25
Hello experts,

We have deployed some winform application to a fileserver.
The exe files are copied to the fileserver and many clients execute them directly from the fileserver via a shortcut.
Our problem is when we try to release new versions, we have to find
every client that is executing the apps, tell them to close and only then we can release the new version.

Is there a way to receive the list of clients using a certain file, in the same way
I can receive it when managing open files via MMC?

We tried many ways, including Netapi32.dll, WMI etc.
I thought maybe there is a simple way to determine if a file is locked and receive the client that are locking the file.

Thanks in advance,
Question by:oferz
    LVL 37

    Expert Comment

    The exe should show up as an open file. On Windows Server 2008, in 'Server Management' I go to 'Roles'->'File Services'->'Share and Storage Manager' and click 'Manage Open Files...' and the exe files are there in the list.
    LVL 37

    Expert Comment

    Whatever OS you are using, it should be in the shared file management thing, wherever that is.

    We actually avoid that issue entirely to where we can roll out updates without worrying about who has what open.

    The directory looks something like this

    All program.exe does is search the directory for the latest version and then run it. So we can just drop updates in since we don't overwrite the old versions. Also if program.exe needs updating (rare) it's not a problem since it's never open for more than a few milliseconds.

    The only downside is you do run the risk of someone using the old version for days if they don't log out or shut down their computer overnight.

    Author Comment

    Thanks Tommy,
    We tried the solution that you are using.
    Some of the application must be open all the time, logging, birocracy issues, long story...
    We have to make sure the clients close all the exe files and then replace them with the new version.
    So I'm looking for a .net function to receive all the users holding the file.

    Thank you for the quick reply.
    LVL 37

    Expert Comment

    Oh okay. I get it. You're basically looking for a .NET API into the shared file administrative tool, right?
    LVL 37

    Accepted Solution

    As far as I know (and from looking it up some more just now) there isn't anything built in to do it. The way ProcessMonitor and the like do it is by loading a dynamic device driver (complicated). Why do you want to do it from .NET instead of the Server Management tool?

    The easiest way would probably be to track who has it open yourself. Write the form such that it logs when it's opened and by whom (Have you used environment variables? They are easy.) That way you can do it without any complex mumbo-jumbo.
    LVL 33

    Expert Comment

    by:Todd Gerbert
    It sounds like this particular application would benefit greatly from ClickOnce. It's not a particular good idea to publish an application in the manner that you are, if for no other reason than what you've just described and likely others.

    ClickOnce Deployment:

    It's intended specifically for the exact scenario you've just described, and makes updating your application a piece of cake.

    Author Closing Comment

    I was interested in the solution as I described above because we use several application in the same way. If I would find a way it would make our life easier for all our application at this customer.
    Just to let you know my progress so far, I found a way to show all shared folders at the file server, on one of this shared folder is all our exe files. The server does not execute the files as a service so they won't apprear in the process list but they should appear as open files like in the manage open files / sessions. Any way just to share with you my progress so far:

                Dim searcher As Management.ManagementObjectSearcher '("SELECT * FROM Win32_ConnectionShare")
                searcher = New Management.ManagementObjectSearcher("\\" & txtServerName.Text & "\root\cimv2", _
                "SELECT * FROM Win32_ConnectionShare") 'Win32_ConnectionShare") 'SELECT * FROM Win32_Share
                For Each connectionShare As Management.ManagementObject In searcher.[Get]()
                    ' Win32_Share
                    Dim antecedent As String = connectionShare("Antecedent").ToString()
                    Console.WriteLine("Antecedent: " + antecedent)
                    Dim share As New Management.ManagementObject(antecedent)

                    ' Win32_ServerConnection
                    Dim dependant As String = connectionShare("Dependent").ToString()
                    Console.WriteLine("Dependant: " + dependant)

    Thank you anyway,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    A short article about a problem I had getting the GPS LocationListener working.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    760 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

    15 Experts available now in Live!

    Get 1:1 Help Now