I have a c# console application that I want to run from task scheduler that has 2 main functions: 1) Closes all Internet Explorer processes; and 2) Restarts Internet Explorer and loads the appropriate website.
The console app does exactly what it is supposed to do if run from the command line, but fails if executed from Task Scheduler.
The app is designed to run on the client computer the only function of which is to load a single website and broadcast the website to our internal TV Channel 195. We have connection issues with our ISP and while the connection issue is usually temporary, Internet explorer needs to be restarted to re-show the website.
I want to set it up to run multiple times each day to eliminate any possible connection issues between the web server and the client.
private static void StartExplorer()
{
Process _process;
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "iexplore.exe",
Arguments = "-noframemerging -private -k \"http://tv.TheelmAtClark.Com\""
};
try{
_process = Process.Start(psi);
}
catch(Exception Ex)
{
Console.WriteLine(Ex.ToString());
}
}
Is it possible to run the app using task scheduler?
I would recommend that you look at alternative approaches, if possible.
A Firefox plugin like Reload Every is designed to do just this. I use this in our to project to a big screen TV.
However, if you are keen on doing this via Internet explorer, again there are two approaches
1) Something similar to the Firefox plugin I mentioned above - Autorefresher for IE
2) If you insist on having a task scheduler, as you mentioned above, here is how I think you can do it-
To kill all Internet Explorer instances, use PSKill. Invoke it via Process.Start with arguments to kill Internet Explorer.
To launch a new instance, try invoking Process.Start with UseShellExecute=true.
Related
Is there a way of opening this from a C# application without needing explorer.exe to be running? I have a Windows 10 IoT device running with a custom shell, but needs to be able allow the user to set up WiFi connections.
I have tried this:
ProcessStartInfo psInfo = new ProcessStartInfo("control.exe", "/name Microsoft.NetworkAndSharingCenter");
However while this works fine when running normally in Windows, when I run it in the custom shell (explorer.exe is not running), nothing happens.
This differs from the Network Connections applet which runs fine even within the custom shell...
ProcessStartInfo psInfo = new ProcessStartInfo("rundll32.exe", "shell32.dll,Control_RunDLL ncpa.cpl");
Is there a way to get rundll32 to run the "Network and Sharing center"? I can't find another .cpl that does it and any research on the 'net just points me back to the original command I tried above.
Developing a Self-Updating Asp.Net Core Windows Service which works roughly as below:
The Service downloads the new release and unzips it in an "update" folder
The Service starts an Updater-Process
The Updater stops the Service and waits for the Service to finish
The Updater moves the current "bin" folder to "backup" then "update" to "bin"
The Updater should start the Service again
The Problem
On 5. the Problem occurred , that the Port am using to run my app , would be busy Even if I wait for the Port to get free like 2 minutes, it won't.
But when calling the Updater "by Hand" it works just perfectly. The Port is free instantly, and the Service can be started again.
The Updater gets started like this in the Service:
Process process = new Process {
StartInfo = new ProcessStartInfo(Path.Combine(parent, "VersionUpdater.exe")) {
CreateNoWindow = true,
UseShellExecute = false
}
};
process.Start();
It looks like it is still connected to the Service Process, although they got different PIDs.
Does anyone know how i can decouple the processes or open the port?
I found the problem:
The parent-process is waiting for the child-process so the port is still open.
Solution:
You need to set the "UseShellExecute" to true.
I am trying to launch a process from a web page's back-end code/app pool. This process will launch an App that i built myself.
For some reason, the process only works / runs when i start it from VS2013... it never works when i launch it from IIS(7.5) itself.
I am on a Windows 7 machine (both IIS host, and App location), and I've setup my web site to only be accessible via internal network.
Here's the code, followed by the config / attempts to fix the issue:
protected void btn_DoIt_Click(object sender, EventArgs e)
{
string file_text = this.txt_Urls.Text;
if (!String.IsNullOrWhiteSpace(file_text))
File.WriteAllText(ConfigurationManager.AppSettings["filePath"], file_text);
ProcessStartInfo inf = new ProcessStartInfo();
SecureString ss = GetSecureString("SomePassword");
inf.FileName = #"........\bin\Release\SomeExecutable.exe";
inf.Arguments = ConfigurationManager.AppSettings["filePath"];
inf.UserName = "SomeUserName";
inf.Password = ss;
inf.UseShellExecute = false;
//launch desktop app, but don't close it in case we want to see the results!
try
{
Process.Start(inf);
}
catch(Exception ex)
{
this.txt_Urls.Text = ex.Message;
}
this.txt_Urls.Enabled = false;
this.btn_DoIt.Enabled = false;
this.txt_Urls.Text = "Entries received and process started. Check local machine for status update, or use refresh below.";
}
Here are the things I've tried to resolve the issue:
Made sure the executing assembly was built with AnyCPU instead of
x86
Ensured that the AppPool that runs the app, also runs under the same account (SomeUsername) as the ProcessStartInfo specified.
Ensured that the specific user account has full access to the executable's folder.
Ensured that IIS_USR has full access to the executable's folder.
Restarted both the app pool and IIS itself many times over implementing these fixes
I am now at a loss as to why this simply will not launch the app... when i first looked into the event log, i saw that the app would die immediately with code 1000:KERNELBASE.dll, which got me on the AnyCPU config instead of X86 fix... that fixed the event log entries but the app still doesn't start (nothing comes up in task manager), and i get no errors in the event log...
if someone could help me fix this problem i would really appreciate it. This would allow me to perform specific tasks on my main computer from any device on my network (phone, tablet, laptop, etc etc) without having to be in front of my main PC...
UPDATE
The comment to my OP, and ultimate answer from #Bradley Uffner actually nailed the problem on the head: My "app" is actually a desktop application with a UI, and in order to run that application, IIS would need to be able to get access to the desktop and the UI, just like if it were a person sitting down in front of the PC. This of course is not the case since IIS is running only as a service account and it makes sense that it shouldn't be launching UI programs in the background. Also see his answer for one way of getting around this.
Your best bet might be to try writing this as 2 parts. A web site that posts commands to a text file (or database, or some other persistent storage), and a desktop application that periodically polls that file (database, etc) for changes and executes those commands. You could write out the entire command line, including exe path command arguments, and switches.
This is the only way I can really think of to allow a service application like IIS to execute applications that require a desktop context with a logged in user.
You should assign a technical user with enough high priviliges to the running application pool. By default the application pool is running with ApplicationPoolIdentity identy which has a very low priviliges.
I have a simple windows service which i need to use to invoke a console application.The console app generates pdf to print by opening the adobe reader window.Running the console app works fine to print pdf.But invoking it from service not successful.It doesnt even show up the console window where i log events.
Process pdfprocess = new Process();
pdfprocess.StartInfo.FileName = #"C:\Documents and Settings\xyz\Desktop\dgdfg\PdfReportGeneration\bin\Debug\PdfReportGeneration.exe";
pdfprocess.StartInfo.UseShellExecute = false;
pdfprocess.StartInfo.RedirectStandardOutput = true;
pdfprocess.Start();
But invoking other application like
pdfprocess.StartInfo.FileName = #"C:\Program Files\Adobe\Reader 11.0\Reader\AcroRd32.exe";
works fine.
What will be the reason?
There is probably some permissions issue there (PdfReportGeneration.exe inaccessible under service account or maybe something that it uses...)
I would advise to capture Process Monitor log to see where exactly it fails.
Windows services run in a different window station and cannot interact with the desktop, unless you're using an older version of Windows and tick a checkbox in the service properties in the service manager.
I am looking for a way to block a user from opening new IE or firefox windows. Is there a way to do this using c#. I am looking at system.diagnostics
You could use a windows service since it runs on background and use this code to terminate a process (the code terminates a detected running internet explorer process)
while (true)
{
StartLoop:
try
{
foreach (System.Diagnostics.Process process in System.Diagnostics.Process.GetProcesses())
{
if (process.ProcessName.ToUpperInvariant().Equals("IEXPLORE"))
process.Kill();
}
}
catch
{
goto StartLoop;
}
}
How about making a group policy for the "testing account" that excludes most of the start menu and the desktop. Make your program the only one that can run.
It won't guarantee that another process won't be started, but it will certainly make it more difficult.