I'm trying to log in to a server through remote desktop using c#. I'm able to initiate the connection using the AxMSTSCLib and the code below. However, I'm stuck on our domain's security notice.
When logging in manually it requires you to click ok on the notice before the log in completes. I have been unable to find anyway to interact with this OK button through my application. I've tried variations of SendKeys, sending key events using interop services, finding the cursor position and sending a mouse click event...
I'm running out of ideas here.
rdp.Server = server;
rdp.Domain = domain;
rdp.UserName = userName;
IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
secured.ClearTextPassword = password;
rdp.StartConnected = 1;
rdp.Connect();
Thanks
Well, there is a way to do what you ask.
You will need to download a copy of Windows 7 Embedded Standard (WES7 wSP1).
WES7 contains something that other editions of Windows 7 do not - a Dialog Filter.
It runs as a service, and allows you to specify certain window events to be performed automatically, without user interaction.
The Dialog Filter Editor is installed with the Windows Embedded Standard 7 tools in the EmbeddedSDK\bin folder.
All you have to do is:
Add the service to your Windows, by copying the necessary Dialog Filter files to C:\Windows\System32. There are x86 and x64 versions, so choose the correct architecture.
Register the files, and enable the service to run automatically.
Add the ConfigurationList.xml file created with the editor to C:\ProgramData\Microsoft\DialogFilter.
This location is hidden by defeault, so make sure to show hidden files and unhide protected system files in Windows Explorer.
I've actually created the ConfigurationList.xml file already, so you can simply copy the following code and save it as "ConfigurationList.xml":
<?xml version="1.0" encoding="utf-8"?>
<CL:dialogs xmlns:CL="urn:Dialogs">
<dialog>
<ProcessImageName>rundll32.exe</ProcessImageName>
<Title>Remote Desktop Connection</Title>
<Class>#32770</Class>
<Buttons>
<Button>OK</Button>
<Button>Cancel</Button>
<Button>Close</Button>
</Buttons>
<Actions>
<Action>OK</Action>
</Actions>
</dialog>
</CL:dialogs>
As you can see, the action is set to press the OK button automatically in the RDP dialog that pops up when making an RDP connection.
More info regarding the Dialog Filter directly from MS:
https://msdn.microsoft.com/en-US/library/ff794135(v=winembedded.60).aspx
Just found a much easier way to do this:
There's a free small app called ClickOff, which works in a very similar manner to Windows Embedded Standard 7 DialogFilter.
You can download ClickOff v1.90 here.
After you install ClickOff, you can define which window to capture, and which button inside it to click. Only thing is that you must add it to your startup apps.
I have already created a clickoff.lst file which clicks OK on the 30-sec RDP timeout popup window. The file should be placed in C:\Users\USERNAME\AppData\Roaming\ClickOff. Here's the contents of the file:
1.900
WINDOWTITLE="Remote Desktop Connection" BUTTONTEXT="OK" MSGTEXT="CompName\\UserName wants to connect to this machine.\r\n\r\nClick OK to disconnect your session immediately or click cancel to stay connected.\r\n\r\nOtherwise, you will be disconnected in 30 seconds." BUTTONID="1" MSGID="65535" DLGID="0" CLKEVENT="17" CLKMETHOD="3" TIMESCLICKED="0" WAIT="0" BPOSX="0" BPOSY="0" ;
Cheers.
Related
So I am having a form placement issue when launching a remote desktop connection session that automatically executes an application that is used as a main application portal.
I created this WPF form using C# and the Prism MVVM framework for accessing the company's billing desktop applications a user has permissions to.
So instead of distributing this main application and the billing applications on each user's desktop, the infrastructure team created a remote desktop connection file (*.rdp) that will be distributed to all users that have permissions to these billing desktop applications.
The remote desktop connection file has been modified where the user will login to the application server and ONLY be able to launch the application main portal and the billing applications they have permission to.
Here is the script for the RDP file
use multimon:i:0
desktopwidth:i:1920
desktopheight:i:1200
session bpp:i:32
winposstr:s:0,1,-1674,83,-248,1127
compression:i:1
keyboardhook:i:2
audiocapturemode:i:0
videoplaybackmode:i:1
connection type:i:7
networkautodetect:i:1
bandwidthautodetect:i:1
displayconnectionbar:i:1
enableworkspacereconnect:i:0
disable wallpaper:i:0
allow font smoothing:i:0
allow desktop composition:i:0
disable full window drag:i:1
disable menu anims:i:1
disable themes:i:0
disable cursor setting:i:0
bitmapcachepersistenable:i:1
full address:s:prod.goctii.com
audiomode:i:0
redirectprinters:i:1
redirectcomports:i:0
redirectsmartcards:i:1
redirectclipboard:i:1
redirectposdevices:i:0
autoreconnection enabled:i:1
authentication level:i:2
prompt for credentials:i:0
negotiate security layer:i:1
remoteapplicationmode:i:0
alternate shell:s:
shell working directory:s:
gatewayhostname:s:
gatewayusagemethod:i:4
gatewaycredentialssource:i:4
gatewayprofileusagemethod:i:0
promptcredentialonce:i:0
gatewaybrokeringtype:i:0
use redirection server name:i:0
rdgiskdcproxy:i:0
kdcproxyname:s:
alternate shell:s:"C:\CTII\AppMan\AppMan.exe"
So originally I had the WindowStartupLocation = CenterScreen in the XAML.
I would double click the remote desktop connection file that I placed on my desktop and then login with my credentials.
The main application portal form is displayed in the upper left hand corner of the remote desktop connection screen fully maximized as seen below
Now if I launch the FBM application from this application list and then click the button to return to the main application portal, the form is centered in the remote desktop connection window like it should as shown below.
So I placed the WindowsStartupLocation = CenterScreen in the constructor and removed it from the XAML with no success.
So I was looking through the StackOverflow community and found this article: Why does WindowStartupLocation = CenterScreen place my window somewhere other than the center of the screen?
I tried the Edit #4 - Workaround by creating a blank window that is launched first and then is hidden after the form has been displayed. When it is closed, then the blank window is also closed.
It also didn't work.
So I am trying to figure out where is the needle in the haystack.
If anyone has any insight on what I can try, please post a URL or reply back with suggestions.
Thank you very much StackOverflow community for taking the time to review my case and provide feedback.
I am having a strange problem that I am unable to access files written by my c# application. My app basically does :
var file = "C:\\Users\\Public\\Documents\\something.txt";
List<string> content = new List<string> { "one thing", "two things" };
Console.WriteLine(System.IO.File.Exists(file));
System.IO.File.WriteAllLines(file, content);
Console.WriteLine(System.IO.File.Exists(file));
The first time I run the app, the output is
False
True
Yet I cannot see the written file in Windows Explorer (Windows 10). I get no exceptions attempting to write the file. The second time I run the app, the output is :
True
True
According to my application the file is being written however Windows thinks differently. As a sanity check I spun up a second app that opens a dialog using OpenFileDialog. When I run that, I am able to see my written files! Windows explorer still cannot. Attached is a screenshot of windows explorer and my openfiledialog side by side.
If I go to notepad and browse for the file I cannot see it or manually type in the name.
Its been a long week of work, there must be some dumb explanation...? Help! :-)
Screenshot - windows explorer on left, c# app open dialog on right :
https://imgur.com/a/8ZTDIe6
per #BACON 's suggestion in the comments above I discovered that after disabling the Comodo anti-virus I am able to write and see my files.
I believe the software is running my app or either only allowing IO from my app in some kind of container. I need to figure out how to grant my apps proper permissions through the anti-virus software, but that was the culprit.
I'm automating tests using Selenium and C# and I need to open an external app from the browser. The problem is, I always get this notification and it blocks the test execution.
Does anyone know how to deal with this?
Chrome stores the settings for the acceptance of protocol handlers in the user profile. When running Chrome from Selenium, Chrome doesn't seem to use the standard Chrome user profile by default, and instead uses some default settings that are not persisted.
To get around this, you can launch Chrome from the command line manually and manually specify a new --user-data-dir=c:\foo\bar profile location. (Point it to a new/empty directory and Chrome will populate it for you.)
Using this manually-launched browser, navigate to the page you need to interact with, activate the link, click the "always open" checkbox, and run the program once.
Next, close Chrome and save a copy of the entire new user profile directory. When you run your Selenium tests, make sure to always pass Chrome the same command line options pointing it to that user profile. These settings are now persisted, so the link will open without user intervention in the future. (This question may be of help to feed the right command line args to Chrome.)
For repeatable tests, you will probably want to save a static copy of this profile and redeploy it whenever you launch Selenium.
If you are using Javascript+Selenium or WebdriverJS then use this :
chromeOptions = {
'args': ['--test-type',
'--start-maximized',
'use-fake-ui-for-media-stream',],
'prefs': {
protocol_handler: {
excluded_schemes: {
'yourprotocolname': false
}
}
},
};
I want to write a program which recognizes when a browser is open and which do every time an action, when the user went to a website. For example:
The program is running as a system tray and starting automatically on windows startup. (this works)
Now the program runs an function, if the client open a random internet-browser (IE, Chrome, ...) which have the example-code MessageBox.Show("You opened a browser!").
If the user types for example "www.google.com" in the address bar and push [enter] the program should open an example-function like MessageBox.Show("You entered " + enteredURL) before the Website is loaded.
Thanks in advance for your help!
Take a look at the Navigating event:
Occurs before the WebBrowser control navigates to a new document.
It is possible to connect to an existing instance of IE, but you'll need to work with underlying the COM API (see here).
For other browsers there is no general mechanism: you'll need to work out if some API even exists browser by browser.
As the title states, I have a C# console app which uses interop to open Excel and create a new workbook. The code works fine when running the console app via command line. However this exception is thrown when running the console app via a scheduled task:
System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005
It is thrown from the following call:
_xlApp = new Excel.Application()
The scheduled task is setup to use my credentials (I am an administrator). Based on other forums I have made sure I have granted full control to my account at Component Services --> Computers --> My Computer --> DCom Config --> Microsoft Excel Application, but no luck.
I'm on Windows 7 Enterprise 64 bit. Not sure what the next step should be, any help is appreciated
The error 80070005 is a COM Access Denied error.
Are you sure that your credentials have the ability to instantiate the Interop Library?
Check this link and follow some of the debug steps.
(I know you said you did the DCOMConfig thing already, but there are more test scenarios in this link and hopefully something here will help you)
I ended up writing a windows service to call out to a library containing the Excel generation code. That fixed the error. However there was another COM exception when calling the workbook.Save() method. No matter what I tried that error would not go away. I read another post which stated that this was a security precaution and therefore by design.
However, calling workbook.SaveAs() will produce the same result and works fine when called from a windows service.
Thanks for the input funkymushroom. Hopefully this post will be helpful to someone else struggling with Excel Interop automation.
I had the similar issue, I have resolved the issue by performing the following steps.
DCOM Configuration
Click Start -> Run
Enter DCOMCNFG and press OK. This will open the DCOMCNFG window.
Browse down the tree to Console Root -> Component Services -> Computers -> My Computer
right-click on "My Computer" and select properties
Select the "Default Properties" tab
Enable Distributed COM on this computer - Option is checked
Default Authentication Level - Set to Connect
Default Impersonation Level - Set to Identify
Select the "COM Security" tab
Click on Access Permissions ' Edit Default
a. Add "Anonymous", "Everyone", "Interactive", "Network", "System" with Local and Remote access permissions set.
Click on Launch and Activation Permissions ' Edit Default
a. Add "Anonymous", "Everyone", "Interactive", "Network", "System" with Local and Remote access permissions set.
Click on OK
Close the DCOMCNFG window
Later I got an exception while opening the Excel. So please make sure that the following paths are available on the server.
C:\Windows\SysWOW64\config\systemprofile\Desktop
C:\Windows\SysWOW64\config\systemprofile\AppData\Roaming\Microsoft
C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft
This might help guys like me.
I also had this problem - it turned out that on the scheduled task I needed to tick the box "Run with highest privileges" on the General tab of the task set-up. This resolved the problem - it was so simple! Hope it helps someone else too.