Block user login or let user login certain hours, windows policies?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14

Thread: Block user login or let user login certain hours, windows policies?

  1. #1
    Join Date
    Sep 2009
    Posts
    6

    Block user login or let user login certain hours, windows policies?

    Hi!

    I have a little problem with an application I've making.

    I need to let login on windows ( only for one user ) and only between certain hours, for example from 17:00 to 22:00, or maybe block the rest of hours, but I can't find any import or using that let me make this.

    I've only found something trought VBScript, but would like to make all with C#.

    Thanks a lot

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    210

    Question Re: Block user login or let user login certain hours, windows policies?

    How this should work?


    Running your application means: to be logged in BEFORE.

  3. #3
    Join Date
    Sep 2009
    Posts
    6

    Re: Block user login or let user login certain hours, windows policies?

    I know that, but if I run my app as a service I think I could make it work, but I don't know how..

  4. #4
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    422

    Re: Block user login or let user login certain hours, windows policies?

    while creating a C# a project using .NET select "Service" type and implement your code in that and run the application as service it should work fine.

  5. #5
    Join Date
    Sep 2009
    Posts
    6

    Re: Block user login or let user login certain hours, windows policies?

    Quote Originally Posted by vcdebugger View Post
    while creating a C# a project using .NET select "Service" type and implement your code in that and run the application as service it should work fine.
    Thanks for it, but anyone know how I can let login to windows only in certain hours?

    Thanks

  6. #6
    Join Date
    Jul 2006
    Posts
    297

    Re: Block user login or let user login certain hours, windows policies?

    Do you have Active Directory installed on your network? The only way I can think of is to have an application change a users available login times. Never done it before but there are plenty of tutorials on how to interact with AD in C# i'm sure you can find something.

    I doubt there is a simple way to do this. Restricting login to a computer is handled by the OS. I don't understand why you need to create an application to do this when windows has this built in?

  7. #7
    Join Date
    Sep 2009
    Posts
    6

    Re: Block user login or let user login certain hours, windows policies?

    I understand your questions.

    The enviroment is the following:

    there isn't a network, is a single pc of a particular house, then I haven't active directory. And this pc doesn't have to let login until 22:00.

    And I need to make this with C#, I think I can make it with VBScript but if I can, i prefeer C#.

    Windows Vista has something similar I've making, but I need to make it for a windows xp.

    Thanks.

  8. #8
    Join Date
    Jul 2006
    Posts
    297

    Re: Block user login or let user login certain hours, windows policies?

    Just go to cmd panel and run this command if you have Windows XP Pro

    Code:
    net user username /time:M-F,08:00-17:00
    to remove it do

    Code:
    net user username /time:all

  9. #9
    Join Date
    Sep 2009
    Posts
    6

    Re: Block user login or let user login certain hours, windows policies?

    Thanks but I know that command and I didn't want to make trought msdos, because user will change it for sure.

    Anyway I'll try with net user /time with redirectoutput but I've looking for other solution.

    Thanks.

  10. #10
    Join Date
    Jul 2006
    Posts
    297

    Re: Block user login or let user login certain hours, windows policies?

    Only administrators can change the login times. A regular user will not be able to change it. Likewise, anything a C# program can do a user can undo manually.

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    10,967

    Re: Block user login or let user login certain hours, windows policies?

    Quote Originally Posted by uoah View Post
    Thanks but I know that command and I didn't want to make trought msdos, because user will change it for sure.

    Anyway I'll try with net user /time with redirectoutput but I've looking for other solution.

    Thanks.
    Why would the user change it? You can certainly execute the command with a hidden console window using CreateProcess or ShellExecEx. The user would have no idea if you changed the time.

    At any rate, if your program runs under the same account as the user, anything your program can do, the user can undo.

  12. #12
    Join Date
    Sep 2009
    Posts
    6

    Re: Block user login or let user login certain hours, windows policies?

    Quote Originally Posted by Arjay View Post
    Why would the user change it? You can certainly execute the command with a hidden console window using CreateProcess or ShellExecEx. The user would have no idea if you changed the time.

    At any rate, if your program runs under the same account as the user, anything your program can do, the user can undo.
    Thanks for your replies.

    At the end, I've made trought cmd with net use /time, and I'll update every x minuts.

    The user would change it because is a child who stays a lot of hours in the pc, and his parents doesn't want it. If he knows ( or search a little on google ) he find the way to unblock, but if I check every x minuts, if he unblock it, my program block again.

    Thanks.

  13. #13
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    10,967

    Re: Block user login or let user login certain hours, windows policies?

    Change the user's account to a regular user (instead of admin or power user) and remove the time change policy from regular user accounts so the user can't change the time.

  14. #14
    Join Date
    Jul 2006
    Posts
    297

    Re: Block user login or let user login certain hours, windows policies?

    Quote Originally Posted by uoah View Post
    Thanks for your replies.

    At the end, I've made trought cmd with net use /time, and I'll update every x minuts.

    The user would change it because is a child who stays a lot of hours in the pc, and his parents doesn't want it. If he knows ( or search a little on google ) he find the way to unblock, but if I check every x minuts, if he unblock it, my program block again.

    Thanks.
    You realize that no matter what you do the kid can undo it. The kid can stop your program from running if hes on the computer. Reverse the /time command and continue playing. Like a few of us have already said make the kid a (non-admin) user and change the /time of his login. He will not be able to change it unless he logs in under an admin account.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center