Sham1206
Sham1206

Reputation: 1

Writing a batch to run mutiple commands?

I'm trying to run multiple commands in a BAT file, but it is only running the first one, and then stopping. This is what I have:

cmd /k "reg delete HKEY_LOCAL_MACHINE\SOFTWARE\SAP /f"
cmd /k "reg delete HKEY_USERS\.DEFAULT\Software\SAP /f"
cmd /k "RD /S /Q C:\Users\%USERNAME%\AppData\Local\SAP /f"
cmd /k "RD /S /Q C:\Users\%USERNAME%\AppData\Roaming\SAP /f"
cmd /k "RD /S /Q C:\Program Files\SAP /f"
cmd /k "RD /S /Q C:\Program Files (x86)\SAP /f"

It runs the first command successfully then stops.

Upvotes: 0

Views: 58

Answers (2)

Compo
Compo

Reputation: 38604

Simply removing the instances of cmd /k would be the biggest improvement for your script. This version however makes a few less important improvements.

@Echo Off
Reg Delete "HKLM\SOFTWARE\SAP" /F>Nul
Reg Delete "HKU\.DEFAULT\Software\SAP" /F>Nul
RD/S/Q "%LOCALAPPDATA%\SAP"
RD/S/Q "%APPDATA%\SAP"
RD/S/Q "%PROGRAMFILES%\SAP"
RD/S/Q "%PROGRAMFILES(X86)%\SAP"

Upvotes: 2

juzraai
juzraai

Reputation: 5943

I don't think you need the cmd /k part. Did you try this way?

reg delete HKEY_LOCAL_MACHINE\SOFTWARE\SAP /f
reg delete HKEY_USERS.DEFAULT\Software\SAP /f
RD /S /Q "C:\Users\%USERNAME%\AppData\Local\SAP" /f
RD /S /Q "C:\Users\%USERNAME%\AppData\Roaming\SAP" /f
RD /S /Q "C:\Program Files\SAP" /f
RD /S /Q "C:\Program Files (x86)\SAP" /f

Upvotes: 2

Related Questions