I am trying to code an executable that will call an exe file when run.
The windows location of the file is:
"C:\\Users\\User1\\AppData\\Local\\Apptest\\Application\\apptest.exe"
Because it is located inside Local App Data folder for the user profile, it needs to be called with %LOCALAPPDATA%
short-cut because I will share the execurable with others.
The below code calls above path via a short-cut:
"%LOCALAPPDATA%\\Apptest\\Application\\apptest.exe"
but it does not work.
#include "stdafx.h"
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <errno.h>
#include <ctype.h>
#include <shellapi.h>
#include <tchar.h>
#include <time.h>
#include <iostream>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
STARTUPINFO siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);
if (CreateProcess(_T("%LOCALAPPDATA%\\Apptest\\Application\\apptest.exe") ,NULL, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &siStartupInfo, &piProcessInfo)){
WaitForSingleObject(piProcessInfo.hProcess, INFINITE);
CloseHandle(piProcessInfo.hProcess);
CloseHandle(piProcessInfo.hThread);
}
else {
MessageBox(0, TEXT("Can not start program"), TEXT("AppTest"), MB_OK);
exit(0);// Shutdown on fail
}
return 0;
}
How is %LOCALAPPDATA%
short-cut is used in CreateProcess
?