Purpose . I am trying to send some files from my client to the server. I use "rsync" to transfer data. I use CreateProcess APi and pass the rsync path along with the parameters.
A positive case . When I send data from local drives, such as "C:" where my windows are installed, the above method works correctly and transfers the data.
Problem . When I try to send data to a mapped drive (shared network drive). CreateProcess fails, but the error I get is rsync cannot find the file. The same rsync command, when I run on the command line, all files are transferred successfully without any errors, but the files cannot be transferred using CreateProcess.
Code :
int CreateRsyncProcess(const wchar_t * ptrCommand)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
SECURITY_ATTRIBUTES sap,sat,sao;
HANDLE out;
DWORD pwExit;
memset(&si,0,sizeof(si));
si.cb=sizeof(si);
wstring cmd = L"";
cmd.append(ptrCommand);
sap.nLength=sizeof(SECURITY_ATTRIBUTES);
sap.lpSecurityDescriptor= NULL;
sap.bInheritHandle=1;
sat.nLength=sizeof(SECURITY_ATTRIBUTES);
sat.lpSecurityDescriptor= NULL;
sat.bInheritHandle=1;
if(!CreateProcess(NULL,(LPWSTR)cmd.c_str(),&sap,&sat,1,CREATE_NO_WINDOW,NULL,NULL,&si,&pi))
{
DWORD err = GetLastError();
if(out != INVALID_HANDLE_VALUE)
CloseHandle(out);
return 1;
}
WaitForSingleObject(pi.hProcess,INFINITE);
GetExitCodeProcess(pi.hProcess,&pwExit);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
if(out != INVALID_HANDLE_VALUE)
CloseHandle(out);
TerminateProcess(pi.hProcess,0);
return pwExit;
}
Rsync Cmd : "C: \ Program Files \ cwRsync \ bin \ rsync.exe" -cvriHPDkREL --no-implied-dirs --stats -e '"C: \ Program Files \ cwRsync \ bin \ ssh" -o StrictHostKeyChecking = no -i "C: \ Program Files \ cwRsync \ bin \ rsync-key" '"/ cygdrive / Z / 64Bit" user@server.com : ~ / 6a90c592-2b3b-4088-8942-2106776c863a /
Does this happen due to some security or security issues related to creating CreateProcess or something else? Please help as I am stuck on this.
thank
The EDIT: . This works fine as a normal process, but when I run it in a service, it fails. Thus, the main problem is that the service does not have access to network resources. Any workarounds for this?