System.diagnostics.process.start -System.ComponentModel.Win32Exception - c#

This is my code block:
Process myProcess = new Process();
myProcess.StartInfo.FileName = fullpath;
myProcess.StartInfo.Arguments = " " + strNewFilePath;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.Start();
I am running an exe file using the System.diagnostics.process and i am keep getting this error:
System.ComponentModel.Win32Exception (0x80004005): The application has
failed to start because its side-by-side configuration is incorrect
The machine i am running this on is x64.
Googled it for a couple of hours, not much info on this. Any ideas?

Which application are you trying to run? Is it a 32-bit or 64-bit app?
You can check the event viewer Application log to figure out more information about this error.
If it due to some VC runtime then you can install the appropriate x86/x64 VCredist package (2005/2008/2010/2013) and see if it works for the application that you are trying to launch.

Related

WebView2 runtime silent install fails with error 0x80070057

I am trying to get the WebView2 runtime installed using the Evergreen installer MicrosoftEdgeWebview2Setup.exe which is embedded in my app.
This works fine:
Process.Start(Application.StartupPath + "\\MicrosoftEdgeWebview2Setup.exe");
but I want to install the runtime silently.
I tried this code
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = Application.StartupPath +"\\MicrosoftEdgeWebview2Setup.exe",
Arguments = " / silent / install",
UseShellExecute = true,
Verb ="runas"
};
Process p = Process.Start(startInfo);
but the install fails with error code 0x80070057.
Has anyone else hit this issue ?
My command line arguments had too many spaces. It should read
Arguments = " /silent /install"
After that the runtime install will install silently and also much quicker than just using Process.Start without startinfo

System cannot find file specified

So we need to execute a exe in our .net API, and this exe is built at the same time as the API itself in our pipelines.
The exe is present in the exact same directory as our .NET API exe and ddl files.
I used the below code to try and trigger the exe:
var process = new System.Diagnostics.Process();
process.StartInfo.FileName = "customProgram.exe";
process.StartInfo.Arguments = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
process.Start();
process.WaitForExit();
This throws an error:
An error occurred trying to start process 'customProgram.exe' with working directory '/app'. No such file or directory
Try to specify the full path to the file.
For example like here:
Process.Start(#"C:\Program Files\Google\Chrome\Application\chrome");

Cannot launch .exe with another .exe

I wrote a program to get rid of unexpected errors like NULLs or zeros in .xml file after crash but the "restart" part of code isn't working. It's all good when I run the code in Visual Studio Code but when I use .exe file from dotnet publish function the program just crashes.
I've already tried setting UAC at level 0, UseShellExecute true/false, System.Diagnostics.Process.Start();, running as administrator.
static string exeAdress = #"C:\Program Files (x86)\NaturalPoint\SmartNav\SmartNAV.exe";
// Process.Start(exeAdress); // this isn't working either
Process p = new Process();
p.StartInfo.FileName = exeAdress;
p.StartInfo.UserName = "User";
p.StartInfo.Domain = "Domain";
p.StartInfo.UseShellExecute = true;
p.StartInfo.CreateNoWindow = false;
Actual output is throwing exception but I expect to run the exe without errors:
Unhandled Exception: System.ComponentModel.Win32Exception: The requested operation requires elevation
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
You need to run your main application as administrator (with elevated permission).
If you can run your application with elevated user then you do not need to supply
p.StartInfo.UserName = "User";
p.StartInfo.Domain = "Domain";
parameters.

SQLCMD was not found when running Process from ASP .NET

I have an ASP .NET application that starts sqlcmd.exe as a Process. In two of our three test environments, we have no problems. However, on the third machine, even though sqlcmd.exe was installed along with client connectivity tools, Process.exe cannot find sqlcmd.exe. The error shown is:
Error running process: System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at L3_CNM.Utilities.Common.SqlcmdHelper.RunRemoteScript(String ServerAddress, String datbaseName, String filePath, String outputFilePath
I am at a loss for why this happens. The differences between the case when everything is fine as opposed to when it fails are:
1) When it works, there is a full SQL server installation. When it fails, we are only installing sqlcmd as a downloaded installation package which points to a SQL server that resides elsewhere.
2) When it works, the application is running from the same disk volume as Windows installation. On the machine that fails, the application is installed on another volume from the Windows installation.
Other key points - the PATH variable shows the location to sqlcmd.exe, the user that is the application pool identity is a part of the local system administrators, when running sqlcmd.exe through command prompt the results are expected.
Any help would be highly appreciated.
Thanks
EDIT: Adding code:
try
{
Process process = new Process();
process.StartInfo.FileName = "sqlcmd.exe";
Logging.Instance.Log(Logging.Levels.Message, "Process start arguments: " + process.StartInfo.Arguments);
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.CreateNoWindow = true;
if (process.Start())
Logging.Instance.Log(Logging.Levels.Message, "Process successfully started");
else
{
Logging.Instance.Log(Logging.Levels.Message, "Unable to start process");
}
string output = process.StandardOutput.ReadToEnd();
output += process.StandardError.ReadToEnd();
process.WaitForExit();
Logging.Instance.Log(Logging.Levels.Message, "Process exited with output: " + output);
return output;
}
catch (Exception e)
{
Logging.Instance.Log(Logging.Levels.Error, "Error running process: " + e.ToString());
return e.ToString();
}
I would guess it's about the PATH environment variable.
Couple of tests! One, open a command window and type
WHERE SQLCMD
This will print out anywhere SQLCMD can be seen. If you get nothing, you'll need to update your path. If you get something, it may be a user environment variable, not the system environment variable, which is what ASP.NET would use.
Can you check that the SYSTEM version of this variable contains the right folder? On win8 and above, open start menu and type "edit the system environment variables". Then click "environment variables" and make sure, under System Variables, that PATH contains the folder returned by WHERE SQLCMD If not, put it in, separating from other folders with a semicolon.
A simple Reboot. God I hate Windows sometimes.
Thanks #Methodman for the suggestion.

process.start: new process has different files rights then the parent, why?

i'm starting a child application from my main process with the following code:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = DestinationNameEXE;
startInfo.WorkingDirectory = Toolbox.AssemblyDirectory;
startInfo.UseShellExecute = true;
startInfo.Arguments =
binParameter + #" """ + _BINPath + #" """
+ tmpParameter + #" """ + binFolder_ForExtration + #" """;
Process.Start(startInfo);
before i do this i check if the process has write rights in the binFolder_ForExtration and _BInPath with following code (source) and a simple write file check:
try
{
using (File.Create(tmpfile)) { }
File.Delete(tmpfile);
createFilesAllow = true;
}
catch
{
createFilesAllow = false;
}
in the main process i can write & create files. also the function HasWritePermissionOnDir returns true.
in the new process i'm doing the same test, but in this case i got from HasWritePermissionOnDir true, but if i try to create a file, i got an exception. the new process has the rights to change existing files.
how can this be? what i'm doing wrong?
how can the new process have less rights then the first process?
i don't change the user context.
i' have also tested to start the process with ProcessAsUser.Launch (source) but without any change. the new process dond't have the right to create new files in the given folder.
if i start the process with elevated rights:
startInfo.Verb = "runas";
everything works finde. the new process can write, create and change files in the given folder.
thx for any help
Update:
i'm testing on a windows 7 x86
the main process is compiled with target x86 and .Net 4.5. its a dll called from a vb6 application
the user i'm testing with has admin rights (but it's not the user administrator). the main process is started with normal rights settings (not elevated rights)
the new process is compiled with target any CPU and .Net 4.5.
since i require access to Process.GetProcesses in the new process it should be compiled as any CPU to be used on x86 and x64 systems (as far as i know)
currently all folder tests and occured errors happend in the folder *c:\Program Files (x86)\appname\BIN*. in the code i'm using full path and test the correctness of the path with direcotry.exist() bevore any execution.

Categories

Resources