Batch File help - delete reg key and install software

Hello,

I'm looking for a batch script that will query to see if a reg key of 'PendingFileRenameOperations' is present in the following location: "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\"

I don't want to know the value of this key, I just need it deleting if it exists, after this I need to trigger an software installation.

So in summary, query the key, delete it then install software, if the key does not exist then I still need the software to install. what I've got so far:

reg query  /v  "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations"

if %ERRORLEVEL% == 0 goto DELETE
if %ERRORLEVEL% == 1 goto Install

:DELETE reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager" /v PendingFileRenameOperations /f

:Install %~dp0Agent-Windows-x64-7-50-6422.exe /s /v" SILENTINSTALLDIR=\"C:\Software\Evault\" ACCOUNTTYPE=localsystem REGISTERWITHWEBCC=true AMPNWADDRESS=amp-proxy.itservicedesk.uk.com AMPUSERNAME="Username" AMPPASSWORD="Password" KEEPAMPREGISTRATION=true FEATURECLUSTER=ON FEATUREEXCHANGEMAPI=OFF FEATUREEXCHANGE=ON FEATUREEXCHANGE2010=ON FEATUREMAESTRO=OFF FEATUREORACLE=OFF FEATURESHAREPOINT=OFF FEATURESQL=ON FEATUREVOLUMEIMAGE=ON /qn"

Reg location
The script does not need to include the path of the installation as it's in the same directory as the script.
ProjNetAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Assuming your setup command is correct, try this:
@echo off
setlocal
reg.exe query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager" /v PendingFileRenameOperations 1>NUL 2>&1
if errorlevel 1 goto Install
reg.exe delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager" /v PendingFileRenameOperations /f
:Install
"%~dp0Agent-Windows-x64-7-50-6422.exe" /s /v" SILENTINSTALLDIR=\"C:\Software\Evault\" ACCOUNTTYPE=localsystem REGISTERWITHWEBCC=true AMPNWADDRESS=amp-proxy.itservicedesk.uk.com AMPUSERNAME="Username" AMPPASSWORD="Password" KEEPAMPREGISTRATION=true FEATURECLUSTER=ON FEATUREEXCHANGEMAPI=OFF FEATUREEXCHANGE=ON FEATUREEXCHANGE2010=ON FEATUREMAESTRO=OFF FEATUREORACLE=OFF FEATURESHAREPOINT=OFF FEATURESQL=ON FEATUREVOLUMEIMAGE=ON /qn"

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
deroodeSystems AdministratorCommented:
Be warned however that this PendingFileRenameOperations is used by all software installers including windows update to replace system files on startup that are in use once windows has started, and deleting this key may very well invalidate or corrupt any installed software or windows updates, rendering your computer unable to startup.
ProjNetAuthor Commented:
Spot on, thank you.
ProjNetAuthor Commented:
Yes you're right, I've informed the client of the risks and they're willing to accept it.

Thanks for the script, it worked perfectly.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.