0

I was trying this (very rudimentary) command in a batch file

takeown.exe /F c:\WINDOWS\SYSTEM32\%1%
ICACLS C:\WINDOWS\SYSTEM32\%1% /grant MY\PC:F

And when I run it from an admin CMD prompt as:

c:\Data>takeownscript.bat drivers\netbio.sys

It throws an error saying:

c:\Data>takeown.exe /F c:\WINDOWS\SYSTEM32\drivers\netio.sys

SUCCESS: The file (or folder): "c:\WINDOWS\SYSTEM32\drivers\netio.sys" now owned by user "MY\PC".

c:\Data>ICACLS C:\WINDOWS\SYSTEM32\drivers\netio.sysF C:\WINDOWS\SYSTEM32\drivers\netio.sysF: The system cannot find the file specified. Successfully processed 0 files; Failed processing 1 files

How/why is the F getting appended to the driver path ? I am suspecting that I am not using the correct replacement syntax.

Zoso
  • 3,273
  • 1
  • 16
  • 27
  • 2
    Arguments of the batch file should be referenced using `%1`, and not `%1%` as explained in this [question](https://stackoverflow.com/questions/14286457/using-parameters-in-batch-files-at-dos-command-line). – Laf Aug 07 '17 at 15:05
  • @Laf that works. Please consider this query solved! – Zoso Aug 09 '17 at 19:08

1 Answers1

1

Just to finish up so the community knows there is an answer.


Command-line arguments are used as %n(n represents which argument) in a batch file.

Another thing for precaution is that one should use %~1 at all times. %~1 strips off quotes from %1. Note that this won't work: %~yourVariable%.