Windows 7 Copy to c:\ doesn't work with batch file

Glip

New Member
Joined
Sep 17, 2009
Messages
12
I have a little strange problem under Windows 7 x64 using the copy command at the command prompt.

If I enter the following command at an elevated command prompt:

copy somefile c:\

it copies the file somefile to c:\. Now when I create a batch file from this command and run it with admin privileges it says it cannot find the file! Also, a strange thing is that when I run the batch file without administrator privileges it properly says 'access denied', so it can find it then, which is correct because you can't just write something to the C root.

Can someone verify and possibly resolve this?

Note this is all with UAC set to standard.
 


Last edited:
Solution
Bat to exe converter will not download on my Windows 7. It says the zip file is invalid.

YES.. I was sad to see that bat to exe doesn't work consistently on 7.... it does work sometimes but usually fails.




I have the same problem with XCOPY described in this thread.

I have used XCOPY in similar .BAT files on all my PCs from DOS through every Windows to Vista. It refuses to work on 7.

The code in the .BAT file is as follows :-

echo on
xcopy "C:\Users\David\My Documents\*.*" "DAVID_BACKUPS\CHANGES_Documents" /s /m
echo off
echo on
xcopy "C:\Users\David\My Pictures\*.*" "DAVID_BACKUPS\CHANGES_Pictures" /s /m
echo off
echo on
xcopy "C:\Users\David\My Music\*.*" "DAVID_BACKUPS\CHANGES_Music" /s /m
echo off
echo on...
Copy and paste the contents of your bat file so we can see if it's ok.

I made a dummy txt file in D and then added this to a bat file, worked fine -

Code:
xcopy D:\txt.txt C:\
What is it you are trying to achieve?
 


Thanks, at least that works i.e.
Code:
copy d:\txt.txt c:\
pause
But the following does not (it gives the file not found error):
Code:
copy txt.txt c:\
pause
where the file txt.txt is in the same folder as the batch file (on C: or D: - doesn't matter).

Apparently it is not possible to apply 'relative' pointing to a file when using administrator privilieges with batch files. Does anyone else have a say on this?
 


Thanks, at least that works i.e.
Code:
copy d:\txt.txt c:\
pause
But the following does not (it gives the file not found error):
Code:
copy txt.txt c:\
pause
where the file txt.txt is in the same folder as the batch file (on C: or D: - doesn't matter).

Use -
Code:
xcopy ./txt.txt C:\
pause

That should work!
 


No unfortunately it doesn't. :-)
Note that you had the slash wrong (should be a back slash: xcopy .\txt.txt C:\)
so that it works in non protected locations (not C:\). But copying to C:\ still doesn't work. Do you have some other way to point to a file in a non direct way (but relative to the batch file's location)?

BTW this is for a batch file that needs to install a boot manager on C. It's really only a few commands but I need to do it on several computers, that's why.
 


I have tried running the bat file from multiple locations, sending files to multiple locations and it works every time.

It's a long shot but you could try adding

Code:
cd /d ./

That should 'fix' the location of the bat file relative to the folder it's in.

You could take a look Link Removed to see if adding any switches to your statement will resolve your problem.
 


Last edited:
A new quirky find has come up for the good part. I 've got it working, in a sense. I didn't tell you how I ran the batch file. Well I just right clicked on it and select 'run as administrator', which gives the file not found error. Now, when I go into an elevated command prompt first, navigate to the location of the batch file and then run it, it works!

So running the batch file with administrator privileges from Windows Explorer directly doesn't work, but when you are in an elevated prompt and run it from there it does. I know that's ridiculous, but I can live with it. I just have to navigate to the batch file's location first and run it. Oh well let's just say it's one of Windows' oddities. If somebody wants to add anything to this thread please do (even if it's years from now). Thank you for helping me.
 


i had same problem but i tried to copy DLL files into system 32.
Xcopy says it was copied but when u open it and look its not there :(
What i die was i compiled .bat into .exe using bat2exe program from here
Bat To Exe Converter
set compile options to
Add Vista ADministrator manifest anc click compile

This works great
 


Thanks for the suggestion; I'll try it.

I'm still curious as to why this problem exists only when executing batch files direclty. If somebody can explain this, even if it's years from now, please do!
 


W7 protection i think. this crappy OS takes away more then it gives i think.
Even if u are administrator, u still cannot fully use anything u want in anyway u need.
As my example shows u cant copy files anywhere u want using CMD, what the hell is up with that ?
What kind of administrator do i have to be to be able to do what administrator should be able to do (everything)

I coded a program and had another execution issue, looks like windows 7 doenst transfer permissions to files correctly if this file was executed using shortcuts that were executed by another application.
For example u have a shotrcut leading to program that executes another program. u execute this shortcut using yet another program and u have a problem, the final destination is not executed somenow, yet all program functions worked. To fix it i had to go back to Windows XP and i love it :)

TO be hones man if u realy need something to bo copied to where u want it, use that bat to exe converter i gave u link to and compile using 1 simple option (add administrator manifest). This will solve ton of problems. In fact it works so great that it even lets o owerwrite system files such as dll's ad any other. To bad W7 wont let u do it unless u are some kind of super duper administrator or something.
In fact it would solve my problem but my script is to complex to run in CMD, so i had to code it in language.

Good luck
CMD rocks
 


Last edited:
You can also use iexpress that is in 7 (all version of windows actually). Then run the built exe as admin.

I also wanted to add,, that I am glad it is not so easy to put files in the Root of C: This is a good thing.
You will need to work around it if it is what you need to do.
 


Last edited:
Turn off UAC as long as you have set yourself to an administrative account, not a limited account.

Limited accounts are for newbies and children.
 


Last edited:
I agree with reghakr. To fix the problem you need to know why it's happening first. Disable UAC (reboot after you disable it) then try it. If it works, then you know your problem. And yes, contrary to what you hear, it is safe to disable UAC, it is nothing but a nuisance.


 


And NO, contrary to what you hear, it is NOT safe to disable UAC.

The problem discussed in this thread is an issue with rights.
By default you do not have exclusive rights to write anything to the C: drive. This is a good thing.


In fact I was just discussing this today.

People bitch and complain about XP's lack of security. Now it's there and people complain about that.
With Security comes inconvenience. Deal with it, or be unsecured. **Edited**

Maybe that comes across a bit harsh, but honestly, it needs to be said.

What I will say is that this has been discussed to death. And yes,,, UAC is not perfect, but it can and does save some people from getting hit with nasty crap, or doing things they shouldn't, so long as they pay attention to the prompt,, if they ignore it? then yes,, it's useless. but that has more to do with social Engineering. And that is partly what UAC is trying to do. Make people more security conscious ( perceiving, apprehending, or noticing with a degree of controlled thought or observation) about the decisions and things they do.

Advising people to turn it off cause you think it's a nuisance is irresponsible. It is a security feature that can be useful.
 


Last edited:
True if user is a newby. Problem effects advanced users like me and most of us here/Programers/Coders/Scripters and anyone else but those who is not like that child on TV that promots Windows 7 comes out on 10/20/09 tomorrow :)
Microsoft thinks everyone is stupid.
To prove it try calling any of your electronic customer service and see for your self.
1st question is: are you sure its pluged it ? (what ? yes it is u idiot)
2nd question is : are you sure you pressed the power button ? (no i cant switch channel because i forgot to turn it on dumb dumb)
you get the idea.
Even if i would try to tell them that i need some advanced tech help they would still ask me those stupid questions, like network issues with ports and firewalls (thats for network geeks) but still am trying to tell them where am at and they would still ask me if i am connected. YES i an connected to you in live chat you idiot.

W7 should have had an option to setup your windows according to your level of expirience.
Stupid
SO SO
Regular
I know some stuff
Advanced
PRO
and
GOD

If it had these options which would add/remove some of windows default features life would be easier for most of us (i think) :)
 


Last edited:
If I secretly watched 100 people using UAC at default settings (Vista or 7) I'm sure not 1 of those people would read the prompt, or, they would read it, and regardless of said prompt, allow it anyway. Yes, maybe the op is not advanced enough to disable UAC and I shouldn't encourage it, but in answer to his original question, the UAC is most likely the reason he can't save to the root of c:\

The biggest security threat are the users themselves and UAC does not solve that problem. I expect to see/hear/read just as many people complain about "slow" Win 7computers that are infested with malware and viruses as I have with XP and Vista.
 


But what you don't realize is how many non-techy people do visit these forums.

And I can tell you have never worked Help Desk Support.
Have any idea of the number of people who think they know something,
then you throw the magic down and they say,, and I quote "hunh? how did you do that?" "What was the problem?"
and what I want to say... "I don't know, you tell me, you think you know so much." <,, But I can't unfortunately.

Trust me,, you would be supprised at the power button question... "Please turn off the PC so we can shut it down." ,,,, waiting alloted time..... "ok,, turn it back on."
"The same thing is on the screen...." ,, You mean you are at the login screen?" ,, "No, the exact same things are on the screen." ,,, Did you hit the power button on the PC or the Monitor? ,,, The monitor,, isn't that what you asked?"

So,, thier questions a lot of times are truly legit.

However,, you also have idiot,, off the street,, non-techy people working on some Help Desks that rely on Scripts to tell them how to fix a problem.

Regardless,,, any way,, there are steps you can take to be a true admin on a 7 box.
 


The biggest security threat are the users themselves and UAC does not solve that problem
But it can help if they are informed properly.

Most people (and many of them in the industry) do not inform others properly,, and that is where the real problem lay.

Regardless, I stand by my earlier statement....

Advising people to turn it off cause you think it's a nuisance is irresponsible. It is a security feature that can be useful.
 


Last edited:
If I was a newbie and was afraid of the UAC prompt, I would get nothing accomplished at all

UAC is so stupid, it asks you if you'd like to run a Micro oft program.

Yea, that would be dangerous.

It also slows down the work you want to perform on your computer.

I have always turned it off the very first time I install and have never had any problems whatsoever.

UAC is garbage.
 


That is your choice.

But I do not see it as garbage.

To be honest,, I really do not see it that much, depending on what I am doing.

Now, if like you,, you are tearing into the OS,, ok,, disable it,, it's your risk,, and you know them.

But telling Joe Schmo that it's garbage and to turn it off is irresponsible, as it is a usefull tool that does save people from some things,, not everything,, but you have to be aware... Is it going to save everyone? No ,, Most people are idiots who don't pay attention to what they are clicking on and click every popup add they see,, "Oh look pretty. damn windows sucks I got a virus" ,, that's their own damn fault.

Anyway,, I digress..... .......... .........
 


Back
Top