Executing FolderItem.Open on exe

I’m trying to run the native Windows 10 native screen snipping tool from my app using this:

var st As FolderItem
st = SpecialFolder.System.Child("SnippingTool.exe")
'' did not show the file  st = FolderItem.ShowOpenFileDialog("")
MessageBox(st.NativePath) ' this is correct path and file name
If st = Nil Then
  MessageBox("Nil")
ElseIf st.Exists = False Then
  MessageBox("DoesNotExist")
Else 
  st.Open()
End If

I can see that the path is correct and file is indeed there. However, I am getting a does not exist error. In fact, if I copy the path generated and just post it into File Explorer it runs.

Interestingly, I can navigate and go to this file in File Explorer. However, if use the file open dialog option commented out above, that file does not show up in the XOJO file dialog.

If I replace SnippingTool.exe with calc.exe the calculator runs. This could be a permissions issue, but why am I able to view and run in file explorer but not by executing above.

Ideas?

On macOS that is the telltale sign of a security issue. System security prevents your app from being able to access paths that aren’t provided by the user, but the user can access them easily through Finder.

Check your Windows Defender settings related to ransomeware (called “Controlled folder access” here on Windows 11). It does seem odd that Calculator will launch though, this is just a guess.

Also, I think I remember something about Microsoft removing the classic snipping tool to replace it with a newer tool. When I check the location your code describes (\Windows\System32\SnippingTool.exe) it truly does not exist, while calc.exe does. (again for clarity, I’m on Windows 11 so that may be a factor).

You might have to find another way to launch Snipping Tool to make sure you’re getting the right one.

Hi Tim,

Thanks for the ideas. On Win10, or at least my machine the snipping tool that comes up by default (print screen) is still located in the \Windows\System32\SnippingTool.exe. I can actually just paste that in file explorer and it runs.

It could be a security issue, but the weird thing is that the file shows in windows file explorer, but in the Xojo open file dialog it does not. Quite strange.

If you start snipping tool by searching for snip in the search box, then start TaskManager and look at the processes, what is the name of the tool it actually launches?

SnippingTool.exe

image

Tried your code on my Windows 10 and Xojo2023R2 and it opened Snipping Tool just fine

1 Like

Hi Brian, thanks for testing that! I suspect some type of issue with antivirus or system permissions.

Thanks!

@Joseph_E

You are welcome and hope it helps you narrow down and resolve the issue you are having :+1:

Does it work if you run your app as Administrator? That would indicate permissions.

@Tim_Hare
Wouldn’t UAC still have elevation prompt if the application required it, Admin or not?

No.

Alrighty :grin:

I checked and the code the OP posted worked for me as standard user and user belonging to admin group

The snipping tool might be disabled.

Check the registry for HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\TabletPC\DisableSnippingTool

If this key exists and is set to 1 (true) then the snipping tool is not allowed to run.

Right click on the child process, properties, check the path.

in windows 11, after some updates, the snipping functionality is now backed in the OS, not an exe. So be aware that your solution will not be universal on every windows version.

An update: Thanks for everyone’s help on this. After much wrangling, I created a new test project to try and isolate the issue and do some testing.

I created a new project and I dropped my code in a button and bam it worked! Why? Well, the new desktop project defaults to 64 bit. If I change that to 32 bit it will error out and not let it run - because it can’t find the file.

Can anyone else confirm this and why would this behave this way?

Thanks!