help copying a file into system32 folder

#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<fstream>

using namespace std;

int main(int argc,char *argv[])
{
char name;
ifstream ifs("c:\\alien.jpg", ios::binary);
ofstream ofs("%systemroot%\\System32\\oobe\\info\\backgrounds\\hello.jpg", ios::binary);
ofs << ifs.rdbuf();
cout<<"success\n";
getch();
return 0;
}

i am trying to copy the image alien.jpg to c:\windows\system32\oobe\info\backgrounds folder. when i run this code i am getting success message but the file is not being copied to backgrounds folder.

Someone please help.
%systemroot% is a batch variable (environmental variable), I'm not sure that C++ will know what that means.*

(Maybe) try: http://cplusplus.com/reference/clibrary/cstdlib/getenv

______________
*Okay so the C++ compiler does NOT understand the syntax from the environment, but it's in a string, so perhaps the ostream constructor could do something with it. I doubt it will, but maybe...
Last edited on
closed account (4i67ko23)
Doesn't your program need admin permission to copy files to the windows folder?
i also tried running the program as administrator but its not working
closed account (DSLq5Di1)
Why are you copying a file with <fstream>??

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363851
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762181
Topic archived. No new replies allowed.