• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

How to know the users running the application and give message

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?
  • 4
1 Solution
David LeeCommented:
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).
swtirsAuthor Commented:

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.

David LeeCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
David LeeCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now