Batch script fails when run as admin from explorer, but not when run as admin from terminal?
<p>I have a batch script that needs to run as admin. I will be distributing to users so it would be best if they can run it from Windows Explorer.</p>

<p>Unfortunately, it doesn't work when run from explorer (right click -> run as admin). It does work when called from a pre-existing admin terminal. </p>

<p>Initially I thought the problem was with the active directory, but I added a "cd /d %~dp0" as the first command. I confirmed through echo that this places them both in the same directory, but it still fails when running from explorer.</p>

<p>The failure occurs when reading an external file in the same directory as the .bat. It pulls empty strings when run from explorer. Here is sample code:</p>

<pre><code>rem Make sure active directory is correct (verified that this works)
cd /d %~dp0

rem Load parameters from params.txt
for /f "delims== tokens=1,2" %%G in ("params.txt") do set %%G=%%H

rem Print params (it's a loop so you can read it when running from expl.)
for /l %%a in (1 1 100000) do echo %DST%
</code></pre>

<p>Then you just need to make sure params.txt is in same directory as .bat and includes the line "DST=some\directory\name"</p>

<p>Anybody know why this doesn't work?</p>