Installing Windows Service fails when command run in batch file - windows

I'm converting a legacy VC 6 C++ Windows Service application to Visual Studio 2022
The conversion is completed and, if I open a CMD prompt with Admin rights, I can install the service using this command:
Service.exe /Install
It installs instantly and starts correctly.
However, I need to install it within an installation script, which loads a bunch of services by calling a batch file which contains the commands to start them. It is run with elevated permissions. However, which it reaches the above line (Service.exe /Install) it hangs. There is no error message and I cannot even terminate it using CTRL + C. The only way around it is to close the CMD prompt. The service is not installed.
My service does not appear in the Task manager's list of processes when the batch file hangs.
I've tried adding the full path to the service in the batch file but it makes no difference. Running this batch file from an elevated command prompt (rather than the installer script) runs into the same problem.
I'm tearing my hair out over this (almost bald now :-)) - can anyone provide any suggestions?
Thanks
Andy

Debugging found a logic error in the start up code.
Basically, calling Service.exe /Install directly from the command line just passes "Service.exe /Install" as the command line, whereas calling it from a batch file / CreateProcess() passes the whole path to the service in the command line and the parser was not taking that into account. Maybe it behaved differently in older Windows versions, but the parser was really badly written.
I'm glad it was me who wrote it :-)

Related

Why does running a .sh script from Visual Studio open the file instead of running it?

I am attempting to run an .sh script (which itself is supposed to kick off a series of unit tests in flask) from within Visual Studio Code running in Windows 10 and for some reason no matter what I try it only opens the file for editing instead of actually running the file.
This is the exact command I am typing:
C:\Users\my.user\MyRepo>.\scripts\run-unit-tests.sh
Here are my notes:
This is a brand new installation of Windows 10 where I believe I have enabled WSL2
I am completely unfamiliar with doing development from within Windows (coming from a Ubuntu/Linux background)
My goal is to run this script from within the built in terminal in VS Code, however I have also tried running it from a cmd prompt and also from powershell and both of those also result in opening the file in VS Code.
Addendum: more notes:
I actually have two windows machines. one is my personal machine, the other provided by my work. For whatever reason this file works fine on my personal machine but does not on my work machine. Also the bash script is in a repo which was created by others at my company so i'm certain that this can be made to run without modifying the .sh file itself.
I figured out what was going on.
In windows there are default file associations. Mine was set up to run Visual Studio Code for the .sh file extension. Also, windows does not know how to handle .sh files by default. There were likely many potential fixes for this however the one that worked was for me to re-associate the .sh file extension to open with Git Bash which I happened to also have installed on this machine.
Thanks all who tried to help.

Windows deletes make executable file upon running. Why?

I am trying to get some code running which uses make. I've downloaded and installed both MinGW (standard 32 bit) and TDM-GCCs flavor of MinGW on my 64-bit Windows 7 machine.
When I run make (i.e. mingw32-make.exe) in Administrator mode, I get the following error message:
Windows cannot access the specified path, or file. You may not have the appropriate permissions to access the item.
The weird/scary part is that, upon running, it immediately deletes the exe file.
I ran a checksum SHA1 as recommended in the comments using the Microsoft (R) File Checksum Integrity Verifier V2.05:
C:\path\to\folder>fciv.exe -sha1 mingw32-make.exe
//
// File Checksum Integrity Verifier version 2.05.
//
c8ae5c780ab7bed652883d6443b5bfe5e23d30c9 mingw32-make.exe
I don't understand what this output means, but maybe it's helpful to someone.
Notes:
This happens regardless of where the file is located on my pc.
This behavior is specific to the make program (others such as gfortran and gcc appear to be working fine)
Renaming the file makes no difference.
I am an administrator on the pc
Same behavior when I run the program from the explorer or command line.
My anti-virus program (Avast) does not detect any problems with the file when I scan it.
I got the MinGW setup file from this SourceForge page.
I got the TDM-GCC web installer from this page.
The file size is 219,662 bytes (from both the main MinGW and TDM-GCC packages)
I have run make from the command line where I have started the command prompt by way of selecting Run as Administrator in the context menu.
I have also tried to run make by selecting Run as Administrator when I have it selected.
I run the command mingw32-make when this behavior occurs. I have also tried renaming it to things like make and foo with the same result.
The first time this happened with both MinGW it deleted the original file and I re-installed it using the mingw-get application. From thereon after I started making copies of the original mingw32-make for testing.
For the make executable, I have all permissions (including Read & execute) except the special permissions field.
After using the process manager I found out it was indeed Avast that was the problem :S A couple of lines revealed avast actually deleted the file before windows got around to executing it, which was the reason for the windows message. I put Avast on 'Silent Mode' a while back; I thought the only purpose of this mode was to suppress notifications about minor updates, but apparently it also gave Avast permission to deal with 'threats' silently as well.
After figuring that out the solution was straightforward. I just went into the settings and created an exception for the mingw32-make.exe file. It now runs without issue.
Thanks very much for your help everyone!
User account has administrator privilege but when user started to work , not all privilege are taken in account , just start your application for compiling with run with administrator mode try this : https://technet.microsoft.com/en-in/library/cc781763(v=ws.10).aspx

How do you install dependent programs with a batch file?

I'd like to install two programs (program.exe, program_sp1.exe) via batch script.
The problem is that the first install adds environment variables that are needed by the 2nd.
Is there a good way to run the 2nd installer in a new command prompt so the values are picked up, but without user interaction to close it?
I've tried this in a Windows 7 Machine.
You should be able to run program.exe and the run cmd and then run your program_sp1.exe, and an exit as the cmd is running another version in itself with the updated environment variables.

Abort NSIS silent installer

I've created an NSIS installer that installs a certain program. Everything works fine but I wonder if it is possible to abort the installation when it runs in silent mode.
So is there a way to abort an installation when I install an NSIS installer via the command line with this command: installer.exe /S /D=Path/To/Directory?
I tried to abort it via CTRL+C as it works for other programs, too, but that didn't work.
NSIS is not a console program so it is not going to respond to console keyboard shortcuts.
Even if you could trick it into behaving like a console program when started silent it is not going to work in a stable manner because CTRL+C will just kill the process unless the program has added extra code to handle the aborting events...

Nuget.exe crashes when invoked from cmd.exe

I'm trying to automatically download Nuget.exe from a Rakefile, in order to minimize the amount of initial setup needed to run my samples on GitHub.
I've understand how to download a file (I'm using HTTParty) and how to save a binary file (using the b flag on File.new) but now I've got problem running Nuget.exe. In particular:
if I launch it directly or from PowerShell, the executable runs fine;
if I launch it from cmd or from a Rakefile (which in turn runs cmd), Windows tells me that the program "stopped working".
I reproduced the same behavior with the Nuget bootstrapper, so I thought that the cause was some configuration in my computer.
It then occured to me that I installed ansicom, a library to handle ANSI sequences. I disabled it and then Nuget started without any problem.

Resources