Run a program taking parameters after installation - command-line

I have a Windows Service and I've created an installer for the service in the same project.
Now I want to deploy my service. So I've added a new project in my solution (Wix Setup Project).
What I want now is to run my program i.e. my Windows service after installation and send a parameter so that service installs. For example the command line shuld be like this:
MyService.exe /I
And also a want to send a parameter /U to uninstall my service.
Thanks

I've solved this on my own.
<InstallExecuteSequence>
<Custom Action="InstallWinService" Before="InstallFinalize">NOT Installed</Custom>
<Custom Action="UninstallWinService" Before="RemoveFiles">Installed AND NOT REINSTALL</Custom>
</InstallExecuteSequence>

Related

Run node module in guest executable

I've got a global npm package installed, TileServer, that I run as service through command line. I'd like to convert this to a guest executable in service fabric, but I'm having trouble implementing.
Pre-Guest executable, I would invoke the following command in cmd:
tileserver-gl-light --port=8788 map.mbtiles
My configuration for my guest executable is:
<ExeHost>
<Program>tileserver-gl-light</Program>
<Arguments>--port=8788 c:\maptiles.mbtiles</Arguments>
<WorkingFolder>Work</WorkingFolder>
</ExeHost>
Unfortunately, the error I get when trying to run the service just says "There were deployment errors. Continue?"
Any ideas on how to get this working?
Thanks!
Can you check to see if that application package validates on your local machine by calling Test-ServiceFabricApplicationPackage?
Usually SF expects the file to be
Present in the application package and
Some sort of executable file that the OS understands (for windows .bat, .exe, etc.)
In this case I think what you're saying is that the tileserver bits are actually outside the package (wherever your node packages are), and you're actually trying to use node to start it (since the tileserver-gl packages aren't natively executable by Windows).
If that's the case your program should probably be something like a batch file that just says "tileserver-gl-light" and then your command line args in it.
Include that batch file in your code package and reference that as your program (and straighten out how you want to pass the args) and you should be good to go.
As #masnider pointed out, the files must be present in the application package, and we must call the executable as something the OS understands. This presents particular challenges for node modules as:
They must be wrapped in a .bat
They can't be called using the global command
They need parameters
They files, node_modules, often has issues with file path length issues
My end service had the following file structure:
- ApplicationPackageRoot
- MyService.ServicePkg
- Code
- 7za.exe
- node.exe
- npm.7z
- start.bat
My ServiceManifest.xml had these values in it:
<SetupEntryPoint>
<ExeHost>
<Program>7za.exe</Program>
<Arguments>x npm.7z<Arguments>
<WorkingFolder>CodeBase</WorkingFolder>
</ExeHost>
</SetupEntryPoint>
<EntryPoint>
<ExeHost>
<Program>start.bat</Program>
<Arguments><Arguments>
<WorkingFolder>CodeBase</WorkingFolder>
</ExeHost>
<EnvironmentVariables>
<EnvironmentVariable Name="Port" Value="8788"/>
<EnvironmentVariable Name="TilePath" Value="mytiles.mbtiles"/>
</EnvironmentVariables>
</EntryPoint>
And finally, my start.bat was comprised of the following line:
.\node.exe npm/node_modules/tileserver-gl-light/sc/main.js --port=%Port% %TilePath%
So how did this work? The npm.7z in the Code consisted of my node_modules, pre-zipped. The 7za was the portable version of 7zip which allows use to get around the file path length issues present on windows. 7za is called in the SetupEntryPoint.
Then the SF calls start.bat, which reads in the environmental variables of Port and TilePath. This has to called the exactly .js file called by the normal tileserver-gl-light command.
Doing this results in a properly working node application in a service fabric guest executable.

Powershell remote installation has problems with setup of util:ServiceConfig wix element during installation

I would like to ask you if there is any other way how to setup parts of wix element - util:ServiceConfig other than in MS installer?
I need to configure this parts of wix element:
FirstFailureActionType="restart"
SecondFailureActionType="restart"
ThirdFailureActionType="restart"
ResetPeriodInDays="1"
RestartServiceDelayInSeconds="60"
When I make comment from whole "util:ServiceConfig" part of code and build installer, everything is fine and remote installation will be executed without issues.
I am trying to find way how to configure it besides Microsoft installer but google did not give me desired answers.
Or is there any other solution how to make PowerShell remote installation somehow process that configuration?(I mean user rights and permissions or something similar)
I have found solution for this problem by myself.
I have created Custom action which is executing command calling "sc.exe failure" and configure FailureActions in that command.
I deleted whole util:ServiceConfig wix element and replaced it with this:
<CustomAction Id="ServiceRestarter"
Directory="INSTALLFOLDER"
ExeCommand=""[SystemFolder]sc.exe" failure "ServiceName" reset= 86400 actions= restart/60000/restart/60000/restart/60000"/>
<InstallExecuteSequence>
<Custom Action='ServiceRestarter' After='InstallFinalize'>(NOT Installed)</Custom>
</InstallExecuteSequence>
Now my PowerShell script doesn't have problem with remote installation of .msi package. Cheers, I hope it will help someone else than me.

Calling External Command From Powershell Plugin

I have an application process that runs in IBM UrbanCode. The process uses a Powershell Script that uses the CloudFoundry CLI. Our application process runs on an agent on which the CloudFoundry CLI is installed and available on the Path. Strangely enough, the Powershell plugin doesn't know that the CloudFoundry CLI is on the path. Echoing out the path via the plugin itself confirms this.
Currently, our application process looks like:
Copy CloudFoundry CLI into UCD's workspace at the start of the job.
Execute various CloudFoundry commands via the following sytax: .\cf login -u foo -p bar -o baz -s bart
I want to avoid copying the client into the workspace and having to use the .\cf sytax in order to make the scripts more portable.
How can I get the Powershell plugin to respect the Agent's path?
Sounds like the user that your powershell agent is running under does not have CloudFoundry in its path. options are
1. Ensure the PATH variable is set system wide.
2. instead of copying the CloudFoundary CLI you could manually add the path to CloudFoundry before you run the script
$env:Path += ;<PATH TO CLOUDFOUNARY>
Note: this will only persist for the current session.
To test that you have CloudFoundary in the path you can use
Get-Command cf

Startup Task not running on Azure Cloud Service role

I'm having difficulties trying to setup a startup task in an Azure role.
The ultimate goal is to disable RC4 cipher, along with other SSL configurations. In my (VS2012Express) project (solution partially achieved following another answer here in SO that led me to https://gist.github.com/sidshetye/29d6d48dfa0c2f5488a4 ) I created a Startup.cmd file like this:
# Execute powershell command to disable RC4 and imporve SSL security settings
ECHO Batch started >> "StartupLog.txt" 2>&1
PowerShell -ExecutionPolicy Unrestricted .\HardenSSL.ps1 >> log- HardenSSL.txt 2>&1
EXIT /B 0
HardenSSL.ps1 is the PowerShell script from the previous link. Both the .cmd and .ps1 scripts are placed in the application root directory, marked as "Content" with properties set to "CopyLocal=Always".
In my service definition, I put this:
<Startup>
<Task commandLine="Startup.cmd" executionContext="elevated" taskType="background"></Task>
</Startup>
Now, when I deploy the application to Azure, "nothing" happens. I configured the role instance to allow remote desktop, connected to the machine. I verified the scripts where published, and there were no log files, RC4 still enabled. I tried to manually run the .cmd and the machine runs the scripts to completion, disables RC4 and restarts. So the scripts are actually "correct".
The problem is that the scripts are not getting fired up at startup. I may be wrong, but I don't see anything related looking Windows events. Actually, the server now keeps all the configurations, but I have to be sure the scripts get executed in case I'll have to publish to new instances/cloud services.
I also tried to:
1. place the scripts on a child directory
2. create other 2 "simpler" .cmd that just create a log file with "script started" to exclude problems related to the .cmd calling the PowerShell script.
None of those scripts got executed.
Hope I've been sufficiently clear, any help would be greatly appreciated.
Thank you in advance,
Alberto
UPDATE 1
Reading through various discussions, I missed one very important thing: the script files are actually published in 2 distinct places, one being inside the /bin folder.
Ex: I placed my scripts in a /StartupScripts folder in my project, and when I connect via Remote Desktop to the Azure server I find the scripts both in "approot/StartupScripts" and in "approot/bin/StartupScripts".
The scripts the are actually executing are those placed inside the "bin" folder. the real problem is that I have probably a path problem inside the .cmd since I now found the execution logs with an error.
Now I will try to change it up and update the question here on SO.
Ok.
In the end it was indeed a problem with a path in my Startup.cmd file: .\HardenSSL.ps1 could not be found if the StartUp Task pointed to a subfolder.
Solution was to place both Startup.cmd and HardenSSL.ps1 files in the application root, remove the ".\" part when calling the PowerShell Script and all worked well.
Anyway, I would like to suggest anyone to pick this other solution I found in stack exchage:
https://security.stackexchange.com/a/79957
It links to a NuGet package that does the same thing as the script I found on the link to github in the original post, just "better"; mainly:
Better configuration of cipher suites, with support for ForwardSecrecy for all reference browsers on SSLLabs
Retain SSL support for Internet Explorer 8 on windows XP (unfortunately still a necessity for us)
Alberto.

Start an application silently with "AsyncNoWait"?

I am trying to build an installer that will start a REST service (win32 console application) after installation silently.
I have did a lot of permutations, and can get some result, however I can't get what I want.
Here is a list of test cases:
With Filekey I can launch the application, but with console.
With "BinaryKey="WixCA" DllEntry="CAQuietExec"" I can run the application silently, but it is not asynchronous. The installer will stop and wait, and, with property, deferred custom action.
Can anybody help me figure this out?
To run an installer silently I use /qn in the command line.
So this looks something like:
msiexec /i <installername> /qn /l*v install.log
With this command the installer will run silently, without bringing up the UI. The customaction may be set such that it starts the REST service as part of the installation process. The install.log file that will be created in the same location where the installer exists is the log file for the installation.
I maybe able to help if you may share the exact command and parameters that has to be run to start the REST process.