Run "Find" (ctrl + F) in Google Chrome using C# - c#

I'm trying to make an app, which could open a pdf file in a browser (Chrome) and search for a certain word automatically. However, I can't find anything about passing commands to Google from C# whatsoever.
Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = "chrome";
process.StartInfo.Arguments = "console.log(\"TEST1\")";
process.Start();
I've tried running Chrome with StartInfo.FileName = "chrome", which went well. After that I thought I could add some Arguments: StartInfo.Arguments = "something" and that's where I ran into two problems:
The browser takes the Arguments as a URL and tries to open it as a web page (which of course fails)
I couldn't find the console command to run the search function in Chrome
Is there maybe some google API capable of this thing? Also please note that I'm not trying to use "search". I need the browser to literally focus on the word it found
If anyone here knows how to solve even one of these problems, I would be really grateful. Also this is my first question on StackOverflow (and I might have forgotten something) - I can give some additional info, if you ask

Related

Open Edge in a new process and kill it again

I'm currently making a program, that essentially needs to open a link in Edge, take a screenshot and then close the browser again.
1st issue:
I can open the browser just fine, but it just opens a new tab instead of a new window, if the browser's already open.
I do not want to interfere with an already existing open Edge browser, that our users may be using, but instead open a completely new instance, take a screenshot and then close it again.
I tried using the following, with no luck - it still just opens a new tab
Process proc = new Process();
proc.StartInfo.FileName = "microsoftedge.exe";
proc.StartInfo.Arguments = "http://172.31.44.1/#/cameras" + " --new-window";
proc.Start();
2nd issue:
When trying to kill the process using proc.Kill() I end up getting a system.invalidoperationexception cannot process request because the process has exited , but the browser's still open
Any help is appreciated!
Thank you in advance
Check this out:
using System.Diagnostics;
Process proc = new Process();
proc.StartInfo.FileName = #"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
proc.StartInfo.Arguments = " --new-window http://google.com";
proc.Start();
It seems as though Chrome (and therefor also Edge) has changed the behavior of this recently.
It used to be the case that you could use the parameter "--no-service-autorun" to avoid the browser closing the original process, and to avoid you ending up with an invalid (dead) process id.
This doesn't work anymore.
When "Startup boost" is disabled in Edge, the first window does have the correct process id, but anything after that is still invalid.
The only thing that I could find that works, is to use "--user-data-dir" parameter to give each process it's own profile and process.
For example, use "msedge.exe --user-data-dir=C:\test123" (make sure each process has a unique directory).

Add more than one arguments when launch a process c#

Hy,
I need to launch a vnc viewer in a winform (ultravnc in my case) and I need to send two parameters to see the remote desktop and after several issues, I can't find any solutions.
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = "C:/Program Files/uvnc bvba/ultravnc/vncviewer.exe";
proc.StartInfo.Arguments = host;
proc.Start();
the first argument "host" is the ip of the pc and that just work.
After that, ultravnc ask me the password for the remote desktop connection.
And this is where I can't find any solutions :
1)I try to add a second arguments :
proc.StartInfo.Arguments = mdpVNC;
But VNC take this as a replacement of the "host" variable.
2)I try to use the SendKeys class but it doesn't work
3)I try the property "PasswordInClearText" but that doesn't work either.
I try several things and I don't want to use an external package (like vncSharp or other, because these solutions don't suit me)
I need help plz.
Thanks in advance.
StartInfo.Arguments is a string, and you put in there the arguments. Make the string that has the arguments as you would write them in the command line. For example:
startInfo.Arguments = "host -dsmplugin msrc4plugin.dsm";
That is for the first example in UltraVNC Viewer Commandline Parameters
.
Or whatever you need.

Why does Process.Start show an error message box, even though I redirect the standard error?

Why does Process.Start show an error message box, even though I redirect the standard error?
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.Arguments = Optimizer.GetArgumentsString();
startInfo.FileName = ProjectSettings.OptimizerExe;
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
process = System.Diagnostics.Process.Start(startInfo);
string output = process.StandardOutput.ReadToEnd();
string outpute = process.StandardError.ReadToEnd();
process.WaitForExit();
The call System.Diagnostics.Process.Start(startInfo) results in this error message box:
but I don't want that message box to show. If there is an error in the called exe
I want to handle it myself, I don't know where that error message box comes from.
This message box comes right from the process you started.
You could check if there is "console" mode of operation for your process - try to start it from the command line with option for help - ( "/?", "/help",...) or contact the customer support of the company that developed the application.
If it is inhouse applicaiton or you have access to the source code - you can modify it and implement the console mode yourself. There are well known techniques how to do it - I will not describe them here as this would different question :)
If there is no console mode and you have no soure code access - than the process is just not intended to be used like this and you are out of luck. Of course you could make sure a valid license is found and message box does not show - but some other message box can pop up later.
Well, the process you're starting is showing the error box. There's nothing clean you can do about it. It's out of your reach.
The message box exists in a wholy separate message loop, in a completely different process. It has nothing to do with you using Process.Start - if you start the exe using Windows Explorer, it will still show that dialog. If you do have the license file, make sure you set the WorkingDirectory to the correct folder (provided the application actually reads the license from a file) - that might solve your issue.
Redirect standard output will do exactly what it says - it will redirect the standard output pipe. That's basically Console.WriteLine/ReadLine - it does nothing with GUI.
The same way "standard error" is just another pipe. The application obviously doesn't use it to output errors. It's not required too, and it's not used much in GUI applications.
In reality, both standard output and standard error are features of command line applications, not of GUI applications. If the application isn't designed to work from the command line, you ain't gonna make it :)
Oh, and when you redirect standard output/error, you have to actually read it. Otherwise, if they are used by the application, their buffers will get filled and the application will freeze :)

Break out of a C# instantiated batch script to get a shell?

I am attempting to verify the security of an application. The scenario is this:
A C# WinForms application is run by a limited user via Terminal Services (no desktop, just the app). One of the things this C# app can do is execute a batch file that runs a lengthy process with elevated privileges. I am afraid that the limited user may be able to interrupt the batch script (vua Ctrl+C or some other method) and gain access to the underlying elevated shell.
I have tried to do this myself with various combos of Ctrl+C and Ctrl+Break, etc. All I can get is the "Teminate batch job? (Y/N)" prompt, and if you choose terminate, then control is immediately returned to the C# app (which is good). I have not found a way to break this but it seems dangerous to me.
Does anyone know of a way to break out of a C# instantiated batch script and access the underlying shell without returning to the C# app?
No, don't think there is one. But if you're really worried, why not set the CreateNoWindow property on the ProcessStartInfo object you are presumably using to true to prevent user interaction at all?
Not quite an answer to your described scenario but a different way to look at it.
If possible, I would have a "jobs server" who sole responsibility is to run the jobs your Terminal Services-run apps create. Then you would communicate the job (or just it parameters) via WCF to the server. The users would have no access to the server and very little control of the jobs (possibly just a cancel option and success/failure status reports).
You could do something like this (with a Textbox on your app)
ProcessStartInfo info = new ProcessStartInfo();
info.Arguments = "/C ping 127.0.0.1";
info.WindowStyle = ProcessWindowStyle.Hidden;
info.CreateNoWindow = true;
info.FileName = "cmd.exe";
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
using (Process process = Process.Start(info))
{
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
textBox1.Text += result;
}
}
Then you can see the results of the batch without the users being able to actually see the window at all, that way it's only visible as a process so they can't interupt it.

How to control network client pc

In my local network ,I have more than 10 pc.I need to take care all of the pc.I want to know all pc’s hardware informations.I also want to control those pc,Suppose ,at this moment I want to restart one of my client pc.Is it possible in C#.if have any question plz ask.Thanks in advance
I use bellow syntax to execute command.
try
{
// create the ProcessStartInfo using "cmd" as the program to be run,
// and "/c " as the parameters.
// Incidentally, /c tells cmd that we want it to execute the command that follows,
// and then exit.
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd", "/c " + "shutdown /r /m \\172.16.1.3 /t 1 /");
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
// Display the command output.
Console.WriteLine(result);
}
catch (Exception objException)
{
// Log the exception
}
Using the above code I get the message "The network path was not found."
Pls check the url.
http://support.microsoft.com/kb/317371
If you want to make a program which u can able to get the remote system information. You have to use Microsoft's Remoting.Here we can able to create an object in the remote system and we can able to control it.
It is possible to get System's information by executing the System.Diagnostics.ProcessStartInfo.
It is possible to get system information using "systeminfo" .It is possible to take the output using C#
Pls chk the this.
I hope this will be useful for you.
I don't think this is a C# question, cause this can be done much more elegant with things like Group Policy Editor, System Management Server, System Center Operations Manager, etc.
To do some simple tasks on a remote machine you can take a look into the PsTools.
With those requirements my first stop would be WMI. There's for example the Win32_OperatingSystem class with its Reboot and Shutdown methods and the Win32_Processor with all kinds of information about the CPU.
This MSDN section shows you how to use it from .Net: Getting Started Accessing WMI Data
This MSDN section has quite a lot of short VBScript samples for doing various things using WMI, and even if the code is different, at least you can see which WMI classes/methods/properties you should be looking at: WMI Tasks for Scripts and Applications
Please note RB's comment though, you'll need to have the correct permissions for it to work.
Edit: Forgot that since you'll want to connect to other computers, this sample will be useful: How To: Connect to a Remote Computer

Categories

Resources