1

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.

Sam
  • 17
  • 1
  • 1
  • 4
  • Where does that mount command come from ? As far as I know there isn't any mount command in Windows 10... – Tonny Dec 28 '18 at 14:03
  • Possible duplicate of [How can I mount an ISO via PowerShell/programmatically?](https://superuser.com/questions/499264/how-can-i-mount-an-iso-via-powershell-programmatically) – LotPings Dec 28 '18 at 14:06
  • @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. – Tonny Dec 28 '18 at 14:11
  • The script should not only mount the ISO file, it should also run the executable lfs-inst.exe that resides in it. – Sam Dec 28 '18 at 14:45

2 Answers2

2

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
LPChip
  • 59,229
  • 10
  • 98
  • 140
  • 1
    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!! – Vomit IT - Chunky Mess Style Dec 28 '18 at 15:48
  • I don't know how to eject via commandline without going the powershell route. – LPChip Dec 28 '18 at 16:00
  • 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`. – Ultrasonic54321 Dec 28 '18 at 16:16
  • Do I have to make a .bat file or a .cmd file for the above answer. – Sam Dec 28 '18 at 16:43
  • @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 Dec 28 '18 at 16:52
  • @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. – Vomit IT - Chunky Mess Style Dec 28 '18 at 16:55
  • @PimpJuiceIT, I think you have to use a program like these: https://thegeekpage.com/free-tools-to-eject-or-close-cddvd-tray/ Maybe one of them you can call from command line – Wernfried Domscheit Apr 23 '20 at 05:15
  • I do not want to rely on default file extension handling because usually I assign .iso to 7-zip. So, is there another approach? – Chameleon Jun 30 '23 at 12:00
0
Explorer "D:\A folder\An image.iso"

The above command tells Windows to use Windows Explorer (explorer.exe) to open (mount) the ISO file.

Matthew Wai
  • 541
  • 3
  • 12
  • 32