Page 1 of 1

[Solved] RunProgram fails as admin

Posted: Sat Jun 08, 2019 8:05 am
by BarryG
Solved! :) I noticed that when I was logged in as admin, my default apps were set to something called "TWINUI". So I googled that, and found this thread:

https://superuser.com/questions/1150365 ... ith-twinui

A little down the page of that link, was a PowerShell script to "reset" the apps to their Win 10 defaults:

https://github.com/WillBixler/TwinUI-Fix

So I downloaded the script and ran it (hoping it wasn't malicious!) and it removed the "TWINUI" defaults and put them back to the correct Win 10 defaults. From there, I was able to change those defaults back to IrfanView (for images) and Media Player Classic (for MP4s).

The end result: my app now runs (opens) the files correctly when run as admin! :D

Original post:

Got a weird one for you. The following line fails to open a JPG image when my exe is run with admin rights, but opens it normally when run with limited rights. What the hell? What could be causing it to fail with admin rights? :shock: The result of RunProgram() is 1, so the command "worked", but no image is opened. I tried disabling my anti-virus (Windows Defender) but it didn't make any difference.

Code: Select all

param$=""
file$="c:\temp\image.jpg"
RunProgram(file$,param$,GetPathPart(file$))
[Edit] I even got this Windows message when trying to run it as admin, so it has to be some sort of permission thing? My program works fine on another PC. Wish I knew why one PC has the issue, though. How can I expect my customers to deal with a problem like this?

Image

Re: RunProgram fails as admin

Posted: Sat Jun 08, 2019 8:10 am
by RSBasic
Works with and without administrator rights.
Which image program is opened on your PC?

Re: RunProgram fails as admin

Posted: Sat Jun 08, 2019 8:11 am
by BarryG
IrfanView. It's so weird, isn't it? Such a simple command and snippet. I'm shocked. Maybe it's a permission thing. Even ShellExecute_() won't open it when run as admin.

Re: RunProgram fails as admin

Posted: Sat Jun 08, 2019 8:21 am
by RSBasic
On my PC the standard Windows program "Windows Photo Viewer" is opened.

Does this code work?

Code: Select all

param$=""
file$="c:\temp\image.jpg"

RunProgram("rundll32.exe", Chr(34) + GetEnvironmentVariable("ProgramFiles") + "\Windows Photo Viewer\PhotoViewer.dll" + Chr(34) + ",ImageView_Fullscreen " + file$, "")

Re: RunProgram fails as admin

Posted: Sat Jun 08, 2019 8:24 am
by RSBasic
Check the opening path: HKEY_CLASSES_ROOT\jpegfile\Shell\open\command
What's the path?
You can open the file with the path entered in the registry.

Re: RunProgram fails as admin

Posted: Sat Jun 08, 2019 8:38 am
by BarryG
Hi RSBasic, opening with your code snippet works perfectly as limited and admin. :)

There's no Registry entry for what you posted (see below). But why does limited open it, but not admin?

Image

Re: RunProgram fails as admin

Posted: Sat Jun 08, 2019 8:47 am
by RSBasic
Can you unfold the "shell" key? There should exist "open" and in the child key "command".

Re: RunProgram fails as admin

Posted: Sat Jun 08, 2019 8:51 am
by BarryG
Nothing under it when expanded. See edited post above with new image.

And it's not just that: when running as limited, PDFs open with SumatraPDF; but when I run as admin, PDFs open with Edge. :shock:

Re: RunProgram fails as admin

Posted: Sat Jun 08, 2019 10:02 am
by Marc56us
Got a weird one for you. The following line fails to open a JPG image when my exe is run with admin rights, but opens it normally when run with limited rights. What the hell? What could be causing it to fail with admin rights? :shock: The result of RunProgram() is 1, so the command "worked", but no image is opened. I tried disabling my anti-virus (Windows Defender) but it didn't make any difference.
First of all, verify Property of file (image.jpg) and parent folder (c:\temp\) (security and owner)

Re: RunProgram fails as admin

Posted: Sat Jun 08, 2019 11:21 am
by BarryG
Marc56us wrote:First of all, verify Property of file (image.jpg) and parent folder (c:\temp\) (security and owner)
Folder and files inside all have full access rights for all users.

Re: RunProgram fails as admin

Posted: Sat Jun 08, 2019 12:59 pm
by Marc56us
This message is a Windows System Message.
Sometime it's due to a corrupted filesystem. This is often the case for illogical behaviour on file access.
:arrow: Check hard drive. (properties, second tab)

Does it occure with another file ? (on another disk drive) (I guess you've already tested it, but just in case...)

:wink:

Re: RunProgram fails as admin

Posted: Sat Jun 08, 2019 1:02 pm
by BarryG
Checked hard drive (SSD), no errors found. It's fairly new, too. The only difference is admin vs limited rights for my process, so wouldn't that rule out any SSD errors?

Re: RunProgram fails as admin

Posted: Sat Jun 08, 2019 1:10 pm
by Marc56us
What about the test with another file? (in another directory)

Re: RunProgram fails as admin

Posted: Sat Jun 08, 2019 1:18 pm
by BarryG
Marc56us wrote:What about the test with another file? (in another directory)
Nope. All JPGs (and MP4s) in other folders won't run from admin either. Only from limited. This bites.