On 2022/07/04 7:22 am, Herbert Kleebauer wrote:
>>> One way to always run as Admin would be to start the batch with:
>>>
>>> If %1=a goto xxxx
>>> SCHTASKS /RUN /TN <TASKNAME> at highest privileges and add argument a.
>>> :xxxx
>>
>> If I can get this to work that will be beautiful as then I won't NEED that
>> damn context menu to run each of a hundred different batch files as admin!
>
> Create a link to the batch file, then in the properties of
> the link you can specify that it should be run as administrator.
Thanks for the advice as I always knew that it was a difficult problem set.
Otherwise I'd already have found a solution in my Internet searches.
Search: How to run a batch file as administrator?
Creating links all day every day fifty times a day might be more work than
just selecting a dozen files at a time and right clicking "Run as Admin."
Mainly I was just trying to clean up the right click context menu so that I
can more easily see "Run as Admin" (for example, if I could put it at the
top or bottom of the list, that would make it easier, as I'm always doing
this all day every day ten times a day.
The batch files change all the time because they are configuration files
that have to be run as administrator because they need to change the
routing table to run VPN.
Each batch file has a different setting for configfile, the problem
being that confifile changes every day a few times a day, otherwise a
single batch file would have worked.
This is the basic boilerplate format of the batch file.
The openvpn config file name changes constantly.
The rest of the boilerplate stays the same.
REM Filename=20220701_1113am_172.178.9.24_udp_1515.bat
REM Must be run as administrator to change the routing table
set DIR=C:\Windows\Temp\openvpn\config\
set CMD=C:\Program Files\OpenVPN\bin\openvpn.exe
set VPN=20220701_1113am_172.178.9.24_udp_1515.ovpn
cd %DIR%
%CMD% %DIR%%VPN%
If I could add lines that put that simple batch skeleton into Administrator
mode when it's doubleclicked, that would solve the problem instantly.
I wouldn't need any rightclick context menu then.
I'd just doubleclick on the batch files.
Otherwise I select a few dozen of these *.bat files and right click and
then select "Run as Administrator" from the *.bat context menu, and then I
hit "Yes" over and over in the UAC prompts until one of those batch files
works.
When that one batch file works, I'm on VPN and then I hit "No" just once to
the UAC prompt and I'm done with interactions until I exit VPN.