Dugo

HelloAll,

I'm new to the MSDN Forums, so hopefully this is the appropriate forum for this question.

I'm looking to see if there exists an API/cmd to temporarily disable or lock a user account on XP Pro Is there an interface I can access to something like the Local Security Policy. Or perhaps create a custom Security Policy. Idunno.

My reason:

Using VB Express 2005, I'm writing a simple countdown timer that forcably logs the user out after a set amount of time. (Basically to limit the amount of computer screen time for my 3yr old son.) I've got everything figured out and running cleanly except locking the user account to block an immediate return visit. -- (Once logged out, he just logs himself back in. Smile

Thanks in Advance,

D




Re: .NET Base Class Library How do I temporarily lock/disable a user account?

Rob Teixeira


If you were working on a domain with Active Directory, the solution would have been slightly simpler

However, on a home XP machine, you're going to have to jump through some (not overly horrible) Win API hoops. You should be able to use the NetUserSetInfo kernel function. This method takes a number of different structures to modify user data. The one you'll be looking for is a structure called USER_INFO_1008, which simply sets account flags. The flag value you need to set is the UF_ACCOUNTDISABLE value. Also, you'll want to get this flag first (by using NetUserGetInfo), and just bitwise OR the UF_ACCOUNTDISABLE flag to the existing flags for the account. To re-enable the account, get the existing flags and bitwise AND the UF_ACCOUNTDISABLE flag out. Also, if the account is a local machine account (which stand-alone XP accounts are), pass NULL to the servername parameter of the function. This should do the trick, although the process executing the code needs to have admin rights (or simply rights to modify user data in the SAM store). On Win XP, most local accounts are capable of that by default, but if you get a access denied error, that would be why.





Re: .NET Base Class Library How do I temporarily lock/disable a user account?

Dugo

Yeah no doubt Active Directory would be easier, however no domain controller on the home network.

Anyway thanks for the NetUserGet/SetInfo recommendation as well as the additional advise on how to use... This sounds like exactly what I need.

I'll post again (and mark answered) after I can implement & test.

MuchAppreciated!






Re: .NET Base Class Library How do I temporarily lock/disable a user account?

motorhomebill

I would be real interested in knowing if this works, and how to do it on my computer running Win XP Pro.

Thanks.





Re: .NET Base Class Library How do I temporarily lock/disable a user account?

Dugo

Sorry motorhomebill,

Haven't gotten back to this lil' side project in awhile. Hopefully I can spend some time playing again over the long weekend.

Anyway the following vbnet code sample may help. It also has a link to disable an account via USER_INFO_1008.

http://vbnet.mvps.org/code/network/netusersetinfo_accountdisable2.htm

HTH,

Dugo