Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8176691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:17:48+00:00 2026-06-06T23:17:48+00:00

I have two processes in my app. 1. myService.exe which is a windows service.

  • 0

I have two processes in my app.
1. “myService.exe” which is a windows service.
2. “myApp.exe” which is located in the same directory as “myService.exe”.

This process is spawned by “myService.exe” using the CreateProcessAsUser api. We have to use this api instead of directly starting the process (using system call) as we need to access the current user’s vpn profiles.

When I hard code the path of “myApp.exe”, it works fine and process is created but the same path got by getting current directory of “myService.exe” is not creating the process and returning the errorcode 2 (File Not Found).

I’m using Visual Studio 2008. The project is compiled in ASCII mode and not Unicode in code below. I tried using Unicode api’s (without the ‘A’ in the end). It didn’t work either.

The problem isn’t in getting the current path. It is verified that the path is not the System32 folder.

    HANDLE hToken;
LPSTR exePath = GetCommandLineA();
string exePathStr = exePath;
char fileExeChar[256];
strcpy(fileExeChar,exePathStr.c_str());
string serverExe = "myService.exe";
for(unsigned int i=0;i<exePathStr.length()-(serverExe.length() + 1);i++)
{
    fileLocation += fileExeChar[i];// removing the service.exe from the path

}
LPSTR fileLocationLp = const_cast<LPSTR>(fileLocation.c_str());

LPCSTR progName = (LPCSTR)"myapp.exe";

char errStr[100];
DWORD dwCreationFlag = NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE;
STARTUPINFO si;
PROCESS_INFORMATION pi;
int k = WTSQueryUserToken (WTSGetActiveConsoleSessionId (), &hToken);
ZeroMemory( &si, sizeof( STARTUPINFO ) );
si.cb = sizeof( STARTUPINFO );
si.lpDesktop = (LPSTR)"winsta0\\default";
    ZeroMemory( &pi,sizeof(pi));
if ( !CreateProcessAsUserA(
                      hToken,
                      progName,
                      fileLocationLp,  
                      NULL,
                      NULL,
                      FALSE,
                      dwCreationFlag,
                      NULL,
                      NULL,
                      &si,
                      &pi
          ) )
{
    sprintf(errStr, "CreateProcessAsUser Failed %d\n", GetLastError());
} 
else
{
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
    CloseHandle(hToken);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:17:49+00:00Added an answer on June 6, 2026 at 11:17 pm

    Windows Services, by default, execute in the System32 directory. This is why it cannot find the other executable when the absolute path of it is not specified. You can confirm this by obtaining the GetCurrentDirectory() from the Windows Service.

    To resolve this (assuming the Windows Service and the other executable reside in the same directory):

    • obtain the full path of the Windows Service executable using GetModuleFileName(), passing NULL as the first argument.
    • extract the directory from the full path
    • then build the path to other executable and pass it to CreateProcessAsUser() or change directory of the Windows Service using SetCurrentDirectory()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two processes which access to the same physical memory(GPIO data addr). So
Two Windows processes have memory mapped the same shared file. If the file consists
I have two processes - a user process and a root-level LaunchDaemon. I'd like
I have two ASP.NET sites (they can not run in the same process) and
I have Process objects that are monitored from two different views. A Windows.Forms.ListView (actually
We have a web app which can upload files to S3. For this to
I have a small app on Heroku's cedar stack that uses two processes. One
I have 3 processes which need to be synchronized. Process one does something then
Hi All, I have an application (windows service/C#) which starts EXCEL and POWERPOINT and
I have two processes: Writes to two tables every second (ish) Reads from said

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.