0

I have created a bat script to install a software and then do find and replace using fnr.exe. I have generated few commands our of fnr.exe and have pasted it within .bat.

Now, since i have generated it out of fnr.exe, i have edited these commands to first find fnr.exe application under C:\Software\fnr.exe, something like below (Just an example):

"C:\Software\fnr.exe" --silent --cl --dir "C:\software\bin" --fileMask "*.*" --excludeFileMask "*.dll, *.exe" --includeSubDirectories --find "Enabled= 0" --replace "Enabled= 1"

Now my service teams aren't very technical and while installting this software on a client machine it is possible that they might copy the software install (folder) to a different location say desktop which would mean that my bat file wouldn't be able to find fnr.exe (coz as per the script it should be under C:\software) and hence find and replace will fail.

Is there a way around it? Any suggestions? Could i do something in the script that would generalise things and it wouldnt matter where they copy the setup folder to install the software on clients machine?

Thanks

Pk boss
  • 274
  • 1
  • 13
irish
  • 197
  • 1
  • 2
  • 18

1 Answers1

1

If I'm understanding you correctly here, you could just do this:

fnr.exe --silent --cl --dir "C:\software\bin" --fileMask "*.*" --excludeFileMask "*.dll, *.exe" --includeSubDirectories --find "Enabled= 0" --replace "Enabled= 1"

That would work so long as fnr.exe is in the same folder as the batch file.

If this doesn't work, it may be due to the batch file being run from a different folder (eg with C:\Software\Example.bat; the current directory could be anywhere.

In that case, do this:

pushd "%~dp0" 
fnr.exe --silent --cl --dir "C:\software\bin" --fileMask "*.*" --excludeFileMask "*.dll, *.exe" --includeSubDirectories --find "Enabled= 0" --replace "Enabled= 1"
popd

This temporarily sets the current directory to the directory of the batch file. (source)

Pokechu22
  • 4,984
  • 9
  • 37
  • 62