Starting a service before login and removing a user from a group
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:
- Create a service that starts be开发者_StackOverflow中文版fore user can login
- 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
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 the
Started´ 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.
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.
精彩评论