I wrote a program. It kills the process notepad.exe running on computer by and it looks like that:
`
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.WorkingDirectory = #"d:\Windows\System32";
process.StartInfo.Arguments = "/c taskkill /IM notepad.exe";
process.Start();
process.Close();`
I placed this code on my web page. The problem is: when I use the Visual Studio Development server it works. When change to local iis 7.5 it don't. I tried to figure it out, so I even gave the administrator privileges to "DefaultAppPool" or run the whole web page as Administrator (then all the processes as cmd.exe are running as Administrator) but wasn't a solution.
Related
I'm trying to run a python script from C# as follows:
var process = new Process();
var startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = $"/C \"python {Constants.PythonScriptPath} --input-folder {directory} --output-folder {directory}\"";
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
The script is processing the files from the input folder into the output folder but the processed files count is less than the count when running the same command from the windows command line.
Is there anything that can terminate the execution when calling the cmd.exe from C#?
If anyone faces similar issue :
This issue happened because the application was running in debug mode with visual studio. When publishing the app it's working fine.
Looks like the visual studio is terminating the execution after a specific Time / Memory.
When I launch cmd.exe from a C# Program in Visual Studio, I get an error saying 'ssh is not an internal or external program' but when I launch cmd via Win + R -> cmd.exe, there is no problem. I checked the PATH variable and its identical in both. What could cause this weird behaviour?
Code:
Process process = new Process();
process.StartInfo.FileName = "CMD.exe";
process.StartInfo.Arguments = "/C ssh user#123.456.789.0";
process.Start();
The problem was the build configuration, making it x64 instead of "Any CPU" solved the problem. See comments for more detail.
I want the C# code to open a program using a shortcut. The program requires admin privileges.
Whilst ensuring Visual Studio is running as administrator,
I have tried:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "FN.lnk";
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.Verb = "runas";
proc.Start();
This fails with the exception: 'The operation was canceled by the user'.
Replacing "FN.lnk" with "cmd.exe" runs a command prompt window with admin privileges...
I have also tried:
System.Diagnostics.Process.Start("CMD.exe", "/K FN.lnk");
which launches an elevated command prompt window, but still says "Access is denied"
If I run cmd as administrator and manually navigate to the folder to run FN.lnk, it works perfectly... which makes this problem even more confusing.
I am trying to install .exe from web application. when i run the application locally(from asp development server) it is installing properly. But when i hosted on IIS it is not working.
I had written this code on Page_load method in asp.net page
//Want to install Test.msi on client machine.
string filepath = Server.MapPath("~/NewFolder1/Test.msi");//NewFolder1 is on server
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('"+filepath+"')", true);
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.UseShellExecute = true;
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
startInfo.FileName = "cmd.exe";
// startInfo.Arguments = "/K msiexec.exe /i \"" + #"D:\Datta\CrispDoxCompression.msi" + "\" /quite /qn";
startInfo.Arguments = "/K msiexec.exe /i \"" + filepath + "\" /qn";
startInfo.Verb = "runas";
process.StartInfo = startInfo;
process.Start();
when I run the application locally (from asp development server) it is installing properly
Of course, because then the server and the client are the same machine. You're starting a process on the server, which also happens to be the client, but in production, this isn't the case.
If you want users to install an application on their machine, then create a page on your site that shows them how to do so, including a link where they can download the installer.
You are not able to automatically install software from a website on a client's machine, let alone silently.
Sit down a minute and think about the implications if what you were asking for were actually possible. Barring browser (plugin) exploits, the days when that was possible are long gone.
If you are running this site in a controlled environment, then perhaps you can get your system administrators to deploy this installer for certain user groups on your domain.
I am trying to install .exe from web application. when i run the application locally(from asp development server) it is installing properly. But when i hosted on IIS it is not working.
I had written this code on Page_load method in asp.net page
//Want to install Test.msi on client machine.
string filepath = Server.MapPath("~/NewFolder1/Test.msi");//NewFolder1 is on server
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('"+filepath+"')", true);
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.UseShellExecute = true;
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
startInfo.FileName = "cmd.exe";
// startInfo.Arguments = "/K msiexec.exe /i \"" + #"D:\Datta\CrispDoxCompression.msi" + "\" /quite /qn";
startInfo.Arguments = "/K msiexec.exe /i \"" + filepath + "\" /qn";
startInfo.Verb = "runas";
process.StartInfo = startInfo;
process.Start();
when I run the application locally (from asp development server) it is installing properly
Of course, because then the server and the client are the same machine. You're starting a process on the server, which also happens to be the client, but in production, this isn't the case.
If you want users to install an application on their machine, then create a page on your site that shows them how to do so, including a link where they can download the installer.
You are not able to automatically install software from a website on a client's machine, let alone silently.
Sit down a minute and think about the implications if what you were asking for were actually possible. Barring browser (plugin) exploits, the days when that was possible are long gone.
If you are running this site in a controlled environment, then perhaps you can get your system administrators to deploy this installer for certain user groups on your domain.