How to Write a CMD Script to Mount and Use ISO File

17,532

By default, doubleclicking an .iso file will mount it in windows 10. If you have not altered this behavior, you can use the following command to do the same:

start lfs-ms.iso

Once the command is executed, the iso is mounted the same way it would be if you double click it.

So a dvd-drive appears in explorer with a driveletter attached to it, and the file is inside. Find out what drive letter the drive has, and use that in your script. I will assume G: here.

The rest of the script can navigate to the drive and execute the file.

Your batch file would look like this:

start lfs-ms.iso
g:
lfs-ms.exe
Share:
17,532

Related videos on Youtube

Sam
Author by

Sam

Updated on September 18, 2022

Comments

  • Sam
    Sam almost 2 years

    I have an ISO file name lfs-ms.iso located at the following directory:

    F:\MS\lfs-ms.iso
    

    This ISO file contains an executable called lfs-inst.exe. I use this file many a times so I have to mount the ISO file manually every time and then open this executable. I wish to automate this process by using a command line script (.cmd). So I am building a script that first navigates to this directory, mounts the ISO file there and then opens the executable as mentioned above.

    @echo off  
    
    cd  F:\MS\ 
    
    mount lfs-ms.iso 
    
    lfs-inst.exe 
    

    I have tried this but that's not working. Can someone help me how to do it.

    • Tonny
      Tonny over 5 years
      Where does that mount command come from ? As far as I know there isn't any mount command in Windows 10...
    • LotPings
      LotPings over 5 years
    • Tonny
      Tonny over 5 years
      @LotPings Not an exact duplicate, But PowerShell is the way to go. You will also need PowerShell to determine the drive-letter the ISO got. AFAIK you can't mount it on a folder, only as random drive-letter.
    • Sam
      Sam over 5 years
      The script should not only mount the ISO file, it should also run the executable lfs-inst.exe that resides in it.
  • Vomit IT - Chunky Mess Style
    Vomit IT - Chunky Mess Style over 5 years
    Might consider adding a method to eject via command too if possible to fully automate if that's of importance to the OP mount and executable execution. This will work without even using start and just pointing to the iso on my Win 10 system too btw!!
  • LPChip
    LPChip over 5 years
    I don't know how to eject via commandline without going the powershell route.
  • Ultrasonic54321
    Ultrasonic54321 over 5 years
    If you have edited the default behaviour for *.iso files, and you wish to open the file (mount to g: drive or something), replace start with explorer.
  • Sam
    Sam over 5 years
    Do I have to make a .bat file or a .cmd file for the above answer.
  • Vomit IT - Chunky Mess Style
    Vomit IT - Chunky Mess Style over 5 years
    @Sam It should work with either .bat or .cmd extension either way for the commands listed in this answer. If you are trying to automate as you indicated, then yes you will want to create a script that you can run ad-hoc as-needed, on a schedule, etc. The question is whether or not the drive letter is of importance or if you can simple hard-code and be assured the same drive letter is always used when the iso is mounted by Windows. If this is of importance, then you may want to also figure out a way to disconnect the mounted drive via command line afterwards.
  • Vomit IT - Chunky Mess Style
    Vomit IT - Chunky Mess Style over 5 years
    @Sam If the same iso is mounted on subsequent runs if the previous mount of the iso is not disconnected or ejected, then same drive letter will be used. If you mount a different iso though while another is already mounted, it will pick another/different drive letter to mount to the iso. You can simply click on the iso and test this but I'd test regardless depending on how critical the process is and emulate the way it will execute per the "automation" envision you have for how that will work.
  • Wernfried Domscheit
    Wernfried Domscheit about 4 years
    @PimpJuiceIT, I think you have to use a program like these: thegeekpage.com/free-tools-to-eject-or-close-cddvd-tray Maybe one of them you can call from command line