Jump to content

Conditional Cleanup Items?


Recommended Posts

Hi all,

I'm editing my cleanup.cmd file, and there's something I need to do.

I need a way to say "If Firefox is installed, then run the following 3 lines of code".

Then 3 lines of code are:

REM	Mozilla Firefox (Remove IE Shortcuts)
DEL "%UserProfile%\Application Data\Microsoft\Internet Explorer\Quick Launch\Launch Internet Explorer Browser.lnk"
REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu /v "{871C5380-42A0-1069-A2EA-08002B30309D}" /t REG_DWORD /d 1 /f
REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\HideDesktopIcons\NewStartPanel /v "{871C5380-42A0-1069-A2EA-08002B30309D}" /t REG_DWORD /d 1 /f

But these lines should ONLY run, IF firefox was installed.

Also, I need the way to check for firefox to be path-indifferent - meaning, it doesn't matter where firefox is installed to.

How can I do this?

Link to comment
Share on other sites


@ a06lp, this should do it!

@echo off&setlocal enableextensions

for /f "delims=" %%a in ('reg query "HKLM\SOFTWARE\Mozilla\Mozilla Firefox" /s^|findstr "\\Main$"^2^>nul') do (

  if errorlevel 0 for /f "tokens=1,3* delims= " %%b in ('reg query "%%a"^|find "Install Directory"^2^>nul') do (

    if errorlevel 0 set ffdir="%%~c"

  )

)

if defined ffdir (

  :: Mozilla Firefox (Remove IE Shortcuts)

  echo/del /q "%UserProfile%\Application Data\Microsoft\Internet Explorer\Quick Launch\Launch Internet Explorer Browser.lnk"

  echo/reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu /v "{871C5380-42A0-1069-A2EA-08002B30309D}" /t REG_DWORD /d 1 /f

  echo/reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\HideDesktopIcons\NewStartPanel /v "{871C5380-42A0-1069-A2EA-08002B30309D}" /t REG_DWORD /d 1 /f

)

pause&endlocal&goto :eof

Just remove the stuff in red once you have verified it works.

<Edit>

Just looking back at my code, I have noticed that, due to the way the site software works, I need to mention something.

  • make sure when you paste the information into your file, that:
    delims=<Tab>
    not
    delims=<Space>

<Edit>

Edited by Yzöwl
Link to comment
Share on other sites

Just looking back at my code, I have noticed that, due to the way the site software works, I need to mention something.
  • make sure when you paste the information into your file, that:

delims=<Tab>

not

delims=<Space>

Hmm, why is this? Are you sure it won't work? It seemed to be working when I copied and pasted the original code into my cleanup.cmd file...

Link to comment
Share on other sites

The code will still do it's job in that it will still run the appropriate commands, only if the application is installed.

However, the content of %ffdir% will be incorrect. If you use delims=<Tab>, then %ffdir% will also contain the installation path for the application, which you would be able to utilise further in your batch file if you felt the need.

<Edit>

Oh and thank you usually works better for me

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...