0

Need to build a service that displays a message and locks the computer out (Just by using a Windows Form) when the Network Cable is unplugged (So they cannot proceed without Network - Its for a school where the students keep unplugging the cables to bypass certain blocks)

Ive seen that you can interactive with the desktop with a service if you allow it to, im just wondering will Windows Forms display even if there is no user logged in?

As this program needs to catch them out when there authenticating in, then unplugging it.

Cheers Richard

x06265616e
  • 854
  • 11
  • 14
  • 2
    Ugh, what's with these educators that are constantly trying to suppress their students' ingenuity? The likes of Bill Gates never got the "don't do that!" slap of the ruler. Give the kid a badge and ask him to help. – Hans Passant Nov 07 '12 at 22:52
  • What I would love to know is how you can make the computer less locked down by disconnecting network cable. What happens if the network just fails. – David Heffernan Nov 07 '12 at 23:05
  • Why don't you ask for help with your problem, instead of asking how to implement a duff solution? – Tony Hopkinson Nov 07 '12 at 23:39

3 Answers3

0

There are several desktops on windows, one for windows services, one for logon, one for the user etc. See this link for more information.

What I think you could do is to create a new desktop, and then switch to that desktop whenever the network connection is lost. See this question for a start. However, due to security constraints this won't work from a windows service since it's a different session. What you can do (I think), however, is to have an application autostart whenever the user logs in and have that application talk to the windows service. That application can do the desktop switching.

The service will then managed the network and notify the application. If the application doesn't start within a fixed timeout, or is killed, I think you should be able to logout the user using the WTS-api.

Community
  • 1
  • 1
Onkelborg
  • 3,927
  • 1
  • 19
  • 22
  • I was just curious to know if Windows Forms could display outside of a logged on users desktop, just like on the login screen. – x06265616e Nov 07 '12 at 22:30
  • You should be able to create a window on another desktop, however I don't think you can get your windows service to interact with windows on the user's desktop – Onkelborg Nov 07 '12 at 22:32
  • After a bit of thinking, I'm not sure if this will work or not due to security constraints.. – Onkelborg Nov 07 '12 at 22:35
  • A process can only interact with desktops in the same session as the process. Windows services exist in session 0. All interactive desktops are in different sessions. – David Heffernan Nov 07 '12 at 22:36
  • That's what I'm thinking of, but I wonder what the definition of interact is in this context, is switching desktops to interact? – Onkelborg Nov 07 '12 at 22:40
  • Yes, that counts. No desktop switch from a different session. They really are isolated. – David Heffernan Nov 07 '12 at 22:41
  • Updated answer with new ideas :) – Onkelborg Nov 07 '12 at 22:52
0

As of Vista, a Windows service cannot interact with any interactive desktop. Which means that you can't do what you are proposing from a Windows service. You would need a standard desktop application.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
0

You could create a simple application that displays whatever splash screen with a chance to cancel and then locks the computer (or however you want it to work) not as a windows service, but as a desktop application. That application could be triggered to be started whenever the network disconnection event fires.

See this post on how to set up a scheduled task to start an application whenever the network disconnects.

See this post on how to lock a computer programmatically

Community
  • 1
  • 1
TylerOhlsen
  • 5,485
  • 1
  • 24
  • 39