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?
swtirsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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).
0
swtirsAuthor Commented:
BlueDevilFan

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.

0
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
        Next
    End If
    Set objResource = Nothing
    Set objFSO = Nothing
End Sub
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

dpalmeCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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?  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

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.