problem with a program that should copy a file
HI PROGRAMMERS!
i want to write a simple code that take a copy of the file from address below
C:\Windows\System32\telnet.exe
and then paste it into user desktop
if u want to say the code below its not working!
|
system("copy C:\\Windows\\System32\\telnet.exe c:\");
|
i told this on begginer part but it seems nobody can help this is the link to it
http://www.cplusplus.com/forum/beginner/183255/
please give me the whole code tnx u all!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
#include <string>
#include <shlobj.h>
std::wstring path_to_known_folder( REFIID folder_id )
{
std::wstring result ;
wchar_t* path = nullptr ;
if( SHGetKnownFolderPath( folder_id, 0, nullptr, &path ) == S_OK )
{
result = path ;
CoTaskMemFree(path);
}
return result ;
}
bool copy_from_system32_to_desktop( std::wstring file_name )
{
const std::wstring system32_path = path_to_known_folder( FOLDERID_System ) + L'\\' + file_name ;
const std::wstring desktop_path = path_to_known_folder( FOLDERID_Desktop ) + L'\\' + file_name ;
if( system32_path.empty() || desktop_path.empty() ) return false ;
else return CopyFileW( system32_path.c_str(), desktop_path.c_str(), false ) ;
}
int main()
{
if( !copy_from_system32_to_desktop( L"telnet.exe" ) ) std::cerr << "copy failed\n" ;
}
|
Topic archived. No new replies allowed.