Leavii
Leavii

Reputation: 82

Reg Query wiping computer when using remotely

Recently I got a script to query the reg set a value and then delete folders under the folder I puled from the query. Looks like this:

pause

FOR /F "TOKENS=2*" %%I IN ('REG QUERY "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\14.0\Outlook\Security" /V OutlookSecureTempFolder') Do SET "ValueData=%%J"

pause

echo Delete Outlook Temp. Files???
echo Enter to continue or Ctrl+C to cancel.

pause

del /q /f /s "%valuedata%\*.*"

del /q /f /s "%systemdrive%\Jacob'sTemp"

pause
echo --------------------------------------------------------------------------------
echo Complete!  Goodbye!
echo --------------------------------------------------------------------------------


timeout /t 3

Works great when used locally. So I set up a robo copy to copy a folder with this script in it then use psexec to execute it remotely and it looks like this:

set /p cpu=

robocopy "\\nmcfs01\software\scripts\Jacob's Awesome Outlook Scripts" \\%cpu%\c$\Jacob'sTemp

pause

psexec \\%cpu% -u administrator "%systemdrive%\Jacob'sTemp\outlooktempdelete.bat"


pause

Now it works and it will run but here is the kicker when it goes back to the reg query batch to do the reg query it will run but it skips the 1st pause following the query and it always says it can not find the registry key but I can follow the path and it is there. The worst part is once I end the script there it wipes the computer of everything the user has access to. Not folders but all files/subfiles everywhere. Any insight is greatly appricated!

Upvotes: 0

Views: 121

Answers (1)

Compo
Compo

Reputation: 38708

Here's a quick tidy up of your script:

@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%" && (RD/S/Q "%VD%" 2>Nul) && PopD
REM The below commands will empty Jacob'sTemp:
If Exist "%SystemDrive%\Jacob'sTemp" (PushD "%SystemDrive%\Jacob'sTemp" && (
    (RD/S/Q "%SystemDrive%\Jacob'sTemp" 2>Nul) && PopD
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 >Nul

Give that a try exactly as it is just to see if it makes any difference.

I left the lonely but editable 'set' at the top because this is the only bit that need's changing to cater for earlier or later editions of outlook.

Upvotes: 1

Related Questions