How to create a UWP application which only opens a specific url - c#

I want to create a UWP application which only opens a specific url in the browser. So I mean that this app will have an icon in the start menu but when a user clicks this icon nothing happens but only my url is opened in the browser. Is it possible? How to implement such UWP application?
I created an App class and in OnLaunched method I wrote this code:
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
var task = Windows.System.Launcher.LaunchUriAsync(new Uri("https://stackoverflow.com")).AsTask();
task.Wait();
CoreApplication.Exit();
}
This works fine. The only problem is that white window of my app is opened and closed after about 1 second.
Update 1:
The main purpose of my app is to work as an appservice. Another component of my system successfully communicates with it. If it is possible not to show the icon in the start menu at all it would be great solution. However, I don't know how to hide my app from the start menu. So another appropriate solution for me is just to open the url of my specific web site without showing a splash window once a user clicks the icon in the start menu.
I don't care about certification in the store.

Even if you can successfully implement such behavior, the app window and splash screen will still display (even if just for a while) and the app will definitely not pass Microsoft Store submission (because it exits during launch and it brings no additional value over the website itself)

Related

WPF form is cradling the upper left hand corner of a remote desktop connection screen even though I specify "CenterScreen"

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.

How to quit a unity app which is opened by URL SCHEME and go back to the main app?

I have a IOS app which show product details and for the AR section it opens another unity app.What I want to do is Quit the Unity app and go back to same page in the main app.I have used the following code.
public void BackHome()
{
Application.Quit();
}
The problem with this code is it quits like termination not smooth closing of app.Also it goes directly to the Home screen not to the app (that is main app page from where the Unity App opened up).What I want to do is open Unity app from the main app and after that while hitting a back button would like to close the unity app and return to the main app.
In player setting in Unity I have given Behaviour in BackGround - Exit.
Before Application.Quit, try open main app by URLSCHEME: Application.OpenURL("XXXXXX").

AppServiceBridge without console window

I'm playing with Microsoft's UWP AppServiceBridgeSample (here).
It is working well, but I would like to get rid of the console window of the BackgroundProcess application. The reason for this is that my BackgroundProcess starts another Win32 desktop application and works only as a mediator, so I don't want to disturb users with a console window. (Yes, it can be minimized, but I would rather not show it at all).
I have tried to hide it using the API mentioned here, but with no luck, the console window is still visible. Neither did switching the project's output type from Console Application to Windows Application.work.
Another thing I have tried was to create other BackgroundProcess project as a Windows application. It runs fine until I call AppServiceConnection.OpenAsync(), which causes the BackgroundProcess application to exitstrong text, thus the connection to UWA is not available.
static async void ThreadProc()
{
try
{
AppServiceConnection connection = new AppServiceConnection();
connection.AppServiceName = "CommunicationService";
connection.PackageFamilyName = Windows.ApplicationModel.Package.Current.Id.FamilyName;
connection.RequestReceived += Connection_RequestReceived;
AppServiceConnectionStatus status = await connection.OpenAsync();
//status check etc. ...
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
It seems that opening the AppService connection is only possible from a console app.
So here are my two questions:
Is it, by any chance, even possible to hide the background process' console window?
Can I use the background process as a Windows application, without AppServiceConnection failing during OpenAsync calls?
Re 1: Go into the project settings and change the output type from Console to Windows app. Also make sure the Main() function doesn't exit until you are done with the background process. Here is a better sample that shows this with a Windows Application:
https://stefanwick.com/2017/05/26/uwp-calling-office-interop-apis/
Re 2: AppServiceConnection works the same way from a windowed application as well. Make sure you add the right reference to the Windows.winmd to be able to build. If you have trouble with that, please post a specific question with details of the problem you are seeing

How to detect when an internet-browser is open in Windows Forms and do an action if an URL was fired?

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.

How to automatically bypass logon message on RDP?

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.

Categories

Resources