How to start XXX.bat file in IIS? I want to run this file..while i am executing in my development PC its perfectly running. But While I deployed in IIS its working and not executing .bat file
So please guide me how to do...My Code as follows
\\
string exefile = ConfigurationManager.AppSettings["exefile"]; //exefile="D:\\XX\\xxx.bat"
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(exefile);
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);
\\
I would check security.
The user that "hosts" the IIS proccess does likely not have the rights to run exeute files outside the IIS folder.
Also posting a actual error message would be helpfull. On a side note if its Exepction is of type UnauthorizedAccessException then its very likely what i describe above.
I had this problem and for me it was the location of the bat file.
It had placed the bat file in it's own folder under the solution in Visual Studio but this meant IIS could not access it.
When I moved the bat file to the wwwroot folder everything worked as expected.
Related
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()"
When I run dism /Online /Disable-Feature:Microsoft-Hyper-V-Allcommand from command prompt, It works fine.
But same I want to do from C# code. It does not work, Process exists with error code 11.
Process proc = new Process();
proc.StartInfo.FileName = "dism.exe";
proc.StartInfo.Arguments = "/Online /Disable-Feature:Microsoft-Hyper-V-All";
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.Verb = "runas";
proc.Start();
proc.WaitForExit();
int exitCode = proc.ExitCode;
Basically I want to run the given command from C# code (with UAC) as it works with command prompt.
You can't. That is, you as a programmer, don't get to decide whether or not your code runs with administrative rights. However, you can inform the user that your code requires administrative rights and then ask to be granted those rights. How to do that is covered here.
try this method,
You'll want to modify the manifest that gets embedded in the program. This works on Visual Studio 2008 and higher: Project + Add New Item, select "Application Manifest File". Change the element to:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
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.
So here is my issue:
I have start a .bin file, which is just a .exe, renamed to .bin, with administrator privileges.
Here is what I have:
PSI.FileName = "Client.bin";
PSI.WorkingDirectory = Directory.GetCurrentDirectory();
PSI.UseShellExecute = false;
PSI.Verb = "runas";
Process.Start(PSI);
I also have the requireAdministrator set in the manifest.
I have to set UseShellExecute to false, seeing is that is the only way I can find that starts the .bin as a .exe. However, according Here, runas, and the manifest only are used when UseShellExecute is set to true.
Question: How to start a non .exe process, with elevated privileges?
Have a parent process which is a executable with administrative privilege & then launch the ".bin" file from it.
According to this answer this is not possible to run .bin file with elevation directly.
At least you can run your own .exe with runas (and ShellExecute = true) and order it with commandline to run .tmp (without ShellExecute, but the process is already elevated) and die. But this is the "last chance" solution.
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