Reg Query in script not working when executed remotely with psexec
<p>I have recently gotten a script together for querying the reg for a temp folder path and cleaning the folder and it works great(Thanks Compo) but when used remotely with psexec it says, "The system was unable to find the specified registry key or value."  Before I use PSEXEC to execute the batch I first have it copied to the C:\ and I use this to do that.</p>

<pre><code>set /p cpu=

robocopy "\\nmcfs01\software\scripts\Jacob's Awesome Outlook Scripts" \\%cpu%\c$\Jacob'sTemp
</code></pre>

<p>That part goes well then I execute it with psexec with </p>

<pre><code>psexec \\%cpu% -u administrator -i -d "C:\Jacob'sTemp\compo.bat"
</code></pre>

<p>That connects but when it executes the batch file it does not find the reg key.  HOWEVER, if I go to the C:\Jacob'sTemp and double click on the compo.bat file it works fine and deletes out the files.  Also, if I just use PSEXEC to execute it again outside of this script just separately after it is copied over it still does not work.  Here is the script I am using for cleaning it up.</p>

<pre><code>@Echo Off
SetLocal EnableExtensions

(Set OV=14.0)

Choice /C YN /M "Delete Outlook Temp Files?"
If ErrorLevel 2 Exit/B
Set "BK=HKCU\SOFTWARE\Microsoft\Office\"
Set "EK=\Outlook\Security"
Set "VN=OutlookSecureTempFolder"
For /F "Tokens=2*" %%I In ('Reg Query "%BK%%OV%%EK%" /V %VN%') Do Set "VD=%%J"
PushD "%VD%" &amp;&amp; (RD/S/Q "%VD%" 2&gt;Nul) &amp;&amp; PopD
pause
REM The below commands will empty Jacob'sTemp:
If Exist "%SystemDrive%\Jacob'sTemp" (PushD "%SystemDrive%\Jacob'sTemp" &amp;&amp; (
    (RD/S/Q "%SystemDrive%\Jacob'sTemp" 2&gt;Nul) &amp;&amp; PopD
pause
REM The below commands without the first two characters will remove Jacob'sTemp
If Exist "%SystemDrive%\Jacob'sTemp" (RD/S/Q "%SystemDrive%\Jacob'sTemp"
Pause
Echo(------------------------------------------------------------------------------
Echo( Complete!  Goodbye!
Echo(------------------------------------------------------------------------------
Timeout 5 &gt;Nul
</code></pre>

<p>It would be a huge help to have this work as intended where we can just type the computer name in and done but I do not know why it does not work when executed remotely and it is copied to the computer.  Any help is much appreciated!</p>