I have the below command which run batch file, I need to run this batch when I open the ASPX page in the machine browser to affect the machine and not affect server :
ProcessStartInfo psi = new ProcessStartInfo(this.WhiteLabel.Text);
psi.RedirectStandardOutput = false;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = true;
Process.Start(psi);
This is not possible because of security concerns. The only possible way might be to create an ActiveX library that the user would acknowledge and accept on their browser to run. What are you trying to run on the client? Maybe there is another approach?
This has been asked before see here...
How to execute an application on the client from a website?
Related
As part of SharePoint automation testing, I am trying to open Internet Explorer as another user by using the System.Diagnostics.Process . Here is the following C# code
System.Diagnostics.Process p = new System.Diagnostics.Process();
// Domain and User Name:
p.StartInfo.Domain = "MYDOMAIN";
p.StartInfo.UserName = "myusername";
// Command to execute and arguments:
p.StartInfo.FileName = "C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe";
p.StartInfo.Arguments = "http://url/AllItems.aspx";
// Build the SecureString password...
System.String rawPassword = "thepassword";
System.Security.SecureString encPassword = new System.Security.SecureString();
foreach (System.Char c in rawPassword)
{
encPassword.AppendChar(c);
}
p.StartInfo.Password = encPassword;
// The UseShellExecute flag must be turned off in order to supply a password:
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = false;
p.Start();
When I run this automated test Visual Studio returns informing me that the test was successful, however Internet Explorer does not open.
Is there something in my code I am missing in order for a window to appear? There is no iexplore process running prior to the test being run.
putting double quotes around the file path (since it contains spaces) may help:
p.StartInfo.FileName = "\"C:\\Program Files (x86)\\Internet Explorer\\iexplore.exe\""
^^ ^^
In addition, if your intention is to start this from a service process or dll running in a service such as "SharePoint", then this code will probably not launch the process in the desktop desired. You'll need to set the desktop to "winsta0\\default" in the startup info.
To run a process the worker process should have high privileges and this is not an ideal case in any web application. If your purpose is to use IE for unit testing then I would consider using something like WaitIN. If your purpose is for application logic to access a URL and do something then consider using HttpWebRequest. If you still need a process to be started then create a Windows Service and then expose a web call so in Share Point you can just make a call and your Windows Service can run on local account or some other high privilege account.
Hope this helps and please provide the scenario why you want to start the IE and that can give you a better answer in the forum.
Want to execute a exe within Application directory, in Dev system it works fine. In IIS, it is not executed, I have tried below points:
set default application pool to local system
set defualtpool, NETWORK_SERVICE, Everyone access to exe
Enabled 32 bit application to application pool
Server Version : Windows Server 2012
IIS Version: IIS 8.0
Below is my code
p.StartInfo = new ProcessStartInfo();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = System.AppDomain.CurrentDomain.BaseDirectory.ToString() + "wkhtmltopdf\\wkhtmltopdf.exe";
string arg1 = "";
arg1 = "www.google.com" + " test.pdf";
p.StartInfo.Arguments = arg1;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit(60000);
p.Close();
p.Dispose();
Make sure that the location at which your pdf file is getting generated "everyone has access to it"
it seems you are trying to convert html data to pdf file on your iis server. Make sure IIS server can access the site which your are trying to convert "Check if you can access those site using IE on your IIS server as there could be proxy issues"
Consider to set the working path of your exe:
p.StartInfo.WorkingDirectory = System.AppDomain.CurrentDomain.BaseDirectory.ToString() + "wkhtmltopdf";
Also check task manager if the exe is in memory.
Sometimes when a batch got a low level error open a prompt, and IIS do not capture it, so the process is freezed in memory.
Consider also the set a log in the exe in order to understand what goes wrong.
I had similar problem. Solved moving the exe in another folder outside IIS application. This folder should have execution rights.
I've got an aps.net site. Can I start a print request for a pdf from a client to a printer connected only to the server?
In my server I use this code in a web api
[HttpPost]
public void Print()
{
ProcessStartInfo info = new ProcessStartInfo();
info.Verb = "print";
info.FileName = #"C:\Users\Me\Documents\Doc.pdf";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process p = new Process();
p.StartInfo = info;
p.Start();
}
If I run this request while debugging it works (i mean it prints the doc correctly), but if I start the request with with postman from a virtual machine (to simulate a network request) and debug the process attached to a IIS site no error will rise but no print done. The debug steps correctly all the instructions.
I set my application pool with my user identity (admin) and "connect as" on the site as well as my user.
I don't know if It can't be done cause on ASP.NET or cause I'm missing something.
This will do. I print with foxit reader. Maybe my default, Acrobat, have some isseus or asking for user interaction.
I am having a very bad moment executing a process from internet explorer.. I am supposed to call internet explorer from a worker role process to perform some operations..but internet explorer is executing with no visible interface...
This is my code :
psi.FileName = "D:\\Program Files\\Internet Explorer\\iexplore.exe";
psi.CreateNoWindow = true;
psi.ErrorDialog = false;
psi.UseShellExecute = false;
psi.WindowStyle = ProcessWindowStyle.Maximized;
psi.RedirectStandardOutput = false;
psi.RedirectStandardInput = false;
psi.RedirectStandardError = true;
psi.Arguments = fileLocation;
exeProcess = Process.Start(psi);
started = true;
exeProcess.PriorityClass = ProcessPriorityClass.RealTime;
Can you please help me? I need to execute internet explorer with a visible interface.
Running process that normally requires completely functioning Windows desktop is unlikely to run correctly from service as there is no UI/windows associated with services. You should be able to reproduce the same behavior by trying to instantiate such application from a service (i.e. IIS) on local machine running under some service account.
If you need to render web pages on server it would be better to either use external service or specifically designed "headless browser" like PhantomJS.
SHORT VERSION
How do you figure out which DLL is failing to load (and potentially why) when a process exits with error code -1073741502?
LONG VERSION
I'm trying to write a pretxnchangegroup hook for Mercurial, and as a part of that hook I need to get the output of running the command:
hg log
The code that I'm using to start and run the hg.exe process is as follows:
string Command = "log";
Process p = new Process();
ProcessStartInfo psi = p.StartInfo;
p.StartInfo.FileName = #"C:\Program Files (x86)\Mercurial\hg.exe";
psi.CreateNoWindow = true;
psi.LoadUserProfile = true;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
psi.WorkingDirectory = Environment.CurrentDirectory;
p.StartInfo.Arguments = Command;
// Pass-through environment variables
psi.UserName = Properties.Settings.Default.HG_User;
psi.Domain = Properties.Settings.Default.HG_Domain;
psi.Password = new System.Security.SecureString();
foreach (char c in Properties.Settings.Default.HG_Pass)
{
psi.Password.AppendChar(c);
}
p.Start();
p.WaitForExit();
The problem is that the process keeps exiting with error code -1073741502, without outputting anything on Standard Output or Standard Error. After some research online, I discovered that this error code has something to do with the application failing to initialize properly (couldn't find DLL's, maybe?), but I have no idea how to go about figuring out how to fix it.
Keep in mind that this hook is being called for when I'm pushing to the repository over the web (so, IIS is calling the Mercurial CGI via Python, which has this program configured as a hook).
In a totally different web application, I'm able to run HG commands just fine, and I'm also able to run this by doing
runas /user:<same account as in the code> /noprofile cmd.exe and then manually typing in the hg command line.
Also, if I set UseShellExecute = true, then it executes just fine, but then I can't get the Standard Output. I'm really tempted to just make a web service call to the web app which is able to execute this command successfully, but that'd be a really ugly solution.
Any ideas why this thing isn't executing?
I was able to resolve this by disabling UAC so it sounds like a permissions problem even though I do not know the exact details.