BAT file/Script to find and replace files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mrredpants
Posts: 2
Joined: 29 May 2014 12:12

BAT file/Script to find and replace files

#1 Post by mrredpants » 29 May 2014 12:21

Hello!

In a terminal server environment (Windows server 2008 R2) - I want to replace all instances of internet shortcuts for chrome, firefox and IE with custom one's I've created that force opening in incognito or private mode.

So, I need a bat file (or command line) that will scour the users folder and replace all examples of, e.g. "Google Chrome.lnk" with "Google Chrome P.lnk" - the latter being the one I customized with the -incognito parameter.

My intent is to have it replace all desktop shortcuts as well as the pinned shortcuts on the taskbar and start menu. I realize if someone wanted to open a non-private instance, they still could.

Thanks in advance - another forum posted a script here but I couldn't get it to work correctly
http://www.techpowerup.com/forums/threa ... es.146231/

PS - I'm an advanced computer user but NOT a programmer :>)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: BAT file/Script to find and replace files

#2 Post by foxidrive » 29 May 2014 18:16

What are the names of the .lnk files that you want to replace?

mrredpants
Posts: 2
Joined: 29 May 2014 12:12

Re: BAT file/Script to find and replace files

#3 Post by mrredpants » 29 May 2014 18:24

Google Chrome.lnk
Mozilla Firefox.lnk
Internet Explorer.lnk

I can always substitute or add additional links if need be as long as i have the framework
I haven't named the new links yet, but, they could actually be the same name.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: BAT file/Script to find and replace files

#4 Post by foxidrive » 29 May 2014 21:15

This may work - it's untested.

It searches for the .lnk files under c:\users and replaces them with "new link?.lnk" from the same folder as the batch file.


Code: Select all

@echo off
for /r "c:\users" %%a in ("Google Chrome*.lnk") do copy "new linkA.lnk" "%%a"
for /r "c:\users" %%a in ("Mozilla Firefox*.lnk") do copy "new linkB.lnk" "%%a"
for /r "c:\users" %%a in ("Internet Explorer*.lnk") do copy "new linkC.lnk" "%%a"

Post Reply