i’m having a problem in windows 7 which is likely something to do with the way windows handles user files in certain locations on the drive. i’m using a share to copy a file to the remote computer. i’m then adding that file as a service. the problem is that the scm doesn’t see the file … it gives me file not found errors.
are there permissions i can set once i copy the file to the share?
HSCM = OpenSCManager(hostname.c_str(), SERVICES_ACTIVE_DATABASE, GENERIC_READ | SC_MANAGER_CREATE_SERVICE | SERVICE_START);
wstring remote_file_location = L"\\\\" + *hostname + L"\\admin$\\system32\\" + Service::GetServiceName() + L".exe";
CopyFile(&local_file_location[0], &remote_file_location[0], false)
SC_HANDLE h_service = CreateService(HSCM, servicename.c_str(), servicename.c_str(), SC_MANAGER_CREATE_SERVICE, SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START, SERVICE_ERROR_IGNORE, (L"%SYSTEMROOT%\\system32\\" + servicename + L".exe").c_str(), NULL, NULL, NULL, NULL, NULL);
Storing the file in the %systemroot% directory solved this issue. The file is now available to all users.