title: Batch File for AutoRun.inf
body: <p>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:</p>
  
  <pre><code>[autorun]
  open=Program1.exe
  </code></pre>
  
  <p>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)</p>
  
  <p>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.</p>
  
  <p>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! :)</p>
  
  <h2>&lt; Edit ></h2>
  
  <p>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:</p>
  
  <pre><code>[autorun]
  open=Program1.exe
  additional text 1
  additional text 2
  </code></pre>
  
  <p>Would the code you provided need to be modified to stop the code from pulling info on the ending lines?</p>
  
  <p>Here is the edit from the D:\ to F:\ drive, did I get everything?</p>
  
  <pre><code>@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
  </code></pre>