Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

82 lines
2.0 KiB

#include "windows.h"
#include <stdio.h>
BOOL
ForceCopy(
LPCSTR lpszSourceFileName,
LPCSTR lpszDestFileName
)
/*++
Params: lpszSourceFileName Pointer to the source file.
lpzDestFileName Pointer to the destination file.
Return: TRUE on success, FALSE otherwise.
Desc: Attempts to copy a file. If it's in use, move it and replace on reboot.
--*/
{
char szTempPath[MAX_PATH];
char szDelFileName[MAX_PATH];
if (!CopyFileA(lpszSourceFileName, lpszDestFileName, FALSE)) {
if (GetTempPathA(MAX_PATH, szTempPath) == 0) {
printf("GetTempPath failed with 0x%x\n", GetLastError());
return FALSE;
}
if (GetTempFileNameA(szTempPath, "DEL", 0, szDelFileName) == 0) {
printf("GetTempFileName failed with 0x%x\n", GetLastError());
return FALSE;
}
if (!MoveFileExA(lpszDestFileName, szDelFileName, MOVEFILE_REPLACE_EXISTING)) {
printf("MoveFileEx failed with 0x%x\n", GetLastError());
return FALSE;
}
if (!MoveFileExA(szDelFileName, NULL, MOVEFILE_DELAY_UNTIL_REBOOT)) {
printf("MoveFileEx failed with 0x%x\n", GetLastError());
return FALSE;
}
if (!CopyFileA(lpszSourceFileName, lpszDestFileName, FALSE)) {
printf("CopyFile failed with 0x%x\n", GetLastError());
return FALSE;
}
}
return TRUE;
}
int __cdecl
main(
int argc,
CHAR* argv[]
)
{
int cchLen;
if (argc != 3) {
printf("Usage: fcopy SourceFile DestFile\n");
return 0;
}
cchLen = lstrlen(argv[1]);
if (cchLen > MAX_PATH) {
printf("Source file path too long\n");
return 0;
}
cchLen = lstrlen(argv[2]);
if (cchLen > MAX_PATH) {
printf("Dest file path too long\n");
return 0;
}
return ForceCopy(argv[1], argv[2]);
}