How to know the users running the application and give message

Posted on 2004-11-23
Last Modified: 2006-11-17
We have shared an application from win2k server, and in need to know a way to identify the windows users currently running the application. We want to send customized messages to the users connected. How could this be done?
Question by:swtirs
    LVL 76

    Expert Comment

    by:David Lee
    There are several possibile ways of doing this.

    1.  Write a program that enumerates all the connections that have the app's exe open.
    2.  Modify the app and have it create a connection list.  As users start the program they are entered in the connection list.  When they exit they are removed.
    3.  Create a messenger routine in the app.  Have it check a central point periodically for new messages.  Send messages to the users by posting the message in the central point (e.g. in a database or a file located in a certain folder).

    Author Comment


    Method you suggested fails when application crashes or when users abort running the application. Further I would like to have a source code sample that enumerates all the active connection to the exe and then send message to the workstations running the application.

    LVL 76

    Expert Comment

    by:David Lee
    Here's the code for enumerating all the connections to a given file and sending them a message.  The message in this case is a Net Send message.  Make the changes per my comments in the code.  I tested this code in my environment (Windows 2000 AD domain, XP workstation) and it worked as advertised.

    Dim colUsers as Collection

    Private Sub cmdGetOpenFileUsers_Click()
        'Include a project reference to Active DS Type Library
        On Error Resume Next
        Dim objFSO As IADsFileServiceOperations, _
            objResource As IADsResource, _
            WshShell As Object, _
            strComputer As String, _
            strFilename As String, _
            strUsername As String, _
            strPath As String, _
            strMessage As String
        'Change eeBDF to the name of the computer hosting the exe
        strComputer = "eeBDF"
        'Change notepad.exe to the name of the exe you want to check on
        strFilename = "notepad.exe"
        'Change strMessage to the message you want to send to those with the file open
        strMessage = "Please exit the Notepad now."
        Set colUsers = New Collection
        Set objFSO = GetObject("WinNT://" & strComputer & "/LanmanServer")
        Set WshShell = CreateObject("WScript.Shell")
        If (IsEmpty(objFSO) = False) Then
            For Each objResource In objFSO.Resources
                objResource.GetInfoEx Array("user", "path"), 0
                strUsername = ""
                strPath = ""
                strUsername = objResource.Get("user")
                strPath = objResource.Get("path")
                If (Not strUsername = "") And (Not Right(strUsername, 1) = "$") Then
                    If (InStr(1, strPath, strFilename, 1) <> 0) Then
                        colUsers.Add strUsername
                        WshShell.Run "CMD /C net send " & strUsername & " " & strMessage, 1, False
                    End If
                End If
        End If
        Set objResource = Nothing
        Set objFSO = Nothing
    End Sub
    LVL 1

    Accepted Solution

    if you are using ACtive Directory, it is simple to get the users name; let me know if you are and I will send you a sample of the code.
    LVL 76

    Expert Comment

    by:David Lee
    LVL 76

    Expert Comment

    by:David Lee
    Normally I don't comment on a person's decision about how to close a question, but I'm going to this time.  Why would you select a comment as the best answer to your question over code that does exactly what you asked for?  

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    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…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    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…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    755 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

    16 Experts available now in Live!

    Get 1:1 Help Now