Install exe file silently using CMD and PowerShell - docker

I am trying to install an exe created using Inno Setup.
When I try to install it using PowerShell with
Start-Process -wait C:\updatefile.exe /VERYSILENT
all folders are created at proper places, registry values are created, but console hangs and does not return unless Ctrl+C is pressed.
But if I install exe using command prompt with
start /wait C:\updatefile.exe /VERYSILENT
everything goes properly and command prompt returns.
What could be cause of this anomaly?
I need this exe to install through Dockerfile, but as PowerShell install is hanging, container does not install exe. Even with cmd version in Dockerfile, container does not create install folders.
After checking logs I found that exe service is being started by installer in end. If that is reason for hanging, is there some argument I can use to exit PowerShell?

The -Wait switch of PowerShell's Start-Process cmdlet also waits for child processes of the launched process to exit[1], whereas cmd.exe's internal start command does not.
As you note in a later comment, a service executable is launched by your installer at the end; given that services run indefinitely, Start-Process also waiting for that (child) process to terminate indeed explains the hang.
Here is a simple workaround:
cmd /c C:\updatefile.exe /VERYSILENT
When an executable is called via cmd /c, cmd.exe implicitly waits until the executable's process - and only it - terminates, even if it is a GUI application, just like start /wait would.
Given the behavior described in footnote [1], another workaround is to use the -PassThru switch with Start-Process (instead of -Wait) and pipe the result to Wait-Process:
Start-Process -PassThru C:\updatefile.exe /VERYSILENT | Wait-Process
[1] See GitHub issue #15555, which also discusses that Wait-Process acts differently in that only waits for the process itself to terminate.
As zett42 points out, the behavior of Start-Process -Wait is now at least briefly mentioned in the docs as well (emphasis added): "waits for the specified process and its descendants".

try
$arguments = "/Verysilent"
Start-Process -wait C:\updatefile.exe -ArgumentList $arguments

Related

How to install Web Services Enhancements (WSE) 3.0 in a Dockerfile

I'm attempting to containerize a legacy ASP.NET application that has a dependency on Web Services Enhancements (WSE) 3.0. I understand that this is a legacy technology but refactoring the application to remove it is not an option.
My Dockerfile:
FROM mcr.microsoft.com/windows/servercore/iis
RUN mkdir prereqs
WORKDIR /prereqs
COPY ["prereqs/WSE30.msi", "c:/prereqs/"]
RUN "C:\prereqs\WSE30.msi /qn /quiet /passive"
Which fails with the following:
The command 'cmd /S /C "C:\prereqs\WSE30.msi /qn /quiet /passive"' returned a non-zero code: 1603
I've tried modifying the RUN command to include logging...
RUN "C:\prereqs\WSE30.msi /qn /quiet /passive /lv c:/logs/wse30.txt"
...but this creates a condition where the docker build just seems to hang; I've let several of these attempts run for more than an hour and they do not appear to progress or complete.
I've also tried adding an "exit 0" to simply let the build continue if there is an error...
RUN "C:\prereqs\WSE30.msi /qn /quiet /passive /lv c:/logs/wse30.txt" ; exit 0
..but the result is the same. The build appears to hang and never complete.
I know that this particular MSI supports unattended/silent installation as I've done so in batch files.
#DWRoelands , I faced the same issue but I was able to install it on the windowservercore:1909 after installing the all web-serverr and all its subcomponents components.
You will have to set the source of .Net3.5 to the downloaded file of https://dotnetbinaries.blob.core.windows.net/dockerassets/microsoft-windows-netfx3-1909.zip

Unable to start process from powershell

Folks
I am trying to invoke a batch script from a power shell file and the invocation works fine if executed manually.
Start-Process C:\USR\test.bat
However i created a service in C# which is able to delete and write logs using the powershell script however it simply ignores this step and nothing happens. Is it because this script is invoked by a windows service ?
if (Test-Path \\xxxsharepathfullper\FileWatcher\target\watcher.mon) {
echo "File removed" >> C:\USR\logger.txt
Start-Process C:\USR\test.bat
Remove-Item \\xxxsharepathfullper\FileWatcher\target\watcher.mon
}
else {
}
Execution policy is unrestricted
Check access rights on a share, maybe your admin user don't have rights to access it.
You can try run the process as administrator and log any error:
Start-Process -FilePath "C:\USR\test.bat" -RedirectStandardError "testError.txt" -verb RunAs

Powershell why popup window, how to stop it

Not sure why when I execute a Python tools like pip or nosetests inside powershell, a separate popup command line windows will show, execute my command, then disappeared. This is annoying because I can hardly see the executable output, especially the last few lines before the popup close.
I assume there are some setting I can change to stop the popup?
I am using Powershell 2.0 in Windows 7.
Powershell is not cmd.exe, and it has a different console interface. More than likely, your py tools are writing to a non-existent shell window. You may be able to get around this by using the following syntax:
cmd /c script.py
What you do when you execute the python scripts directly from the PS prompt is fire-off a DOS shell for the period of time it takes for the command to complete. Since there's no 'pause' implemented, the shell window closes when the command completes.
A test script
# tester.py, just a test
print "This is a test script, that is all."
Output in PS:
C:\src\python
{powem} [36] --> .\tester.py
C:\src\python
{powem} [37] --> cmd /c .\tester.py
This is a test script, that is all.
mp
For someone has similar problem, please have a look at this answer, I think this solution eventually solved my problem. and in my case, I have to restart my computer to get it all working.

Running multiple commands in cmd via psexec

I'm working on creating a single command that will run mulitple things on the command line of another machine. Here is what I'm looking to do.
Use psexec to access remote machine
travel to proper directory and file
execute ant task
exit cmd
run together in one line
I can run the below command from Run to complete what I need accomplished but can't seem to get the format correct for psexec to understand it.
cmd /K cd /d D:\directory & ant & exit
I've tried appling this to the psexec example below:
psexec \\machine cmd /K cd /d D:\directory & ant & exit
When executing this it will activate the command line and travel to D:\directory but won't execute the remaining commands. Adding "" just creates more issues.
Can anyone guide me to the correct format? Or something other than psexec I can use to complete this (free options only)?
Figured it out finally after some more internet searching and trial and error. psexec needs /c to run multiple commands, but that syntax doesn't work with the setup I wrote above. I've gotten the below command to run what I need.
psexec \\machine cmd /c (^d:^ ^& cd directory^ ^& ant^)
I don't need to exit because psexec will exit itself upon completion. You can also use && to require success to continue on to the next command. Found this forum helpful
http://forum.sysinternals.com/psexec_topic318.html
And this for running psexec commands
http://ss64.com/nt/psexec.html
This works:
psexec \ComputerName cmd /c "echo hey1 & echo hey2"
For simple cases I use:
PsExec \\machine <options> CMD /C "command_1 & command_2 & ... & command_N"
For more complex cases, using a batch file with PsExec's -c switch may be more suitable:
The -c switch directs PsExec to copy the specified executable to the remote system for execution and delete the executable from the remote system when the program has finished running.
PsExec \\machine <options> -c PSEXEC_COMMANDS.cmd <arguments>
Since you asked about other options and this has tag configuration managment-- I guess you may be interested in Jenkins (or Hudson). It provide very good way of creating master-slave mechanism which may help in simplifying the build process.
I always use like this way :) and works properly
psexec \\COMPUTER -e cmd /c (COMMAND1 ^& COMMAND2 ^& COMMAND3)

launch a gui program from windows console and then make it 'detach' itself

I'm trying to modify a legacy Delphi 5 app so that it can be launched either from it's icon/via Explorer, or from the console (command-line). When it gets launched from the console, I want the program to detach itself from the console process, so that the console can continue to execute other instructions without waiting for my program to terminate.
I want to use it in a 'batch' file, such that I might have;
#echo off
rem step 1 - do some stuff here
rem
rem step 2 - launch my app
c:\myfolder\myapp
rem
rem step 3 - do some more stuff here
and that the console process moves on to step 3 straight after launching my app in step 2.
I'm sure I've done this before, many years ago, but I'm puzzled as to what exactly I did. I don't want to write a tiny console app 'launcher' for my main Windows app - I'm 95% sure that there was a way of doing this within a 'normal' Delphi GUI app.
I guess I could use vbscript or powershell or something to 'execute' my program with some kind of 'nowait' parameter but the client is familiar with batch files and I don't really want to upset the applecart by suggesting he change his scripts or install additional stuff - I'm making changes to the executable anyway and it would be great to tick this box for him too.
Anyone? :-)
I think the START command is the one you're looking for. It starts a process separately to the console and it's part of cmd.exe so no extra software required.
But I was of the opinion that GUI apps did this anyway. Maybe Delphi is different to MSVC.
Open up a console and type "start /?".
As itowlson states in the comments, GUI application do generally detach themselves. It's the actual cmd.exe shell doing trickery in that it waits for it to finish if it's running from a cmd file.
So "notepad" from the prompt will start it in the background but "notepad" within a cmd file will wait. Within the cmd file, you need to use:
start notepad.exe
or whatever your application is called (not notepad, presumably).
try: start "" c:\myfolder\myapp (with the empty quotes)
I think Microsoft has been solve this problem in Windows Power Shell.
In command prompt, even if you use "start ", you cant detach your process really from cmd. If you close the cmd, you will die, suddenly. But In windows Power Shell, you can detach your program or command from Power Shell as default.
So, if you prefer to use Windows Power Shell instead of Command Prompt, just do this:
PS: X:\> <your command>
Here's one way that I've found. It works quite cleanly and doesn't leave any extra cmd windows around (the recommendation to use start c:\myfolder\myapp does not work:
cmd /c dir && c:\myfolder\myapp
To quote the CMD help:
/C Carries out the command specified by string and then terminates
Note that multiple commands separated by the command separator '&&'
are accepted for string if surrounded by quotes.
Apparently it notices that the dir command terminates and exits, even though your app was launched on the same command. Chalk it up to one of Windows vagaries.
u should use the cd command example
cd/
cd myfolder
start myapp
exit

Resources