Unable to launch a packaged executable as a Windows service via ProcRun - windows

I have a requirement to launch an executable as a windows service with help of procrun.
I followed the below steps.
Created a batch-file named run.bat, to create a service.
"C:\Program Files (x86)\Test\prunsrv.exe" //IS//Test --DisplayName="Test" --Startup=auto --Install="C:\Program Files (x86)\Test\prunsrv.exe" --StartMode=exe --StartImage="C:\Program Files (x86)\Test\batchSample.exe" --LogPath="C:\Program Files (x86)\Test\logs" --StdOutput=auto --StdError=auto
Created a batch-file, batchSample.bat, to launch a URL:
start https://www.youtube.com/watch?v=q3pG6b3uI_E
Converted the batch-file to an executable, batchSample.exe, and placed it in C:\Program Files (x86)\Test.
Executed run.bat.
At this point the the windows service, Test started without giving any error, but it did not execute the batchSample.exe as used for --StartImage.
Appreciate your help.

Your batch file is not an executable, no matter what extension you give it.
Per the docs - https://commons.apache.org/proper/commons-daemon/procrun.html
--StartImage Executable that will be run. Only applies to exe mode.
++StartParams List of parameters that will be passed to either StartImage or StartClass. Parameters are separated using either # or ; character.
You need a program to execute your batch file as StartImage (sh?), and put the batch file in StartParams.

Related

Visual Studio Code Run build task in the Windows prompt with shortcut ctrl+shift+B

I have a C program and I need to run two batch file which manage all the compilation toolchain. The First one sets the enviroment variables and the next one to be executed performs the compilation and the linking. For some reason, eventhough I am setting all the needed enviroments variables with the first batch file, some .exe that are called by the second batch file are not recognized by the VS code internal terminal (extended error message: "file.exe" is not recognized as internal command or/and an executable program or a batch file"). I have tried to run in sequence this two batch files (by directly calling it, without any shortcut) in the Windows prompt opened in VS code and the C program is successfully compiled. Thus, Is there a way to run my build task (this batch file) in the Windows prompt opened in VS code by using the shortcut ctrl+shift+b? I have tried to set some option in the settings but they do not work.
The problem is that I was calling in sequence this two batch file, namely by defining in the task.json that the compilation batch file must be executed after the other batch. But in this way, the two batch files will be executed in two different instances of the prompt, so the enviroment variable will exist only in the first prompt. That is why when the compilation batch is executed I get that problem "'file.exe' is not recognized as internal command or/and an executable program or a batch file".
In order to execute these two batch files in the same prompt it is necessary to define a task in the task.json with this command:
command: "batch1 && batch2",

Trying to open programs with bat file but always comes back invalid

I am a streamer and I need a few programs to stream. It's annoying to open all of them so I tried putting them in a batch file. I looked up the process and followed it,but every time I run the batch file it comes back invalid.
This is what my batch file looks like:
#echo off
cd C:\Program Files "(x86)\obs-studio\bin\64bit"
start obs64.exe
#echo off
cd "C:\Program Files\HexChat"
start hexchat.exe
#echo off
cd "C:\Program Files (x86)\Nightbot"
start nightbot.exe
exit
Cmd gives me an error saying it cannot find the file. When I put this into cmd by itself it opens the program.
Also is there a way to add applications from chrome to the file?
Open a command prompt window and run from within this window start /? which outputs the help for this command and explaining all options.
Following batch file most likely works:
#echo off
start "" "%ProgramFiles(x86)%\obs-studio\bin\64bit\obs64.exe"
start "" "%ProgramFiles%\HexChat\hexchat.exe"
start "" "%ProgramFiles(x86)%\Nightbot\nightbot.exe"
This batch file starts the three applications with current directory on execution of the batch file being also the current directory for the 3 started applications.
But the following batch file should be used if it is really necessary that each application is started with the application's directory as current directory:
#echo off
start "" /D"%ProgramFiles(x86)%\obs-studio\bin\64bit" obs64.exe
start "" /D"%ProgramFiles%\HexChat" hexchat.exe
start "" /D"%ProgramFiles(x86)%\Nightbot" nightbot.exe
With parameter /D and path of application's folder the Start In directory is set first like when using command CD. So for example hexchat.exe is started with current directory being C:\Program Files\HexChat for this application.
The two double quotes after command START are necessary as this command interprets first double quoted string as title for the process. By using "" an empty title string is explicitly specified resulting in rest of command line being correct interpreted as expected. I suppose those three applications are all GUI applications and not console applications and therefore a real title string being useful on running a console application in an new command process for the console window is not really necessary.
%ProgramFiles% references the predefined environment variable ProgramFiles containing path to standard program files folder for 64-bit applications on 64-bit Windows when batch file is started with 64-bit cmd.exe as default on 64-bit Windows and is replaced by Windows command interpreter before execution of the command line on your Windows computer by C:\Program Files.
%ProgramFiles(x86)% references the predefined environment variable ProgramFiles(x86) containing always path to standard program files folder for 32-bit applications on 64-bit Windows and is replaced by Windows command interpreter before execution of the command line on your Windows computer by C:\Program Files (x86).
It is of course also possible to use the real paths in your computer instead of the environment variable references if this batch file is never shared with other people.
Extra hint:
Run in a command prompt window the command you want to use with /? as parameter to get displayed the help for this command. Other sources for help on commands and predefined environment variables displayed all on running in a command prompt window set are:
SS64.com - A-Z index of the Windows CMD command line
Microsoft's command-line reference
Windows Environment Variables and WOW64 Implementation Details

7zip sfx is executing RunProgram before it extracts all the files

I have a 7 zip self extracting exe, it is archived as shown below:
[mainfolder]
start.exe (a C++ bootstrapper)
[subfolder] (contains all my applications assemblies and executable
Now my config.txt is running the start.exe (through "RunProgram") which will actually run a executable in [subfolder]. Now this is failing as the extraction all the files in [subfolder] is still not complete (i did find all files in extraction location) by the time "start.exe" is started.
One other strange thing is the extraction of all files in [subfolder] is completed if at all i specify to run a exe inside subfolder in config file i.e to "RunProgram", or even i specify a random text to "RunProgram" at least the extraction is complete.
What it could be that if prefer to run a file in [mainfolder] causes the [subfolder] to be extracted incompletely? Please help.
It was a wrong analysis, the problem was not with extraction.. all the time it was extracting properly. But when i was trying to call bootstrapper it used to call another exe and exit so SFX thought the process has finished executing and was deleting files.
So when there is chain of calls from diff application care should be taken that at least the application you start from (through "RunProgram","ExecuteFile" or from any thing..) stays alive till all needy application exits.
One workaround is to nest the sfx. You first make an sfx that include all the necessary files, and then nest it together with your bootstrapper and a script to extract that and run your bootstrapper inside another sfx which will run that script.
See more: SFX with 7-zip : Is it possible to run a included .bat file before extracting the files?

Unable to open application by specifying it's location under App Paths

I have created a key(for example myapp.exe) under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" with below values in registry.
(Default) --> C:\Program Files\folder1\folder2\myapp.exe
Path --> C:\Program Files\folder1\folder2\;
Then I opened a command prompt and tried to open my application. But I am getting an error like "'myap.exe' is not recognized as an internal or external command,operable program or batch file."
If I add the directory where my application resides to Path environment variable, then I am able to run the application successfully from command prompt.
please let me know where I went wrong.
This is another way to start an application from the command prompt.
Create a batch file similar to the following and call it FR.BAT which is short for foxit reader in this example, and store the FR.BAT file in c:\windows or another directory on the PATH.
When you open a CMD prompt and type fr then it will launch this batch file and start the application.
#echo off
start "" "c:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe"
Just be careful not to use a name which is the same as an existing Windows command.

How to run exe before or after "RunProgram" from 7zip sfx files setting on config.txt?

I am using 7zip to pack an installation (im using 7z because i need it to work in linux and windows).
From what i've been reading the config.txt file can contains this:
;!#Install#!UTF-8!
RunProgram="Installer.exe"
;!#InstallEnd#!
But what if i need to run another exe before or after running installer.exe? Is it possible like it is in NSIS?
You can specify another progrem in 'RUnProgram' config parameter. Lets say its some .bat file. At the moment program is run, files are already extracted at TEMP location. As your .bat will run then, it can call Installer.exe once script is finished preparations.

Resources