2

I'm trying to create a client process in a user session from a service, by using CreateProcessAsUser. But when I debug it with VS 2010, CreateProcessAsUser fails and error code is 0, error message is

cannot create a file when that file already exists

If I distribute it and install with the installer, it seems CreateProcessAsUser occasionally fails with this error. I'm quite curious about what file it is trying to write to.

Personally I don't think it is the client trying to write something. Since CreateProcessAsUser just starts the process and initialize it, then return.

I do use a different way to install the service than the installer does. Would that be the cause?

Here is the code

ZeroMemory(&m_processInfo, sizeof(PROCESS_INFORMATION));

STARTUPINFO si;
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.lpDesktop = "winsta0\\Default";
si.hStdError = m_stdOutWrite;
si.hStdOutput = m_stdOutWrite;
si.dwFlags |= STARTF_USESTDHANDLES;

LPVOID environment;
BOOL blockRet = CreateEnvironmentBlock(&environment, userToken, FALSE);
if (!blockRet) {
    throw XArch(new XArchEvalWindows);
}

DWORD creationFlags = 
    NORMAL_PRIORITY_CLASS |
    CREATE_NO_WINDOW |
    CREATE_UNICODE_ENVIRONMENT;

BOOL createRet = CreateProcessAsUser(
    userToken, NULL, LPSTR(command.c_str()),
    sa, NULL, TRUE, creationFlags,
    environment, NULL, &si, &m_processInfo);

DestroyEnvironmentBlock(environment);
CloseHandle(userToken);
Falko
  • 17,076
  • 13
  • 60
  • 105
Jerry
  • 1,704
  • 5
  • 20
  • 40

0 Answers0