How to run RDC Windows application - c#

I tried lot in running RDC windows application on there I'm trying to capture details.
Like ---- > connecting Myremotedesktop ----> Run the windows application in rdc and enter values to get details (eg if I enter rollnumber address details will come) ----> capture details data and store it on my local desktop.
Is there any way to automate this process using c# code?
I'm able to connect remote desktop.
I tried the UIAutomation and the below code working fine for local desktop:
System.Threading.Thread.Sleep(500);
AutomationElement rootElement = AutomationElement.RootElement;
Condition appCondition = new PropertyCondition(AutomationElement.NameProperty, "Untitled - Notepad");
Condition documentCondition = new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "document");
AutomationElement documentElement = rootElement.FindFirst(TreeScope.Subtree, documentCondition);
documentElement.SetFocus();
SendKeys.SendWait("This is a test of the emergency broadcast system.")
How to do this same thing on remotedesktop?

Due to your requirement of not being able to put any software on the server side of the RDP connection remote control like you want to do is impossible unless the buttons you want to click are int he same position every time and you hard code the X,Y values of where to move the mouse in your automation script.
If you could run something on the RDP server you could take your automation code and write a listener program that would talk to your client over Virtual Channels which would allow you to pass messages to your listener over the RDP connection and the listener could perform the automation tasks server side.

Can you force the client side to be Windows 8? I believe that UI Automation requests get "tunneled" through the RDC connection on Windows 8.

Related

Sending Keyboard RETURN Key on remote server with Remote Desktop Connection Closed

I have a WinForms WebView2 project that is a simple bot running some JavaScript on a webpage. I am using JS to click an element on the webpage and download a file. The website prompts me with "Are you sure you want to leave the page?" dialog, So I want to send the RETURN keyboard press to confirm that I want to leave the webpage and download the file.
I want to run this automatically using windows Task Scheduler. This method works, as long as I am remote connected to my server and the window is not minimized. However, when I am not remote connected to my server, my enter keypress returns and error.
I have tried this code with SendKeys
//Get Webview proccess
Process p = Process.GetProcessesByName("msedgewebview2").FirstOrDefault();
if (p != null)
{
IntPtr h = p.MainWindowHandle;
SetForegroundWindow(h);
printToTextbox("pressed ENTER key");
SendKeys.SendWait("{ENTER}");
await checkDownloadFinished();
}
I start my Bot and then exit my remote session. When I return, this error is given when the program reaches SendKeys.SendWait("{ENTER}");
System.ComponentModel.Win32Exception: 'Access is denied'
I also tried the Nuget package InputSimulator
Process p = Process.GetProcessesByName("msedgewebview2").FirstOrDefault();
if (p != null)
{
IntPtr h = p.MainWindowHandle;
SetForegroundWindow(h);
printToTextbox("pressed ENTER key");
InputSimulator s = new InputSimulator();
s.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.RETURN);
await checkDownloadFinished();
}
Following the same proccess, I start my bot and exit my remote session. When I return, I am met with this error:
System.Exception: 'Some simulated input commands were not sent successfully. The most common reason
for this happening are the security features of Windows including User Interface Privacy Isolation
(UIPI). Your application can only send commands to applications of the same or lower elevation.
Similarly certain commands are restricted to Accessibility/UIAutomation applications. Refer to the
project home page and the code samples for more information.'
Is there another c# compatible way to send keystrokes? Or is there a way to prevent the dialog from ever popping up? Thank you!
You're doing it wrong :-)
You should try to look at: CoreWebView2.ScriptDialogOpening Event.
The scriptdialogopening has its eventargs with an Accept() method to click Ok on the dialog.
Here's the eventargs link: CoreWebView2ScriptDialogOpeningEventArgs
Now you don't have to mess with SendKeys.

Open Network And Sharing Center programatically without explorer.exe

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.

Give commands to multiple RDP and wait for result

I have a repetitive task at the end of the month to give commands to multiple Remote Desktop Connections (Win7, Win Server 2008, Win server 2012, Win 8 ...) and i need to open all of them one by one to do this task. I want somekind of tool that would log on each and every one of them and give commands.
Here is what i tried :
public Form1()
{
InitializeComponent();
rdp.Server = "1.2.3.4";
rdp.UserName = "Rmlabuser2";
IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
secured.ClearTextPassword = "Rmlabuser2";
rdp.Connect();
// open cmd.exe and give commands like VER and return output into a message text box
// rdp.SecuredSettings.StartProgram = #"c:\windows\System32\cmd.exe";
}
Full code :
http://www.codeproject.com/Articles/43705/Remote-Desktop-using-C-NET
Any ideeas?
Thanks.
You can use psexec to run commands on remote computer.
If you need to run commands within active session, you can create a scheduled task on that computer that will do the needed stuff. Scheduled tasks can be configured to run under currently logged-in session or from system/predefined account.
There are a number of C# libraries that can work with windows scheduled tasks. For example http://taskscheduler.codeplex.com/

Reliable method for detecting if Webex Client is running

What is the best method for determining if the Cisco Webex client is running on a user's computer? Currently, I'm checking for a running process like this:
public static bool IsWebExClientRunning()
{
// webex process name started from internet browser (could change). Just use Process Explorer to find the sub process name.
// alternate name - CiscoWebexWebService
Process[] pname = Process.GetProcessesByName("atmgr");
return pname.Length > 0;
}
While this method works, there could be an instance where Cisco pushes out updates to their client that changes the process name which would break this code if we're looking for a specific process name.
The Webex client starts as a child process from an Internet browser since it is technically a browser plugin and it doesn't show up on its own in Windows Task Manager. I have seen both atmgr and CiscoWebexWebService using Process Explorer to find the process. Sometimes, depending on the host operating system, Windows XP/Windows 7, it will just display atmgr and not the child process CiscoWebexWebService belonging to atmgr. It also varies slightly based on the browser that is used. It runs as a browser plugin for all supported browsers and for unsupported browsers, it will give the option to run as a standalone application.
The process tree can vary (i.e. other browsers/operating systems), but it looks something like this:
iexplore.exe
-> atmgr.exe
-> CiscoWebexWebService.exe
Obviously, all checks must be done client side and not server side, but is there a better method for approaching this?
I spoke with a Cisco specialist and they said that my current approach should be safe for detecting if the Webex client is running a user's machine. They were able to confirm that the process name is atmgr.exe and should not change in the near future.

IE screenshot problem in c# windows service

I am using win 2003 server.
I have windows service created in c# .net, it opens IE at every 5 min with predefined URL, get screen shot of it and save it to database. It seems a simple application. But my problem is, when machine is lock (window key + l) or machine is logged off, IE process is start, but cant take screen-shot, it takes "black page" only.
Is there any option to run IE at login screen? or is there any work around of this problem?
As posted in Generate WebPage Thumbmail Screenshot Image you could try using a WebBrowser control in your service and generating a screenshot from that.
The service needs to run with the "interact with desktop" check box ticked. The window needs to be upper-most in the Z-Order when the screen shot is taken and not overlapped by other windows. This approach is quite error prone...as I have found.
To interact with desktop using code:
Put this just before you start the service.
String sYourServiceName = #"MyService" //Change this to r service name
ConnectionOptions co = new ConnectionOptions();
co.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope mgmtScope = new System.Management.ManagementScope(#"root\CIMV2", co);
mgmtScope.Connect();
ManagementObject wmiService;
wmiService = new ManagementObject("Win32_Service.Name='" + sYourServiceName + "'");
ManagementBaseObject InParam = wmiService.GetMethodParameters("Change");
InParam["DesktopInteract"] = true;
ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null);
or
Try to run iexplore "Internet explorer" as a system account from the logon page. Just execute Process.Start("Iexplore.exe") from your Windows service and it should work, but I am not sure if you can execute iexplore as a system level account.
Otherwise, you can try to block the lockout screen by writing a basic key grabber or a key logger to block MENU+L lockout, you can do this by enabling interaction with desktop. I posted the code to make it easier or do it manually by going to services and clicking on your service. There you should see a checkbox with the text interact with desktop.
//M

Categories