System.diagnostics.process process is not working on IIS after hosting? - c#

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.

Related

C#: IIS server fails to run a pg_dump Proccess through CMD.exe

I'm trying to create a function that backs up one of my important tables using pg_dump --table. The function runs successfully on my localhost and does the dump. but when it is run by my program through IIS on the server, it doesnt seem to do anything.
my project uses .NET Framework 4.7.2 , Here is my program's code:
try{
var process = new Process();
var startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.WorkingDirectory = "C:\\Website\\Logs\\";
string fileName = startInfo.WorkingDirectory+RandomString();
startInfo.Arguments =
$"/c set PGPASSWORD={userPassword}&pg_dump --file {fileName} --host {Ip} --port 5432 --username {userName} --no-password --verbose --format=d --table public.clients {DB_Name}";
ServerLogs.SaveLog(startInfo.Arguments); //i am saving the logs
startInfo.Verb = "runas"; //run as administrator
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
process.Close();
return "Success";
}catch (Exception x)
{
return x.Message;
}
As u can see, i am logging the arguments field on the server. here is the CMD that was generated and executed :
/c set PGPASSWORD=MyPassword&pg_dump --file C:\Website\Logs\abcd\FileName123123 --host mycluster.eu-north-1.rds.amazonaws.com --port 5432 --username test--no-password --verbose --format=d --table public.clients CRM
this CMD that was created is good, when i copy it to the EC2 server's terminal it runs and dumps the table successfully into my specified path. But when it is run by my program through IIS, it only saves the log, but the proccess itself is not dumping the table. not creating any file. pg_dump is recognized and configured well in my env variables.
1.I was thinking the code is ok because it runs well locally
2.I was thinking the CMD is ok because it runs well on the server's terminal.
3.I tried changing the startInfo.arguments to be "type nul > somefile.txt" to see if IIS has permissions to create files on this folder, and it ran successfully.. so i was thinking this isnt a permission issue.
But I could be wrong. Because it is not working.
I tried several methods and solutions online and I am kinda clueless. I would very much appriciate any help or suggestions. Thank you very much!

How i can Open CMD.exe from my iis website C# [duplicate]

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.

how to open CMD using iis application windows 10 using C#

how I can open CMD using my IIS Application
var startInfo = new ProcessStartInfo();
startInfo.WorkingDirectory ="c:\\pdftohtml\\";
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "MyText";
Process proc = Process.Start(startInfo);
I believe this code is true but dose not work with IIS for some reason
Thanks in Advance
Opening a command prompt from an IIS application is not a good idea.
If you need to run a tool, maybe it's better to find the API used by the tool and reference it from a service called by the IIS app.
If you need to convert pdf to html, check this link

Killing the process running on server

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.

How to install on remote PC with psexec with my c# code

I'm trying to install some software remotely from our domain server to all the PC's in the office.
I know the code to install it silently on the local computer and have tried various things that I've found while searching to install it remotely when pressing a button in my app but I can't get it to work. This is my local code and it works:
Process SR = new Process();
SR.StartInfo.FileName = "X:\\Teklastructures\\Tekla Structures Releases\\18.0\\TeklaStructures180SR3x64Software.exe";
SR.StartInfo.Arguments = "/s /v\"/qn INSTALLDIR=C:\\TeklaStructures /lvoicewarmupx C:\\teklaSRinstall.log";
SR.Start();
SR.WaitForExit();
SR.Close();
I've been trying to use psexec because I've read that it should do what I want. I believe one problem is that the software is on mapped drive X. So how can I install it remotely? Maybe look at this instead?
"\\server\\d\\Teklastructures\\Tekla Structures Releases\\18.0\\TeklaStructures180SR3x64Software.exe"
This is what I've tried with putting PsExec.exe on the C drive of the server:
Process p = new Process();
p.StartInfo.FileName = "C:\\PsExec.exe";
string args = "/s /v\"/qn INSTALLDIR=C:\\TeklaStructures /lvoicewarmupx C:\\teklaSRinstall.log";
p.StartInfo.Arguments = #"\\COMP14 -accepteula -i -s X:\Teklastructures\Tekla Structures Releases\18.0\TeklaStructures180SR3x64Software.exe " + args;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.WaitForExit();
p.Close();
Any help to install software remotely would be appreciated. Perhaps there's a better way?
You must copy the installer exe to the computer where you want to install it, and then use psexec to run it there. You cannot run the installer exe from a different machine that where you want it to be installed to.

Categories

Resources