[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 716
  • Last Modified:

Copy a File In Use on Reboot

I've found this inuse.exe program that takes advantage of the MoveFileEx() API.  It's a nice utility if you'd like to "MOVE" a file on reboot.  Notice the emphasis on MOVE.  I'd like to COPY a file on reboot.  Emphasis on COPY.  :)  I flat out don't want the the original file removed.  I've considered writing an app to high jack some registry entries to get the job done (I just need the copy done before the user logs in), but that seems so sloppy and why reinvent the wheel if someone has made such a system already.  The one file I whish to copy is impossible to do so while the user is logged in (NTUSER.DAT of the logged in user).

I will not accept an answer such as "log in as someone else with admins rights and copy ntuser.dat".  That's what I'm doing right now.  It's a hassle and it sucks.  I want to run xzy.bat or xyz.exe, reboot and have the ntuser.dat already copied.

Thanks in advance.
0
ElmerFud
Asked:
ElmerFud
  • 7
  • 4
1 Solution
 
ElmerFudAuthor Commented:
Now I remember why I stopped comming to Expert's Exchange....  I'm better apped to help myself rather than rely on the base of knowledge here.  I guess I could hang around EE and answer newbie questions, but why do that when I have a life and a career to maintain?

Even the lure of 500 points hasn't pulled anyone in with a solution or even a comment for that matter.  Hell, given about 10 hours of coding time, I could create and app that solves this problem.  Am I to believe that no one has done this before me?  Doubtful.

I have like 10K points just sitting here.  I should just dump them all on this one question for $hits and giggles, cause this place is worthless.
0
 
kobebeCommented:
comon, you can't expect recieving answers on complicated question such as this so fast, the real genius of EE also have lives and career, you know :)

anyway, if its so important for you, instead of copying filed from the user profile before it login you can' simply create a roaming profile of that user and put it on a nework drive
lets say you have a file server called "myfileserver", just create a shared directory there called "profiles" or something like that
under active directory users and computers right-click the user you wish to make as a roaming profile and mark it and put he's directory under that specific share (\\myfileserver\profiles\user)

from now on that directory will hold the updated ntuser.dat and it'll be resyncronized every time a user logoff any computer, so thats preety updated registry file

hope this helps!
and quit crying man... your not the type to give up :)
0
 
ElmerFudAuthor Commented:
I'm fully aware of roaming profiles and how to use them.  This is unreleated.  I'm creating a template NTUSER.DAT for new users who login for the first time.  This way each new user starts with the same base settings (not the default ones).

Copy File on Reboot FROM:

C:\\WINNT\Profiles\Robert\NTUSER.DAT   (the setup template NTUSER.DAT)

TO:

C:\\WINNT\Profiles\Default User\NTUSER.DAT

because NTUSER.DAT is a part of the current registry when logged in, you cannot copy it unless you use a user other than "Robert" (must have admin rights on the system).  The current solution is to log in a UsernameX and copy said file to it's destination.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
kobebeCommented:
I did that one aswell, I just used a template user, called "kobebe" for example, did whatever I wanted to change (hide icons, change toolbars etc.) and then logged-off, logged-on as local administrator and copied the entire user folder to the default user, then every user logged on had those configurations
sice you seem to be aware of that I still dont get what is your problem
0
 
ElmerFudAuthor Commented:
It's a hassle.  When I setup these machines, there is one user, "Administrator".  Therefore, in order to copy that NTUSER.DAT, I have to create a second username on the machine.  I also have to "Shutdown", because Logging off will store "log off" as the option the user sees when he clicks shut down.  So....

THE CURRENT METHOD

1.) create user "tmp"
2.) assign admin rights to "tmp" so he can copy NTUSER.DAT from another profile
3.) shut down
4.) login as tmp
5.) copy NTUSER.DAT
6.) log off tmp
7.) log in Administrator
8.) delete tmp's profile
9.) delete tmp's username

When I saw this MoveFileEx() API and this cool inuse.exe I was excited to see that I could Move or Delete a file on reboot.  Moving NTUSER.DAT from one profile to the next, however, isn't a good idea.  You'll kill the source profile.  Anyway, if Copy File on Reboot was was possible, this would be much easier:

1.) run copyinuse app
2.) reboot

I think I might be able to do it with RunService or RunOnce registry keys (HKEY_LOCAL_MACHINE).  If memory serves me, one of them is executed prior to login.  The copyinuse app could simply stick a command line to itself in that key.  Then on reboot,it would copy the file and, of course, remove itself from the registry.

I asked this question hoping some utility already existed to do this.  I guess I'll have to code the app myself.  I was just a little frustrated because all of my rescent questions have sat here on EE and rotted away until some moderator deletes them or something.  I guess this one will do the same.
0
 
ElmerFudAuthor Commented:
Crap, I wish I could edit posts..  Anyway, above should be:

C:\\WINNT\Profiles\Administrator\NTUSER.DAT  

The process isn't as bad when the machine it joined to the domain, but typically it prior to joining to the domain and hence you get the problem of having only one admin account on the machine.
0
 
kobebeCommented:
I see what you meen... I haven't heared about that api, or anything realted to... sorry
but I'll really appreciate if you'll send me the code (or the binary file) once you're done, it might be preety helpful in the future

I'll ask around, if I'll have any ideas I'll get back to you
0
 
ElmerFudAuthor Commented:
thanks kobebe, I appriciate the comments and the help.

If I end up making the app (not a lot of free time here), I'll send you the code and binaries.  The above method isn't pretty, but I think it will work.
0
 
kobebeCommented:
by the way, I've thought of another solution, I hope it'll work for you

you can use the group policy in order to copy that specific file (c:\winnt\profiles\defualt user\ntuser.dat) to anywhere you desire when the computer is powering up before you actually login, and any script that run at that state gets administrator privilages (it uses the machine privilages, not a normal user), that way you can creat a simple batch with 1 copy command to do that

if the computer is a member of a domain it'll be even easier
0
 
ElmerFudAuthor Commented:
That works great!!  good job and thanks.
0
 
ElmerFudAuthor Commented:
For those reading/searching...

This is the batch file that I ended up making.  xcopy and the /Y /H is needed bacause these are hidden system files and you need to replace the existing files:

@echo off
xcopy "C:\Documents and Settings\Administrator\NTUSER.DAT" "C:\Documents and Settings\Default User\NTUSER.DAT" /Y /H
xcopy "C:\Documents and Settings\Administrator\NTUSER.INI" "C:\Documents and Settings\Default User\NTUSER.INI" /Y /H

here's another tip, at the command prompt, type:

start gpedit.msc

that will bring up the group policy editor.  Just add the startup script (for the machine).  The batch file seemed best placed in:

C:\WINNT\system32\GroupPolicy\Machine\Scripts\Startup

This is a good tip and brings a lot of new ideas how to make this process easier for me.  Thanks.  This was done on a Windows 2000 Pro machine.  Should work good on XP and probably similarly on Windows NT.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now