Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to detect when a user logs on from a vb service

Posted on 2008-10-10
4
Medium Priority
?
223 Views
Last Modified: 2013-11-07
I have a vb program that runs as a service. I currently have code that can get the user that is currently logged in, but I have no idea when to run it, so it is currently in a timer. All I need is an event that is triggered when a user logs on. I attatched the code I use to get the current user in case anyone is interested.
Dim User As String = ""
            Dim q1 As New ManagementObjectSearcher("select * from Win32_ComputerSystem")
            Dim qc As ManagementObjectCollection = q1.Get
            For Each Mo As ManagementObject In qc
                User = Mo("username")
                Exit For
            Next

Open in new window

0
Comment
Question by:andy148
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 13

Expert Comment

by:SameerJagdale
ID: 22693607
0
 

Author Comment

by:andy148
ID: 22717560
I tried the link, but it didn't help much, I'm looking for an event that is fired when a user logs in, preferably without changing any settings on their computer.
0
 
LVL 13

Accepted Solution

by:
SameerJagdale earned 2000 total points
ID: 22740874
check the following code:
 

Private Shared Sub Main(ByVal args() As String)
        Dim w As ManagementEventWatcher = Nothing
        Dim q As WqlEventQuery = New WqlEventQuery
        q.EventClassName = "__InstanceOperationEvent"
        q.WithinInterval = New TimeSpan(0, 0, 3)
        ' query interval
        q.Condition = "TargetInstance ISA 'Win32_LogonSession'"
        w = New ManagementEventWatcher(q)
        AddHandler w.EventArrived, AddressOf Me.LogonEventArrived
        w.Start
        Console.ReadLine
    End Sub
    
    Public Shared Sub LogonEventArrived(ByVal sender As Object, ByVal e As EventArrivedEventArgs)
        'Get the Event object and display it
        For Each pd As PropertyData In e.NewEvent.Properties
            
        Next
    End Sub

Open in new window

0
 

Author Closing Comment

by:andy148
ID: 31505239
thanks!!
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 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