Running msi installer command line - c#

I am building msi installer using wixsharp with silent installation using command line without any User Interface. I am having many custom action methods similar to the following for checking prerequisite conditions. I want to warn the users if prerequisite conditions are not met.
var project = new Project("ProductName",
new ManagedAction(new Id("OSVersion"), Check.CheckOSVersion, Return.check, When.Before, Step.InstallInitialize, Condition.NOT_Installed));
Custom action methods returns ActionResult.Failure if conditions are not met.
My batch script is below
start /wait msiexec /i Installer.msi /qn /l*v installerlog.log
if "%errorlevel%" == "1013" goto err
if "%errorlevel%" == "1603" goto err
:err
echo "Error: Msiexec failed with errorlevel = %errorlevel%"
pause
exit /b %errorlevel%
Is it possible to make the MSI installer return custom error code and custom error messages like "OS Version Invalid" and display the same in command line. ?

You cannot change the msiexec exitcode - it returns a Windows value, not one you can customize.
Custom error messages are typically done with a custom action that calls MsiProcessMessage with INSTALLMESSAGE_ERROR, and they'd go in the MSI log too.
I don't know exactly what displaying the error in the command line means, but a silent install really is a silent install and the install won't display anything. In what way do you want a silent install but also display a message, making it non-silent? Will the /qb options work so that you see progress and errors?

Related

Customize msiexec progress bar?

My application call msiexec to run uninstall.
logger->LogDebug("Actions: MsiUninstallExec()!");
System::Diagnostics::Process ^p = gcnew System::Diagnostics::Process();
p->StartInfo->FileName = "msiexec";
p->StartInfo->Arguments = "/x " + AppSetting::ProductCode;
p->Start();
/// -->>> Uninstall
/// -->> Choose restart or not.
/// -->>> Application Exit
When uninstallation is done, users have to choose restart or not to complete this process.
But my customer request : "The progress bar of msiexec must move to the last (right end)."
How to edit it ? Do you have any idea for me?
Suggestion: You can try something like this (find product GUID):
msiexec.exe /X {PRODUCT-GUID} /QN REBOOT=ReallySuppress /L*V "C:\Temp\msilog.log"
Quick command line explanation:
/X {PRODUCT-GUID} = run uninstall sequence for specified product
/QN = run completely silently
/REBOOT=ReallySuppress = suppress reboot prompts
/L*V "C:\Temp\msilog.log" = verbose logging at specified path
Alternatives: There are many ways to invoke MSI uninstall: Uninstalling an MSI file from the command line without using msiexec. You can uninstall via: msiexec, ARP, WMI, PowerShell, deployment Systems such as SCCM, VBScript / COM Automation, DTF, or via hidden Windows cache folders, and a few other options.
msiexec.exe: There are two flavors of the msiexec.exe command line. An original one and a later one that added the "full word" switches such as /quiet and /noreboot and the likes. The original command line used /qn as the switch for silent mode. Here are links to both flavors: MSIEXEC what is the difference between qn and quiet.
Some Links:
Silent installation of a MSI package
How can I find the product GUID of an installed MSI setup?
How to report msi installation status on quiet install
msiexec /passive /x ProductCode
This should give you just the ProgressBar UI. You can also ask the user whether they want to skip restart or always force restart when the Uninstall completes. Then can add the /norestart or /forcerestart option appropriately.

WIX Installer with WPF bootstrapper does not set %ERRORLEVEL% variable

I have an installer written in WIX, that has a WPF Bootstrapper. Recently we added a silent installation mode, and we need to use return codes in order to specify what kind of error occurred during silent installation, for instance: invalid username or password, incorrect server address, unsupported Windows version, etc.
We use the Engine.Quit() method from Bootstrapper class to exit the installer with an exit code. This exit code can be seen in the installer log:
[5490:4F84][2018-09-14T14:31:03]i007: Exit code: 0x101, restarting: No
However, when I check the %errorlevel% environment variable, it remains unchanged. Using Environment.Exit() did not help either.
I suspected, that MSI might be responsible for such behavior by overwriting what WIX tried to set, but even forcing ActionResult.Failure in one of the actions of installer does not help. The MSI exit code is in the MSI log, but %errorlevel% remains unchanged:
MSI (c) (AC:9C) [14:30:59:133]: MainEngineThread is returning 1603
=== Verbose logging stopped: 2018-09-14 14:30:59 ===
Is it possibe to make WIX set the %errorlevel% to a custom value, and if yes, how can it be done?
The %ERROPRLEVEL% value is a feature that you get in batch file environments (the Windows cmd BAT shell, and also PowerShell, I believe) so you're not going to see that value outside of a scripting batch environment. It's not clear from your post if your silent install is a batch script or not.
Having said that, an MSI install process returns standard Windows error results that are documented here:
https://learn.microsoft.com/en-us/windows/desktop/Msi/error-codes
so they can't be customized. The particular errors you mentioned (such as invalid user name or invalid server address) appear to be errors from your custom action code in the MSI. People generally deal with error diagnostics in custom actions by using the logging features of Windows Installer to add your messages to the standard log file. This uses MsiProcessMessage() or equivalent as here:
https://social.msdn.microsoft.com/Forums/windows/en-US/5698aaee-11e5-4a8c-b307-f96b9eb1884f/writing-custom-messages-to-log-file-of-msi-using-msiprocessmessage?forum=winformssetup
https://learn.microsoft.com/en-us/windows/desktop/msi/sending-messages-to-windows-installer-using-msiprocessmessage
So you're not going to get errors specific to your custom actions unless you arrange to record the details in the log, as above, or put them somewhere that your silent install can see them (registry?).

Runas admin (from batch script/cmd) not working properly

I'm trying to get a batch script to run a silent install of my program. Here's the line that's causing trouble:
runas /user:domain\admin /savecred start "" "%temp%\MyProgram - 4.6.0.0\Setup.exe" /silent >> %userprofile%\Desktop\BatchLog.txt
A few notes:
"" before the file location is there to avoid issues with spaces in the location of Setup.exe
/silent is a parameter passed into Setup.exe to run a silent installation
>> %userprofile%\Desktop\BatchLog.txt pipes the output to a log file
When run as part of a batch script, Setup.exe isn't running as domain\admin. For the SharePoint savvy, SPFarm.Local is throwing a null ref (it's written in C#), indicating that the running user doesn't have DB access. Can you spot anything wrong with my use of runas here?
Running that line from the command line just pulls up the runas help screen. I'd like to find out why that's happening as well.
If I just manually run (double-click) Setup.exe (logged in as domain\admin) I don't get that null ref, indicating that my program is running properly as domain\admin.
How can I fix this line to execute my program as domain\admin?
Think that the whole command needs to be in quotes as runas only takes 1 "program" parameter. Also, the start command doesn't seem compatible with runas. Try this:
runas /user:domain\admin /savecred "\"%temp%\MyProgram - 4.6.0.0\Setup.exe\" /silent >> \"%userprofile%\Desktop\BatchLog.txt\""

Try to Automate the Build Process for C# Solution through user click

I tried to establish a process through a click button where I can do following activities.
Objective
Download the latest code from SVN.
Build 2 set of Codes to create dlls and exe-
(a)Web application in Release mode
(b)Standalone application in debug mode
Then Replace some values of keys inside config files.
Then Place them to particular location.
Steps followed so far
Created demo.bat file which will build exe and dlls for Standalone as shown below
REM * ============================Starting Setup for Standalone======================================
SET Folder= C:\Automating\Application\Source\StandaloneApp\
cd %Folder%App1
msbuild /property:Configuration=Debug App1.csproj /t:clean /t:build
cd %Folder%App2
msbuild /property:Configuration=Debug App2.csproj /t:clean /t:build
del /F /S /Q /A %Folder%Setup\*.*
XCOPY %Folder%App1\bin\Debug\*.* %Folder%Setup\*.* /S /Y /F /Q
XCOPY %Folder%App2\bin\Debug\*.* %Folder%Setup\*.* /S /Y /F /Q
Created Another bat file demo1.bat to change command prompt to VS2010 cmd prompt
%comspec% /k ""c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86
%comspec% /k ""C:\Automating\BuildAuto\BuildAutomation\demo.bat""
Created one more cmd files to download from svn
TortoiseProc.exe /command:export /URL:[URL path] /Path:"C:/Automating/Demo"
Finally A web application where from user can click button to download as per svnExport.bat and build the downloaded code as per demo1.bat.
protected void Button2_Click(object sender, EventArgs e) {
ProcessStartInfo psi = new ProcessStartInfo(#"C:\AutomatingPOC\BuildAuto\BuildAutomation\demo1.bat");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = false;
psi.CreateNoWindow = false;
Process.Start(psi);
}
Downloading event is working correctly, but build is not working. I need help on how can I build the code
Why reinventing the wheel? Use available tools, such as TeamCity and msbuild (there are plenty other alternatives as well).
I found Eugene made a really nice introduction here.
People spent man-years developing and polishing build automation tools. If I were you, I would stop right there and had a look around.
if you set psi.UserShellExecute to false, then you will need to specify that the command to execute is actually "cmd.exe" and that the batch file is an argument. You'll also have to manages the delay between the time that the request is made and the time the build is actually completed.
automating a task like this can be done easily with Auto Hot Key. also to automatically download you can use the start command and the type of browser of your choice IE Firefox iexplore chrome ~ then you can automate the download. but do note that with some websites page number may change IE.This address has a specified page code:
Try to Automate the Build Process for C# Solution through user click
so instead of putting the regular address in the batch or what ever you chose to use you can put in
https://stackoverflow.com/questions/********
allowing it to find the information
or you can use a mouse/key-board recorder to automate the task.

silent uninstall msi package command WITHOUT administrative rights

I am trying to uninstall a program from my visual studio project but that seems to requiere me to run vs as an admin....so i tried doing this from the cmd to debug it .
I have managed to uninstall a msi setup project installation with this command from cmd :
msiexec /x {3A40307D-6DF2-4412-842F-B1D848043367} /quiet , but that only works when i start cmd as an admin, without admin rights it wont uninstall. What am i doing wrong and is there another approach to get the result I want?
I want to be able to silent uninstall an application without having to ask the user to login as an admin.
Edit:
This is the result from the log :
Error 1001. Error 1001. Unable to delete file C:\ProgramData\XXX.InstallState.
DEBUG: Error 2769: Custom Action _F6174138_B428_4AB6_9FEF_C4DD7A69BDC0.uninstall did not close 1 MSIHANDLEs.
The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2769. The arguments are: _F6174138_B428_4AB6_9FEF_C4DD7A69BDC0.uninstall, 1,
CustomAction _F6174138_B428_4AB6_9FEF_C4DD7A69BDC0.uninstall returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 17:54:40: InstallExecute. Return value 3.
Action ended 17:54:40: INSTALL. Return value 3.
MSI (s) (F0:3C) [17:54:40:355]: Product: XXX -- Removal failed.
That error from the log file indicates that a custom action is crashing. You'll want to investigate the root cause of that issue. My guess is that the custom action requires elevation (admin privileges) to work correctly but is not marked deferred (i.e. runs during the part when the MSI is elevated).
If you launch the uninstall of the MSI from Add/Remove Programs (Programs and Features) then you should not be prompted for elevated credentials. Thus the root issue probably is this custom action.
It appears you have several options here. All of them require creating an msi that doesn't require Admin privileges from the start. If the msi requires them from the start (eg, you have no control over the creation of the msi), there is no way around it. It all depends on what files are being edited as to whether or not admin rights are really required. Check out this answer: How can I create a windows installer MSI that does not require admin access

Categories