I am working on packaging up some installers for internal use. I have the uninstall working fine with a passive switch.
As for installation, the MSI's that do not have an EULA work perfectly with the passive switch showing progress.
The EXE's that contain an EULA are the problem.
I am trying to find a way to accept the EULA without user input - note I do not have access to changing the public properties of the EXE's to set the ACCEPTEULA=1
the base I am working with right now is...
start = new ProcessStartInfo();
start.WindowStyle = ProcessWindowStyle.Hidden;
start.CreateNoWindow = true;
start.Arguments = s.args; //curent argument /qn
start.FileName = tempDir + "/" + s.executable;
start.CreateNoWindow = true;
While this code works perfectly fine with the msi's it does not work with the exe's as they all contain EULAs.
When using an exe you need to preface /qn with /v making it:
setup.exe /v/qn
Related
I am trying to insert msi file using asp.net application. when i run visual studio in administrators mode it is working fine but when i run it in normal mode it is not working.
I had tried following code:
string installerFilePath;
installerFilePath = #"D:\ActivexPractice\test\test\NewFolder1\setup.msi";
System.Diagnostics.Process installerProcess = System.Diagnostics.Process.Start(installerFilePath, "/q");
can any body guide me on this
how to install it without administrators right
You can use msiexec.exe to run installer. Here is sample code.
Process installerProcess = new Process();
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.Arguments = #"/i D:\ActivexPractice\test\test\NewFolder1\setup.msi /q";
processInfo.FileName = "msiexec";
installerProcess.StartInfo = processInfo;
installerProcess.Start();
installerProcess.WaitForExit();
If the MSI requires admin rights to install then it will ask for elevation in a UI install. Your /q is failing because a silent install is really silent and will not prompt for elevation. Note that limited users are not allowed to break security rules simply because they are doing an install.
So in that situation your launching process would need to be elevated, either by running as administrator or giving it a requiresAdministrator manifest so it asks for elevation.
When you fire off the install you need to make sure that your elevated state is used to fire off the install. The simplest way to guarantee this is to just call (p/invoke to...) MsiInstallProduct () directly from your code. The issue with Process.Start is that by default ProcessStartInfo.UseShellExecute is true and your elevated state (if you have one) will not be used to start the install. When the install is launched it needs to be a CreateProcess type of execution rather than a ShellExecute type so that your elevated credentials are used.
static void installMSIs(string path)
{
string[] allFiles = Directory.GetFiles(path, "*.msi");
foreach (string file in allFiles)
{
System.Diagnostics.Process installerProcess =
System.Diagnostics.Process.Start(file, "/q");
while (installerProcess.HasExited == false)
{
installerProcess.WaitForExit();
}
}
}
I have a .exe file which checks the system architecture and based on the system architecture it calls the corresponding msi file.
I am trying to run this exe file from C# using the code below
Process process = new Process();
process.StartInfo.FileName = "my.exe";
process.StartInfo.Arguments = "/quiet";
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.WorkingDirectory = "path//to//exe//directory";
Console.WriteLine(process.StartInfo.WorkingDirectory);
process.Start();
process.WaitForExit();
The exe is getting invoked. i can see the application logs and there are no errors in the logs.
But the msi is not getting started or installed.
When I try to run the same exe file manually the msi is installed.
Note: There are other dependency files for this my.exe which are placed in the same directory.
Why am i not able to install the msi from C# program while i am able to do this manually.
I am running the VisualStudios in administrator mode.
You need to execute .exe (and msi) as an administrator.
To ensure that, use:
process.StartInfo.Verb = "runas"
Also, try it removing quiet arguments to see any possible errors.
Is "my.exe" installing your MSI if you call it, isn't it?
I got this resolved after i added Thread.Sleep(). before "process.WaitForExit()"
I want to run the command line pnputil in c# program. The program needs to install USB driver.
I know how to run cmd in c# program, but I have a different problem:
The driver that I want to install does't have permission of windows.
If I Install the driver via the "device manager->update driver" and choose the path of the driver, I get "Security Message" from windows that "windows can't verify the publisher of this drive software" and let me choose if install the driver or not (of course, if I choose to install - the installing succeeds).
If I run the command from the cmd pnputil -a <path_name_inf> I get this message too and I can install the driver.
But when I try to run the command via c# program - the program runs but the driver is not installed (I also don't get this message).
my code in c#:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = #"/C Pnputil -a <path_name_inf>";
process.StartInfo = startInfo;
process.Start();
How can I do that?
You could try to run the cmd using the runas verb:
startInfo.Verb = "runas";
startInfo.UseShellExecute = true;
This parameter causes a privileges elevation. The same thing could be reached when you use "Run as administrator" in explorer.
Your questions is more towards installing unsigned drivers.
Can you please try following steps:
Open a command prompt as an admin and type:
bcdedit -set TESTSIGNING ON
Please refer MSDN link for more infromation on Test Signing. Making Test signing may put a watermark as TEST in desktop waterpaper
I know this is old, but I wanted to share my solution in case it can help someone else.
My specific scenario is that I wanted to add an unsigned driver package to the driver store on Windows 7 Home Premium 64-bit.
Like the OP, this worked as expected (meaning I received the security warning and the driver package was added to the driver store) if I executed pnputil -a <path_to_inf> using a command prompt using "Run as administrator".
However, if I tried to call pnputil from within C#, I was never able to get the security warning and the driver package was not added to the driver store. I had tried using various options (i.e. Verb = "runas", UseShellExecute = true, etc) with the FileName set as "pnputil" or "cmd".
Ultimately, what worked for me was to create a simple batch file that contained the following:
%windir%\sysnative\pnputil /a <path_to_inf>
My C# app would then call this batch file as follows:
Process proc = new Process();
proc.StartInfo.FileName = "<path_to_bat_file>";
proc.StartInfo.Verb = "runas";
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
The user would first be prompted because I asked to run with elevated permission followed by the expected security warning. The driver package would then be added to the driver store as expected.
If this does not work as expected, you can add "pause" (without quotes) on a new line after the last command in the batch file and remove the WindowStyle and CreateNoWindow lines from the C# code to see what is happening on the command prompt.
I am using a C# code to install a program using a process which runs the msiexec, giving it the path to the MSI file.
This is the code I use:
string pathtoMsiFile = "\"" + msiPath + msiName + "\"";
Process p = new Process();
p.StartInfo.FileName = "msiexec.exe";
p.StartInfo.Arguments = "/i " + pathtoMsiFile + " /quiet";
p.Start();
p.WaitForExit();
The strange thing is that when I try to install the program, for a certain version it installs it to the correct location I would expect to on C:\path but a different version it installs to D:\path for some reason. If I open the MSI itself manually, the default location there is C:\path. Any idea why?
Eventually it appears the problem is with the program the msiexec tried to install.
I am not that program's developer so I couldn't know the problem in advanced on my own.
The program had a custom action in its installation that set a variable representing the drive to install on as the one where the OS is installed. The problem is, that this action was invoked only through the installation's UI (when double clicking the MSI), but not when using a quiet CLI command to install it.
I'm trying to run a Python script from a WPF application, but I can't figure out how to find the file on the client machine. I know ClickOnce installs the files to AppData\Local\, but that seems like a poor way to search for the script.
In my code, I'm starting a shell as follows:
var p = new Process();
p.StartInfo.FileName = #"C:\Python27\python.exe";
p.StartInfo.Arguments = String.Format("{0} {1}", ScriptName, args);
//p.StartInfo.WorkingDirectory = #"<path\to\project>";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
On my development machine, the WorkingDirectory parameter makes it all work if I set it to the project path because that's where the Python script resides.
I included the script in the ClickOnce file manifest and I've verified that it ends up in each version of the application deployment. I've also verified that the file ends up on the client machine in the obfuscated hierarchy, so everything is in place except I can't get my WPF application to actually run it. I could always copy the file to a known place on the machine, but that completely defeats the point of ClickOnce.
Any ideas would be greatly appreciated.
I got this to work, but I'm not 100% sure how. Regardless, here's what I did in case it helps someone else.
Don't set the process working directory (already commented out in my question)
Set the Python script properties as follows:
Build Action = Content
Copy to Output Directory = Copy Always
In the Publish tab under Project Properties, set the script to Include in Application Files.
With the above changes, my application deploys correctly on client machines.