Author Topic: Trouble Copying Users and Program Files Folders  (Read 2987 times)

0 Members and 1 Guest are viewing this topic.

Offline straightdice89

  • Bronze Member
  • Posts: 10
Trouble Copying Users and Program Files Folders
« on: March 01, 2011, 07:16:32 AM »
Hi to all the helpful people here!

A bit of preamble about my question:

Using Win 7 x64. I want to change the default locations for the Users, Program Files and Program Files (x86). I know how this is done (and that it's not supported by Microsoft and there are potential issues with doing this), and I've prepared a reg file to change those directories. The problem I'm having is copying the folders to another partition. I want to do this automatically and a batch file seemed like an easy enough solution.. or so I thought. Also, the reg file I call in the batch is not being merged?  :m

So, here is more or less the batch I've created:

Code: [Select]
@echo off

copy "C:\Users" D:
copy "C:\Program Files" D:
copy "C:\Program Files (x86)" D:

regedit /s myreg.reg

echo System needs to reboot. Close all browsers and open documents.
pause

shutdown /r
(where D: is my desired partition)

I've tried this with and without elevation, with and without UAC enabled, and I've tried manually changing ownership and permissions on all the individual subfolders (defeats the purpose of automation but I wanted to see if that was the issue), all to no avail.

The error I get when I run this is:
Quote
C:\Users\*
The system cannot find the file specified.
            0 file(s) copied.
(same error for other two folders)

These folders can be manually copied by dragging and dropping them. It's so weird that it can't be done with command line.

When it comes time for the reg file to be called, I do get a UAC prompt for Regedit, but then nothing happens (and the entries I've added don't show up). I've tried adding a /c argument to the regedit line:

regedit /c /s myreg.reg

But that doesn't do anything either..

The reg file works if I double-click it, just not when I call it from the batch.

Here's the gist of my reg file, if it matters:
Code: [Select]
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion]
"CommonFilesDir"="D:\\Program Files\\Common Files"
"CommonFilesDir (x86)"="D:\\Program Files (x86)\\Common Files"
"CommonW6432Dir"="D:\\Program Files\\Common Files"
"ProgramFilesDir"="D:\\Program Files"
"ProgramFilesDir (x86)"="D:\\Program Files (x86)"
"ProgramW6432Dir"="D:\\Program Files"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion]
"CommonFilesDir"="D:\\Program Files (x86)\\Common Files"
"CommonFilesDir (x86)"="D:\\Program Files (x86)\\Common Files"
"CommonW6432Dir"="D:\\Program Files\\Common Files"
"ProgramFilesDir"="D:\\Program Files (x86)"
"ProgramFilesDir (x86)"="D:\\Program Files (x86)"
"ProgramW6432Dir"="D:\\Program Files"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList]
"ProfilesDirectory"=hex(2):44,00,3a,00,5c,00,55,00,73,00,65,00,72,00,73,00,00,\
  00
"Default"=hex(2):44,00,3a,00,5c,00,55,00,73,00,65,00,72,00,73,00,5c,00,44,00,\
  65,00,66,00,61,00,75,00,6c,00,74,00,00,00
"Public"=hex(2):44,00,3a,00,5c,00,55,00,73,00,65,00,72,00,73,00,5c,00,50,00,75,\
  00,62,00,6c,00,69,00,63,00,00,00
"ProgramData"=hex(2):44,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,\
  00,44,00,61,00,74,00,61,00,00,00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\ProfileList]
"ProfilesDirectory"=hex(2):44,00,3a,00,5c,00,55,00,73,00,65,00,72,00,73,00,00,\
  00
"Default"=hex(2):44,00,3a,00,5c,00,55,00,73,00,65,00,72,00,73,00,5c,00,44,00,\
  65,00,66,00,61,00,75,00,6c,00,74,00,00,00
"Public"=hex(2):44,00,3a,00,5c,00,55,00,73,00,65,00,72,00,73,00,5c,00,50,00,75,\
  00,62,00,6c,00,69,00,63,00,00,00
"ProgramData"=hex(2):44,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,\
  00,44,00,61,00,74,00,61,00,00,00

So, is there a way I can automatically copy those folders? And why in the world isn't my reg file working? I'm doing this for a friend who is building a new computer, he's just waiting on the parts to arrive, which will be in about 3 days. He'll be using an SSD for his OS partition, so I recommended to him the directory modding to avoid thrashing. I've been doing my testing in a VM. Any help would be greatly appreciated. Worst case scenario, I can just give him instructions to run the reg file and manually copy those folders. I also wanted to learn how to do this for my own experience though. :ty



Offline Hoov

  • Malware Removal Mentors
  • Global Moderator
  • Diamond Member
  • Posts: 22719
  • Unwilling part owner of Gov't. Motors and Chrysler
    • Hoov's Personal Site
Re: Trouble Copying Users and Program Files Folders
« Reply #1 on: March 01, 2011, 08:59:05 AM »
Try removing the " from the copy commands. As for the registry file, try using regedit.exe /s

DOS is very exacting as far as syntax is concerned. If you get the syntax wrong, then it will not do what you want. Try making those changes and see what happens.

Consumer Security

If I am helping you and you don't hear from me for 24Hrs, send me a PM Please!

Offline straightdice89

  • Bronze Member
  • Posts: 10
Re: Trouble Copying Users and Program Files Folders
« Reply #2 on: March 01, 2011, 10:31:39 AM »
Hi Mr Hoov :)1

Thank you for your suggestions. Unfortunately they didn't work.  :m

"regedit.exe" apparently doesn't do anything different than "regedit" in the command line. It gives the UAC prompt for regedit, but doesn't merge the registry file.

As for the copy commands, I didn't think it would work but I tried it. I got the result I was expecting:

Quote
C:\Users\*
The system cannot find the file specified.
            0 file(s) copied.
The system cannot find the file specified.
The system cannot find the file specified.

The Users folder is the same error I was getting before.
The other two folders didn't work at all. I'm assuming this is because they have spaces in their names and need to be encapsulated in quotation marks.

It's very strange because drag and drop copying does work, save for like 5 files that are in use like NTUSER.DAT.

I also tried xcopy and the command line version of teracopy. Xcopy gives the same result as copy but without any of the details. Teracopy successfully copies some of the files but most of the folders are locked.

Out of curiosity I tried Unlocker to unlock the folders but it says it can't find an unlocking point.

The answer exists.. I think we're on the right track!

Offline 1972vet

  • Microsoft® MVP
  • Malware Removal Staff
  • Diamond Member
  • Posts: 8290
  • Patience is bitter indeed, but its fruit is sweet.
Re: Trouble Copying Users and Program Files Folders
« Reply #3 on: March 01, 2011, 10:56:18 AM »
What you're attempting is difficult but do-able. You need to use the boot media to be successful. Think of it as, under the old Windows XP recovery console command prompt. There are things that can be done there that cannot be done using Windows itself while it's mounted. You seem savvy enough to tailor a set of instructions to suit your needs...take a look at This and see if that hits the mark.
Disabled Veteran
U.S.C.G. 1972 - 1978
Membership: U.N.I.T.E., A.S.A.P.

2009-12

Performance and Maintenance for Windows XP, Windows Vista and Windows Seven

Offline Hoov

  • Malware Removal Mentors
  • Global Moderator
  • Diamond Member
  • Posts: 22719
  • Unwilling part owner of Gov't. Motors and Chrysler
    • Hoov's Personal Site
Re: Trouble Copying Users and Program Files Folders
« Reply #4 on: March 01, 2011, 11:22:29 AM »
You may also want to look at this thread on another forum.

Especially this paragraph which is credited to MS.

This setting should be used only in a test environment. By changing the default location of the user profile directories or program data folders to a volume other than the System volume, you will not be able to service your Windows installation. Any updates, fixes, or service packs will fail to be applied to the installation. Microsoft does not recommend that you change the location of the user profile directories or program data folders.

There may be a better way of getting the end result that you want. If you tell us what you are trying to do (ie making backup easier), we may be able to come up with a better game plan for you.

Consumer Security

If I am helping you and you don't hear from me for 24Hrs, send me a PM Please!

Offline straightdice89

  • Bronze Member
  • Posts: 10
Re: Trouble Copying Users and Program Files Folders
« Reply #5 on: March 01, 2011, 03:11:30 PM »
Thank you all very very much, I was able to sort this all out eventually. And my outcome: Yes, it's possible to change the default User and Program Files directories and still have a working system that can update.  :p

It just took an obscene amount of trial and error..

I figured out the reg file command line problem - it needed parenthetical enclosure to run in the directory I was testing from (the desktop).

Code: [Select]
regedit.exe /s "%userprofile%\desktop\myreg.reg"Worked great. The reg file itself needed tweaking - here's the finished product on that:

Code: [Select]
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion]
"CommonFilesDir"="D:\\Program Files\\Common Files"
"CommonFilesDir (x86)"="D:\\Program Files (x86)\\Common Files"
"CommonW6432Dir"="D:\\Program Files\\Common Files"
"ProgramFilesDir"="D:\\Program Files"
"ProgramFilesDir (x86)"="D:\\Program Files (x86)"
"ProgramW6432Dir"="D:\\Program Files"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList]
"ProfilesDirectory"=hex(2):44,00,3a,00,5c,00,55,00,73,00,65,00,72,00,73,00,00,\
  00
"Default"=hex(2):44,00,3a,00,5c,00,55,00,73,00,65,00,72,00,73,00,5c,00,44,00,\
  65,00,66,00,61,00,75,00,6c,00,74,00,00,00
"Public"=hex(2):44,00,3a,00,5c,00,55,00,73,00,65,00,72,00,73,00,5c,00,50,00,75,\
  00,62,00,6c,00,69,00,63,00,00,00
"ProgramData"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,44,00,72,00,69,\
  00,76,00,65,00,25,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,44,00,\
  61,00,74,00,61,00,00,00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-18]
"Flags"=dword:0000000c
"State"=dword:00000000
"RefCount"=dword:00000001
"Sid"=hex:01,01,00,00,00,00,00,05,12,00,00,00
"ProfileImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,\
  00,6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,\
  5c,00,63,00,6f,00,6e,00,66,00,69,00,67,00,5c,00,73,00,79,00,73,00,74,00,65,\
  00,6d,00,70,00,72,00,6f,00,66,00,69,00,6c,00,65,00,00,00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-19]
"ProfileImagePath"=hex(2):43,00,3a,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,\
  00,73,00,5c,00,53,00,65,00,72,00,76,00,69,00,63,00,65,00,50,00,72,00,6f,00,\
  66,00,69,00,6c,00,65,00,73,00,5c,00,4c,00,6f,00,63,00,61,00,6c,00,53,00,65,\
  00,72,00,76,00,69,00,63,00,65,00,00,00
"Flags"=dword:00000000
"State"=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-20]
"ProfileImagePath"=hex(2):43,00,3a,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,\
  00,73,00,5c,00,53,00,65,00,72,00,76,00,69,00,63,00,65,00,50,00,72,00,6f,00,\
  66,00,69,00,6c,00,65,00,73,00,5c,00,4e,00,65,00,74,00,77,00,6f,00,72,00,6b,\
  00,53,00,65,00,72,00,76,00,69,00,63,00,65,00,00,00
"Flags"=dword:00000000
"State"=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21-884096590-523525792-2789496666-1001]
"ProfileImagePath"=hex(2):43,00,3a,00,5c,00,55,00,73,00,65,00,72,00,73,00,5c,\
  00,47,00,65,00,6e,00,65,00,72,00,69,00,63,00,20,00,55,00,73,00,65,00,72,00,\
  00,00
"Flags"=dword:00000000
"State"=dword:00000000

I created a Windows 7 x64 Repair CD (it's the equivalent of Recovery Console for XP I guess), restarted and used that to get into the command line. Ran this batch file based on the reading you guys provided:
Code: [Select]
@echo off

robocopy "C:\Users" "D:\Users" /mir /xj /copyall
robocopy "C:\Program Files" "D:\Program Files" /mir /xj /copyall
robocopy "C:\Program Files (x86)" "D:\Program Files (x86)" /mir /xj /copyall

echo File Copy Complete. Please Restart.
pause
exit

Rebooted. Created new Admin user and deleted the old one (to avoid profile corruption from the move). Tested painstakingly for all the things that had been breaking in my previous attempts - like all shortcuts disappearing, Windows Search not returning any results or crashing, Internet Explorer not loading. and pretty much every app on the system crashing. All of that seems fixed (for now). Needs more testing.

Installed Windows 7 x64 Service Pack 1 RTM without a hitch. Installed Microsoft Security Essentials and updated it without a hitch. Ran Windows Update and updates installed without a hitch.

Installed Internet Explorer 9 x64 Release Candidate - Internet Explorer stopped working (would momentarily flash on screen when loaded, then vanish - known issue). Had to revert to IE8.

It looks like everything (except IE9 RC) will install and update perfectly. Since the guy I'm preparing this for is sane enough to use Firefox anyway, I don't think he'll mind :)1

Picture: Shows Windows Update success, Service Pack 1, open browser, updated MSE, and my customized registry. That's a whole lotta Microsoft crammed in 1 picture lol.
 

*Forgot to mention, Mr Hoov, you asked what I was trying to accomplish with all this. In my friend's instance, he'll be running his OS from a solid state drive. In addition to disabling indexing and moving the paging file, I wanted to move the Users and Program Files folders for two reasons:

To reduce writes on the SSD.

To make it easier to clone the drive, with a smaller image, that's faster and more convenient to restore in case anything goes wrong, or just for the sake of maintenance. He'll be using CloneZilla, and he can make an image that fits onto a single layer DVD, and will restore in about 15 mins. Not too shabby I'd say.

Thanks again guys, couldn't have done it without you!    :b :ty :b
« Last Edit: March 01, 2011, 03:26:39 PM by straightdice89 »

Offline 1972vet

  • Microsoft® MVP
  • Malware Removal Staff
  • Diamond Member
  • Posts: 8290
  • Patience is bitter indeed, but its fruit is sweet.
Re: Trouble Copying Users and Program Files Folders
« Reply #6 on: March 01, 2011, 05:03:21 PM »
Glad we could help  :t
Disabled Veteran
U.S.C.G. 1972 - 1978
Membership: U.N.I.T.E., A.S.A.P.

2009-12

Performance and Maintenance for Windows XP, Windows Vista and Windows Seven

Offline straightdice89

  • Bronze Member
  • Posts: 10
Re: Trouble Copying Users and Program Files Folders
« Reply #7 on: March 01, 2011, 08:29:36 PM »
It appears you can't delete the old directories, even though they're largely unused after the partition change. Some parts of Windows require the old file structure to be intact - it's hard coded? Probably why they suggested not to change it in the first place :)

So it needs the right registry imports, a full copy of the directories to the new partition (done outside the OS environment, like in Repair mode) and NOT deleting the old stuff, plus creating a new Admin account and deleting the old one in order not to crash every time you launch a search or application :)1

It's so simple, why didn't we see it before..  :D1

Offline straightdice89

  • Bronze Member
  • Posts: 10
Re: Trouble Copying Users and Program Files Folders
« Reply #8 on: March 09, 2011, 07:20:56 PM »
I'm back with another question  :)1

When you go into a command prompt from the Windows install media/Repair disc, often the drive lettering is changed.

How would I craft a batch file that detects the changed drive letters for my C: and D: partitions?

I created a Win7 Repair Disc, added an autorun.inf, a small program that incorporates my registry changes, and a batch file that I can run from the Repair console. I thought about having the program copy a small text file to the root of C: and D: so that I could use FIND in a batch to determine the drive letters. Let's say for this example that the autorun program places a "C.txt" in the root of C:\ and a "D.txt" in the root of D:\.

If I do it that way, I can just have the batch file delete the text files when it finishes so it seems like an elegant option.

How would I craft a batch file to search for the text files and use the drive letter of the drives they're found on as variables for the robocopy commands?

The random drive lettering in the Repair console seems to be the last hurdle. I appreciate all the help so far!

Offline 1972vet

  • Microsoft® MVP
  • Malware Removal Staff
  • Diamond Member
  • Posts: 8290
  • Patience is bitter indeed, but its fruit is sweet.
Re: Trouble Copying Users and Program Files Folders
« Reply #9 on: March 09, 2011, 09:51:14 PM »
There is no random lettering for the installed operating system. In a typical install, the boot drive will always be C, and the media device will be D. If these are different because you changed them, or you HAD to change them after the install, then you didn't install from the boot media, but from having already mounted the operating system...or an operating system, then used the boot media to install while already having mounted one of the Windows operating systems already installed. It sounds like you've set up a multi boot system. Correct?
Disabled Veteran
U.S.C.G. 1972 - 1978
Membership: U.N.I.T.E., A.S.A.P.

2009-12

Performance and Maintenance for Windows XP, Windows Vista and Windows Seven

Offline straightdice89

  • Bronze Member
  • Posts: 10
Re: Trouble Copying Users and Program Files Folders
« Reply #10 on: March 10, 2011, 01:54:38 AM »
Hi 1972vet :)1

It's (for the time being) a single boot machine. The drive letters appear correctly in Windows (C:\ = Windows drive, D:\ = 2nd hard drive, E:\ = DVD drive).

When booting into the Repair console from the Win7 install media or a Win7 Repair disc, sometimes the drive lettering is different. The user in the thread you linked to that inspired me to use robocopy also mentions his drive letters were different while using the Repair console.

In my virtual machine, I wasn't able to reproduce this (drive letters were always the same in Windows and in Repair console) but in my friend's PC, the drive lettering was very different, but only the first time he booted into the Repair console.. subsequent times, the drive lettering was the same as in Windows.

So while it may be a quirk or just a really uncommon event, it would make my batch file a lot cleaner to include something that correctly determines the drive letter. Something like:

for %i in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do FIND

But my batch-Fu skills aren't up to snuff for a complex find-two-files-and-use-their-containing-drive-letters-as-variables type operation.

Offline 1972vet

  • Microsoft® MVP
  • Malware Removal Staff
  • Diamond Member
  • Posts: 8290
  • Patience is bitter indeed, but its fruit is sweet.
Re: Trouble Copying Users and Program Files Folders
« Reply #11 on: March 10, 2011, 11:50:08 AM »
Quote
When booting into the Repair console from the Win7 install media or a Win7 Repair disc, sometimes the drive lettering is different. The user in the thread you linked to that inspired me to use robocopy also mentions his drive letters were different while using the Repair console.
Yes, but please note that what I had said, related to a typical install of Windows:
There is no random lettering for the installed operating system. In a typical install, the boot drive will always be C, and the media device will be D.
...and since you have a solid state drive, as well as your virtual machine setup, this falls short, to say the least, of a typical installation of Windows. Additionally, the wording of your statement scares me a bit, as I must point out, there is in fact, no real "Repair console" in Windows 7 (or Windows Vista either for that matter). I would think, with what knowledge you seem to have, certainly you would not be referring to the installation media repair options as the "Repair console"...so, it causes me some concern as to how one should proceed with this.

As I fail to fully understand what it is that you are trying to achieve, and since this whole notion of moving system files from one drive to another is something Microsoft strongly advises against, I would defer the remainder of your questions to one of my other colleagues who may have a better understanding and can direct you in such a way so as not to have any of our other readers veer off the path.

I would also not cherish the thought that my advise, if taken by others less savvy, translates their system into something about as useful as a door stop...or a rather expensive paper weight.

Someone else may be along to add more comments to this thread as prudence dictates, and time permits.
Disabled Veteran
U.S.C.G. 1972 - 1978
Membership: U.N.I.T.E., A.S.A.P.

2009-12

Performance and Maintenance for Windows XP, Windows Vista and Windows Seven

Offline straightdice89

  • Bronze Member
  • Posts: 10
Re: Trouble Copying Users and Program Files Folders
« Reply #12 on: March 10, 2011, 05:17:00 PM »
My fault there, I was just exercising some poetic license. You're correct that I am referring to the install media's Command Prompt in the repair options.

The virtual machine was just for testing before deploying it to a live system. The live system install and moving of the default directories went without a hitch (for the most part). We had to adjust my batch file because the drive lettering was different when accessing the drives via command line in the media repair options. Because we failed to notice the drive lettering difference between being logged into Windows and booting into the repair options command line, we did end up with a "doorstop" at first, but we were able to correct the issue.

What I am trying to achieve is a batch file to be run at the command prompt in the repair options that performs the robocopy operations automatically. In order to fine-tune this process to reduce the risk of error on the user's part, I would like my batch file to correctly determine the current drive letters for the Windows partition/disk and the large capacity storage disk/partition.

Thank you for taking to time to try to understand what I'm trying to accomplish, and to make sure I understand the risks involved.. My intended purpose for this batch file is to reduce the risk of creating an expensive paperweight.

If someone can help me hammer out my batch file when they have some free time I'd be very appreciative. Thanks again for all your contributions.

Offline straightdice89

  • Bronze Member
  • Posts: 10
Re: Trouble Copying Users and Program Files Folders
« Reply #13 on: March 10, 2011, 05:44:08 PM »
I thought it might be prudent to add a disclaimer:

The steps I've taken here pertain only to my system. Others reading this in the hopes of adopting something similar should ask questions before attempting to deploy this in a live system.. These steps can be very dangerous, as 1972vet mentions, and should only be undertaken with a firm grasp of the problems that can arise as a result of this. Our system was made unbootable temporarily. Yours may not be temporary..