I was trying to setup Nginx, so I wanted to make a small service so that I could run it without logging on. I have a bat file that calls both nginx and a php server, shown below
start C:\wiki\nginx-1.7.11\nginx.exe
IF errorlevel 1 goto EXIT_FAILURE
start c:\wiki\php-5.4.39-Win32-VC9-x86\php-cgi.exe -b 127.0.0.1:9000 -c c:\wiki\php-5.6.7-Win32-VC11-x86\php.ini
IF errorlevel 1 goto EXIT_FAILURE
REM exit command can take /B to only exit script instead of command, and then a number specifying the error level
EXIT
:EXIT_FAILURE
EXIT 1
this batch file works when I just double click on it, but when I attempt to run it from within visual studio, Nginx doesn't start.
I run it in visual studio with the command below, where CMD is the string "/c pathtothebatfile". It doesn't seem to work regardless of whether I am Administrator or a local account.
if (!CreateProcess(
//userToken,
"C:\\Windows\\System32\\cmd.exe", // No module name (use command line)
CMD, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi // Pointer to PROCESS_INFORMATION structure
))
{
printf("CreateProcess failed (%d).\n", GetLastError());
}
I have also tried registering the exe as a service. From within the service I can set the property LOGON32_LOGON_SERVICE, and try running it as the user LocalService as well. However I can run a batch file like this, but neither the nginx server, nor the phpserver show up in Windows Task Manager's System Processes, so I assume they cannot start.
My guess is that I can't run nginx or the phpserver without certain privileges or using a certain user account.
I am sure I can either use someone else's service and get nginx to start up without requiring me to log into windows.
However, I would really appreciate it if someone could explain to me what i was doing wrong for my own development as a coder.
start C:\wiki\nginx-1.7.11\nginx.exe
IF errorlevel 1 goto EXIT_FAILURE
start c:\wiki\php-5.4.39-Win32-VC9-x86\php-cgi.exe -b 127.0.0.1:9000 -c c:\wiki\php-5.6.7-Win32-VC11-x86\php.ini
IF errorlevel 1 goto EXIT_FAILURE
REM exit command can take /B to only exit script instead of command, and then a number specifying the error level
EXIT
:EXIT_FAILURE
EXIT 1
this batch file works when I just double click on it, but when I attempt to run it from within visual studio, Nginx doesn't start.
I run it in visual studio with the command below, where CMD is the string "/c pathtothebatfile". It doesn't seem to work regardless of whether I am Administrator or a local account.
if (!CreateProcess(
//userToken,
"C:\\Windows\\System32\\cmd.exe", // No module name (use command line)
CMD, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi // Pointer to PROCESS_INFORMATION structure
))
{
printf("CreateProcess failed (%d).\n", GetLastError());
}
I have also tried registering the exe as a service. From within the service I can set the property LOGON32_LOGON_SERVICE, and try running it as the user LocalService as well. However I can run a batch file like this, but neither the nginx server, nor the phpserver show up in Windows Task Manager's System Processes, so I assume they cannot start.
My guess is that I can't run nginx or the phpserver without certain privileges or using a certain user account.
I am sure I can either use someone else's service and get nginx to start up without requiring me to log into windows.
However, I would really appreciate it if someone could explain to me what i was doing wrong for my own development as a coder.