Launcher.LaunchUriAsync does not work on Xamarin Forms UWP [duplicate] - windows

no Error just nothing happen and file target still there in my path
public void keyboard(){
ProcessStartInfo touchkey = new ProcessStartInfo(#"C:\Program
Files\Common Files\microsoft shared\ink\TabTip.exe");
touchkey.WorkingDirectory = #"C:\";
touchkey.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(touchkey);
}
Update
The suggested solution threw a `UnauthorizedAccessException`:
var path = #"ms-appx://C:/Program Files/Common Files/microsoft
shared/ink/TabTip.exe";
var file = await
Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(path);
await Windows.System.Launcher.LaunchFileAsync(file);
Update2
I try to use FullTrustProcessLauncher it's work fine but like code before Keyboard tabtip.exe not show I dont know what should I do
await Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
{
FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
});

UWP applications are sandboxed and cannot launch other processes directly due to security restrictions.
The only way to launch other applications is if those applications have a URI registered, or an application is a default handler for a particular file type.
In those instances, you can use methods such as LaunchUriAsync or LaunchFileAsync

Without TabTip.exe
I recognize you are trying to show the on-screen keyboard judging by the path of the exe. I suggest a better approach would be to trigger the new touch-enabled keyboard which is easily possible without additional hassle from UWP with InputPane API:
var pane = InputPane.GetForCurrentView();
pane.TryShow();
With TabTip.exe
If you prefer the older on-screen keyboard for some reason, you have two problems with your existing code.
Firstly, ms-appx: scheme is used to refer to files at the application installation path. The path you require is an absolute path, so you can't use it there.
Secondly, as this is an arbitrary path on the hard drive, you don't have access to it directly (as UWP apps run in a sandbox and can't access the filesystem directly for security reasons). To access the file, you will need to declare the broadFileSystemAccess capability, which will then allow you to initialize the StorageFile instance. You can check for example this SO question to learn how to do just that.
Note: I don't have my VS PC around so I can't say for sure if this will allow you to launch the executable or not, as that seems like an additional permission which may not be granted. In case this fails, I strongly recommend the first solution.

Make sure you edited the manifest file and add the extension for full trust process in the application.

Related

Documents and Music folder -> Windows Defender Ransomware protection breaking my app

So it looks like Windows 10 Ransomware has broken my app (StationRipper). It's a C++/MFC app, but it looks like it would break any app that is doing what StationRipper is doing.
My high-level question:
My app needs to write files (e.g., mp3's) as it records them. Is there actually a sensible place do this to (like, say, the Music folder) if Ransomware protection is on, or am I stuck just creating an arbitrary folder someplace? My app is doing the recording behind the scenes, so the user can't choose the dir for each file.
Details:
My app records music files. A very long time ago (like, in 2002) it wrote it to the users "Music" directory. That worked fine, but now I'm seeing a problem - I'm getting the error code for "The system cannot find the file specified." on CreatedDirectory for my app (which was really fun to track down, as that error code isn't listed as an error that CreateDirectory to return), and when I try to write any file to that directory if I manually create it via file explorer.
I finally tried running mkdir, and to create a file in that dir, outside of my app... the same thing happens.
I turned off Ransomware protection in Windows Defender... and it now works from my app.
It looks like I have to use something like the file picker to save to that dir? Which, as I said, won't work as the user isn't involved after they start recording.
I can't just tell my users to turn Ransomware protection off to use my app, but I would prefer to put the music files in their Music folder...
Any suggestions?
Additional info requested in comments:
TCHAR szDocPath[MAX_PATH];
szDocPath[0] = 0;
if (::SHGetSpecialFolderPath(NULL, szDocPath, CSIDL_PERSONAL, FALSE))
{
_tcscat(szDocPath, "\\StationRipper");
DWORD m_dwLastError = ::GetLastError();
BOOL bResult = CreateDirectory(szDocPath, NULL);
m_dwLastError = ::GetLastError();
}
Running the above with Ransomware protection on results in a zero. With it off returns a 1 (and the directory is created).
(note: SHGetSpecialFolderPath is not supported, but its modern equivalent, SHGetKnownFolderPath has the same issue)
Rather than asking users to disable Ransomware Protection entirely, you can ask them to whitelist your application. See the Whitelist apps with Controlled folder access section of this article (the official documentation is somewhat lacking).

Open default application with nativescript

I am quite surprised I have yet to find an answer to this on the internet.
How do I open a native/default app from my nativescript app?
In this instance I want to open a map application with a location parameter (not sure if it will be a string, coordinates, etc).
You can use utils
var utilsModule = require("tns-core-modules/utils/utils");
utilsModule.openUrl("<< for example: maps short link>>");
In fact it will try to open map link with browser. But android && ios will ask to you “do you want to open it via Maps?” at first.
There may be some plugins for opening via maps directly without any question but I think this way is better (you dont need to install a plugin)
For more info about utils, see that

C# Windows Service - Set service login Issue

I'm building a windows service that retrieves information about different hardware, and after that it stores the information in a database, right now that part is done and im trying to install that service in different computers, and i wanted to know if the little window that pops up during the installation, called Set Service login, is possible to set some default values in those textboxes.
Thanks in advance.
If you use the Visual Studio Installer you could try this:
View the code of the processInstaller and go into InitializeComponent() methode.
There you can set the following properties for an existing local account:
this.servicename_processInstaller.Password = "xxxxx";
this.servicename_processInstaller.Username = ".\\localServiceUserAccount";
This prevent to prompt the window.

Issues while converting a windows app to windows service

I created a monitoring utility that checks cpu, ram, drive space stats and emails if the usage goes above set threshold. It works great in the system tray but I realized that the exe will stop when I log out of windows server. That led me to believe that I needed to create a windows service. I would like to use the existing GUI Form to save data to application settings and use those settings in windows service. Here are the steps I took so far,
Added a Windows Service class.
Modified the original code to get rid of any interactive items that were related to GUI Form.
Added the code to this class.
Added a Service installer.
Added this code to it-->
public ProjectInstaller()
{
InitializeComponent();
ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
ServiceInstaller serviceInstaller = new ServiceInstaller();
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
serviceProcessInstaller.Username = null;
serviceProcessInstaller.Password = null;
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.ServiceName = "Server Monitoring";
this.Installers.Add(serviceProcessInstaller);
this.Installers.Add(serviceInstaller);
}
Change Start up object to Utility.Program.
When I try installing this through installUtil I get this error
System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Use
rs\AdminUser\Desktop\Temp\Server' or one of its dependencies. The system cannot
find the file specified..
Thanks!
If you are saving these application settings into a file that is in the same directory as the Windows service, that is going to be your problem. All Windows Services are run in the C:/Windows directory (or a sub-directory in there) so when you access files you will need to do one of two things:
Change the executing directory
You can change the 'current directory' for the executing app back to the folder that contains the exe with the following line of code:
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
This will make all relative files become relative to the executable location once again.
Make all file request full paths
This one is easier for some files than others. System files are the hardest. So if you are trying to get to a .config file, that's going to be a nightmare.

Using OSX Security-Scoped Bookmarks in a Firemonkey app

I have been developing an OSX app with Delphi XE3 and running into various problems. The latest one is with the sanboxed version built for the Apple Appstore.
The user has to select an arbitrary folder and the app needs to get access to it. Since there is a problem with the OpenDialog, I had to turn to drag-drop functionality instead.
The user drags a folder to the app, the sandbox gives the app temporary access to it and all works properly.
To preserve the access to this folder when the app is restarted I have to use the so-called "security-scoped bookmarks"
I am having two issues with them:
1) How to add the "com.apple.security.files.bookmarks.app-scope" entitlement to an XE3 firemonkey app? It is not available in the Project Options->Entitlements. If I add it manually in the ".entitlements" file it gets overwritten when the app is built.
So is there a way to add a custom entitlement that is not in the list in the project options?
2) To create the bookmark I should use the NSURL.bookmarkDataWithOptions method. I think it should be used like this, but I am not sure of the exact syntax:
var
URL: NSURL;
Err: NSError;
Data: NSData;
...
URL := TNSURL.Create;
Data := URL.bookmarkDataWithOptions(NSURLBookmarkCreationWithSecurityScope, nil, #Err);
...
Maybe there should be a call to Wrap(...) instead of Create.
I have not yet experimented with it, because it is pointless without the answer to issue 1).
It seems no one has written anything about these problems for Delphi, but I hope someone here has experience with that.
Thanks in advance.
Edit:
For problem 1) I tried to add edit manually the ".entitlements" file in the OSX32 folder and set it to read-only to prevent it from being overwritten. It was too easy to be true of course, because the linker complained that the file can not be modified...
OK, I finally found the way to manually add entitlements that are not available in the Project Options > Entitlements.
Instead of selecting the "App Store" build in the Project Manager you have to select a Normal release build and deploy the application as usual.
The application gets deployed in the PAServer scratch-dir as APP package. Inside this package there is an "Entitlements.plist" file, which is in XML format and can be edited with a text editor. It is quite obvious how to add new entitlements once you open the file.
After it is edited, the app has to be code-signed manually and a package has to be prepared. It is slightly more complicated than using the Delphi IDE, but there are instructions about it on the Embarcadero and Apple websites and it actually went without problems.
Still haven't tried the bookmarkDataWithOptions functions.
An alternative could be to deactivate the checkbox for the entitlements-file in the deployment page.
But attention: Evry time you change between Build/Release or App Store/Normal, delphi activates the checkbox. That means you have to deactivate it again in the deplayment-page, to avoid the transfer of this file to the mac PC.
By the way: Do you have tryed meanwhile the StartAccessingSecurityScopedResource function?
In the MacApi.Foundation unit the function is not declared in the NSURL interface.
Do you have found a way to use this function?

Resources