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
Something like this should do the trick for you. Although, I added very little error checking.