Copy active profile directory. Cant access certain files like NTUSER.DAT

At my place of business, we copy the user profile that we are currently working with to the Default User so that any regular user who logs on has a consistant profile to work with. Then we use DeepFreeze to preserve the current state.

I am making a program to do this because we work on hundreds of computers doing this over and over again. The trouble is, when I try to open the file, NTUSER.DAT and others in the active profile directory, I cannot, because the files are in use by windows.

I know there is a way to copy the active directory and all it's contents because Windows does it. The OS is Win 2000 and if you right click on My Computer - Properties - Users - From there you have the option to copy any profile, even if it is the active profile.

Is there an api call I can call to copy the active profile or some other way to do this? Ideas, please.
[895 byte] By [aewarnick] at [2007-11-19 19:31:49]
# 1 Re: Copy active profile directory. Cant access certain files like NTUSER.DAT
The API you are looking for is Windows Management Instrumentation, WMI. (http://msdn.microsoft.com/library/en-us/dnanchor/html/anch_wmi.asp)
I can't say for certain, but it's likely that the Windows shell and MMC plugins that do the system adminstration use WMI.

It is a good skill to learn anyways, if you do that kind of IT work.
hankdane at 2007-11-9 13:20:12 >
# 2 Re: Copy active profile directory. Cant access certain files like NTUSER.DAT
Thanks for responding. I don't see how WMI can help me with this problem. Maybe I'm missing something in the documentation. If you know of a specific api call I can use, that would help clarify this. Thanks again.
aewarnick at 2007-11-9 13:21:13 >
# 3 Re: Copy active profile directory. Cant access certain files like NTUSER.DAT
Sorry I didn't respond earlier; busy week. The class I think you want to look at is Win32_UserAccount (http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_useraccount.asp).

You can get all account information on a system with the query
Select * from Win32_UserAccount

Here's an example of a script that enumerates users:
http://www.winserverhelp.com/ftopic4144.html (VB, but WMI is exposed through COM).

You have to do more legwork to get additional information about the user, such as registry entries, desktop settings, etc. Hopefully this will give you a start.
hankdane at 2007-11-9 13:22:22 >
# 4 Re: Copy active profile directory. Cant access certain files like NTUSER.DAT
Thanks for responding.

The problem is not getting the user profiles, it is the ability to use CopyFile to copy the files from the ACTIVE user directory to Default User. But Windows does this, as I said, somehow. So I can probably do it, I just don't know how.

If I have again missed something, please excuse my ignorace.
aewarnick at 2007-11-9 13:23:15 >
# 5 Re: Copy active profile directory. Cant access certain files like NTUSER.DAT
Sorry if I'm not being much help.

Have you tried Win32_Directory.Copy()? It may still give you an error though, but worth a try if you haven't already.

I hope I didn't give you a red herring with WMI. I do know that it was created as an API for general purpose IT/System adminstration automation, and your problem sounds like it's in that area. I've only used it to gather information myself, though, not copy a user profile, so I don't know how to do that specifically.
hankdane at 2007-11-9 13:24:23 >
# 6 Re: Copy active profile directory. Cant access certain files like NTUSER.DAT
Thanks for trying to help me!
The msdn docs say that Win32_Directory is defined in Cimwin32.mof, but apparently cimwin32.mof is not part of the gcc compiler headers.

How do I even compile this?
aewarnick at 2007-11-9 13:25:23 >
# 7 Re: Copy active profile directory. Cant access certain files like NTUSER.DAT
I didn't know you were using GCC. Have you installed the Platform SDK ( http://www.microsoft.com/downloads/details.aspx?FamilyId=0BAF2B35-C656-4969-ACE8-E4C0C0716ADB&displaylang=en)?
hankdane at 2007-11-9 13:26:27 >