ShellRunAs with Variable or Error Suppressant

RyanG 1 Reputation point
2022-04-27T06:19:35.807+00:00

I have a command that upon invocation, it runs an app as a different user using the ShellRunAs sysinternal function.

The issue I encounter is this:
So I have a folder titled "Apps"

C:\Users\Ryan\Apps  

Inside of Apps are several files, such as...

Chrome.lnk  
iTunes.lnk  
Explorer++.exe  
MMC.mmc  
Install.msi  
etc.  

Notice there are various file extensions here inside "Apps". I have mostly .lnk files, but there are some .exe and other miscellaneous extensions.
I have a file containing a list of variables, with reference to their program name, without their extension.

So the file might say:

App01=Chrome  
App02=MMC  
App03=Explorer++  
...  
App26=Powershell.lnk  

I have a file that runs this command:

shellrunas "C:\Users\Ryan\#App%1#.lnk"  

where #App%1# looks for a variable titled App01, 02, 03, ... all the way to App28 , then returns the text to the right of the equal sign.

Now my issue, is if I want to streamline this, and make this shellrunas work for multiple applications, I get this error when the extension is .exe or .mmc, or ....

196825-image.png

My question is, is there a simple way to suppress this error message if it does not find the file?
This would be the easiest way, then I can force all my commands to execute this:

shellrunas "C:\Users\Ryan\#App%1#.lnk" && shellrunas "C:\Users\Ryan\#App%1#.exe" && shellrunas "C:\Users\Ryan\#App%1#.mmc"  

This would allow me to use duplicate code (EEEK!!) to achieve my goal without interruptions.

PS:

The program I am using does not recognize wildcards for the extension, so putting #App%1#.* or #App%1#*.* will not work.

I am using Rainmeter to execute a list of shortcuts and applications with the shellrunas feature.

Everything works if I put the actual extensions of the file, but this would be tedious, and not allow me bypass an extra 30 lines of code.

If I can apply one wildcard, or one error suppressant somewhere, that would be ideal.

Sysinternals
Sysinternals
Advanced system utilities to manage, troubleshoot, and diagnose Windows and Linux systems and applications.
0 comments No comments
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.