0

I have a variety of CD's that have AutoRun.inf files on them. As you all know, AutoRun.inf has been disabled on Windows 7 for the security risks. I would like to know if it is possible to create and run a batch file that would extract the text in the .inf after the open= and then run the application, whatever it's name may be. For example, if we had the following .inf file file:

[autorun]
open=Program1.exe

Would it be possible to write a batch that would extract the text Program1.exe and then execute the program from the batch with a run D:\Program1.exe (assuming D:\ is the CD: drive)

Please note the Program1.exe would be a variable and constantly changing, the only constant would be the drive letter the CD would be in, D:\ in the example.

Please let me know if any clarification is needed, if this is possible, or of any other suggestions to resolve the scenario I have present. Thanks for any and all help! :)

< Edit >

Thanks for the response. I tried your code and changed the drive to F:\ for the Cd drive, please see below. I was unable to get it to run the program and noticed one additional discrepancy other than the drive letter. In some of the .inf files there are additional lines after the open= file, example below:

[autorun]
open=Program1.exe
additional text 1
additional text 2

Would the code you provided need to be modified to stop the code from pulling info on the ending lines?

Here is the edit from the D:\ to F:\ drive, did I get everything?

@echo on
setlocal ENABLEDELAYEDEXPANSION

set _drive=F:

cd /f !_drive!\
for /f "tokens=1,2* delims==" %%i in ('type autorun.inf') do (
  if "%%i"=="open" set _cmd=%%j
)
if not defined _cmd (
  echo Unable to parse autorun.inf and find 'open='
) else (
  !_drive!\!_cmd!
)


endlocal
James L.
  • 9,384
  • 5
  • 38
  • 77
ITguy7
  • 3
  • 1
  • 1
  • 3
  • Have you tried anything yet? It's best to post the code that you've tried and then ask questions. This one's pretty simple, so I might just type up an answer... But it's still best if you provide the initial code and ask questions about it. – James L. Dec 03 '13 at 22:36
  • I have not tried anything yet, I am only familiar with he very basics. Please see main post. – ITguy7 Dec 04 '13 at 20:41

1 Answers1

1

Something like this should do the trick for you. Although, I added very little error checking.

@echo off
setlocal ENABLEDELAYEDEXPANSION

set _drive=F:
set _cmd=

cd /d !_drive!\
for /f "tokens=1,2* delims==" %%i in (autorun.inf) do (
  if "%%i"=="open" set _cmd=%%j
  if "%%i"=="Open" set _cmd=%%j
  if "%%i"=="OPEN" set _cmd=%%j
)
if not defined _cmd (
  echo Unable to parse autorun.inf and find 'open='
) else (
  !_drive!\!_cmd!
)

endlocal
James L.
  • 9,384
  • 5
  • 38
  • 77
  • You should have added your question to my answer here -- "will it ignore the `addition text 1` and `additional text 2`?" The answer is **yes**. It will only pull the information after the `open=` to execute. However, `Open=` is not the same as `open=`, so it won't handle that or any other variation without additional coding. – James L. Dec 04 '13 at 21:32
  • You should go to a CMD prompt and type `for /?` to learn more about the `for` command. That way you can understand what the batch-file is doing, and perhaps customize it to your particular need. – James L. Dec 04 '13 at 21:33
  • I tweaked the code to handle `open`, `Open`, and `OPEN`. There are lots of ways to check for all three. The way I did it is perhaps the easiest to read/understand... – James L. Dec 04 '13 at 21:45
  • Awesome, thank you for your help! I will go in and read the info for /? This is a huge help and great start, I can reference what you've wrote and learn, thanks a TON my friend! May your kindness be repaid many times over! :) – ITguy7 Dec 05 '13 at 22:31