How to receive event when network is connected and also when user logs in

前端 未结 6 1443
再見小時候
再見小時候 2021-02-06 02:32

I have a service that runs and I\'d like to receive notification when:

a) the network is connected.

b) when a user logs in to the machine.

How can I do

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-06 03:28

    To find out when the network is connected, add a handler for the NetworkAvailabilityChanged in the System.Net.NetworkInformation.NetworkChange class.

    One simple way to find out when a user logs in is to make a separate exe and put it into common startup. It would be executed whenever any user logs in, and could then communicate with your service and give the username. If you want your service to interact with the user's desktop, this is (I believe) the only way to do it. If you don't however, this might not be a good idea.

    Remember that it is possible for multiple users to be logged in at once, especially through Remote Desktop or Terminal Services (On Windows Server)

提交回复
热议问题