views:

138

answers:

2

I want to create a windows service that would start before user can login. I want it to start before login so I can remove a user (windows user) from group (HomeUser to be precise), so I dont have to re-login.

So I want to:

  1. Create a service that starts before user can login
  2. Remove a user from group.

Any idea how this can be accomplished in C#?

Edit

For part-2 of question; Here the link on how you can do this: http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.groupprincipal.members.aspx

+1  A: 

Starting at boot is something any service can do, as long as it doesn't need any GUI to operate. It is one of the startup options for a service. Just set it up that way, and you are good to go.

As for making a C# program a service, I'm not too sure. Perhaps they have something, but I'd imagine you'd need to at least wrap it in some unmanaged C++ to interface with the Windows Service API.

T.E.D.
I do know how to create a service, but didn't had any idea how to start it before user login.
cornerback84
Good. It *kinda* looked that way from the way your question was asked, but I wasn't sure.
T.E.D.
+1  A: 

How to do it:

Use the Windows Service (not WCF service!) project type in Visual Studio.

Put your implementation in the OnStart´ method. Add a projectInstaller and configure it to install the service in theStarted´ mode.

compile your project, run `installutil.exe -i´ on your projects.exe

That should install your service, and on next boot have it start.

Why to do it?:

Tbh, it sounds to me like something that is done once, not every boot ´removing a user from a group´. Unless someone else puts the user back in the group, its going to stay the way you set it last.. So, doing it every cold-boot sounds redundant.

Also remember, modifying security settings is a pretty high privilege. Not many accounts are allowed to do this. Make sure your service is installed with an identity which has permission to these levels.

Marvin Smit
The removing user part; I am making this service so I don't have to remove the user every time. I don't know why, but windows put the user back in group when I restart.
cornerback84
Just a weird thought, but it there any way to prevent windows from putting that user in the group in the first place? Or are you bound to a domain controller who does this? I think it would be better to prevent this issue from occuring than trying to reverse it after the fact. Is there more info you can/are allowed to/are willing to give about the user account? Sounds to me like there has to be a solution in the ´homeuser´ direction.
Marvin Smit
Just finished up reading some on the HomeUsers group. At first glance it seems about networking with Samba and related topics. But what hit me was the mentioning of GPO´s. This would be your ´correct´ way to ´execute functionality before a user is allowed to log on´. At least, thats what you can use it for in domains envs. If this is true, than i would suggest setting up a GPO who does your ´remove user from group´. check outhttp://technet.microsoft.com/en-us/library/cc766208%28WS.10%29.aspx (vista version). Maybe your `insert user into HomeUsers group´ is a GPO by itself!
Marvin Smit
Its just a home computer.
cornerback84