Massive Permissions

Doc:

I'm trying to figure out a way to "programmatically" make mass changes to Windows NT user permissions. Specifically, I'm looking for a way to change a user's logon times. While I know this can be done with the user manager, we've got about 6,000 users who need their allowed logon times changed, and this could be a pain, especially if we decide later to change it back.

Anyway, I've written a short Visual C++ app that takes a .TXT list of user names and does a command line 'NET USER /times: etc etc' for each one, but this is a bit inelegant.

Is there an appropriate Windows NT API that I can use to make these changes? I tried reading up on the SAMLIB API, but there's no info available, and for all I know that might not even be the right way to do it.

Thanks for your time,

Dave Yarbrough

Dr. GUI replies:

Six thousand users? Cool! And the good doctor is sure you'll need to change the logon times back when they find out what you've done.

You can call NetUserSetInfo and tell it you're passing a USER_INFO_3 structure. The USER_INFO_3 structure contains the following member

PBYTE usri3_logon_hours

that does exactly what the doctor, or patient in this case, ordered. Set the member correctly and away you go!

Another API, called NetUserEnum, allows you to enumerate existing computer accounts.

Check out the Knowledge Base article, Q136867—"How to Manage Computer Accounts Programmatically in Windows NT"—which provides sample code for how to implement NetUserSetInfo.