Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


ushiro

Install Windows 10 from a USB key with a batch file

Recommended Posts

Hi,

My project is how to create a batch file with a boot menu offering the possibility of installing the following operating system at the user's choice: Windows 10 alone or Windows 10 with preinstalled applications.

A menu will allow the user of this medium to choose his hard disk from the disks installed on the workstation. The following disks may be encountered: 120 GB, 200 GB, 450 GB, 1 TB and 2 TB. 

Among the intern's workstation applications we have: Vmware, Teamviewer, Vnc, Camtasia, Acrobatpdf.

Is it possible to any help to build it?

 

Regards,

 

Shindenryu

Share this post


Link to post
Share on other sites

9 hours ago, ushiro said:

Is it possible to any help to build it?

Yes.

https://jdebp.eu/FGA/questions-with-yes-or-no-answers.html

Of course it depends on what kind of help you are looking for, like:
1) having the whole batch written by some member of the board
or:
2) ask for a code snippet here or there to solve a specific problem you encounter
or:
3) advice on what approach and tools are better/more suitable

Essentially:
1) forget about it
2) just ask :)
3) Nowadays a Windows 10 install is essentially the booting off a PE of sorts and applying of a .wim file, and we casually have here a very good program to this scope:
https://msfn.org/board/topic/149612-winntsetup-v421/

so maybe you want to have a look at it and get familiar with the options it offers, and then ask questions on the batch/batches needed to automate it as much a possible ... 

jaclaz

 

 

Share this post


Link to post
Share on other sites

Hi,

1) having the whole batch written by some member of the board

It would be great if some member of the board write the whole batch, but I don't want to do in this way.
or:
2) ask for a code snippet here or there to solve a specific problem you encounter

It 's better in this way, I already had some snippets of the command and need some explanation for starting, then with the help of the member of the board I can learn the way to build and some command line.
or:
3) advice on what approach and tools are better/more suitable

Actually I should use Notepad++ for writing the entire batch file.

 

So I am working on it and I will send it as soon as possible.

 

Thanks a lot

Share this post


Link to post
Share on other sites

IMO the easiest way to do this would be to build a custom WinPE. Not sure if it would need any packages.

Then in sources you put your two .wim files.

And use the startnet.cmd to be where you put your menu with the two options. Each would just call setup.exe /unattend:file.xml and each .xml would specify the .wim location and index. You can use Choice to make the menu.

Share this post


Link to post
Share on other sites

Hi,

I tested this code:

@echo off
setlocal enabledelayedexpansion
:debut
cls

ECHO *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ECHO "DISK CAPACITY AVAILABLE"
ECHO *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ECHO *																*
ECHO * "TYPE 1 FOR 120 GB"											*
ECHO * "TYPE 2 FOR 200 GB"											*
ECHO * "TYPE 3 FOR 450 GB"											*
ECHO * "TYPE 4 FOR 1 TB"											*
ECHO * "TYPE 5 FOR 2 TB"											*
ECHO *																*
ECHO *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
SET /p choice="Choose your disk: "
ECHO *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

		IF !choice!==1  (
				set capacity="120 GB"
				echo "you have choose: !capacity!"
				diskpart /s c:/Project/120.txt
				pause	
		) else (
				IF !choice!==2  (
						set capacity="200 GB"
						echo "you have choose: !capacity!"
						diskpart /s x:/diskpart/200.txt
				) else (
						IF !choice!==3  (
								set capacity="450 GB"
								echo "you have choose: !capacity!"
								diskpart /s x:/diskpart/450.txt
						) else (
								IF !choice!==4  (
										set capacity="1 TB"
										echo "you have choose: !capacity!"
										diskpart /s x:/diskpart/1000.txt
								) else (
										IF !choice!==5  (
												set capacity="2 TB"
												echo "you have choose: !capacity!"
												diskpart /s x:/diskpart/2000.txt
										) else (
												set capacity="NON REFERENCE"
												echo "NON REFERENCE"
												pause
												goto debut
										)
								)
						)
				)
		)

I tested on VmWare. I created 5 hard disk.
After executing this script, Diskpart works very well for Disk 1.

But the disk initialized by diskpart is not displaying on the screen.

I don't understand why.

 

Share this post


Link to post
Share on other sites
Posted (edited)
18 hours ago, ushiro said:

I tested on VmWare. I created 5 hard disk.
After executing this script, Diskpart works very well for Disk 1.

But the disk initialized by diskpart is not displaying on the screen.

I don't understand why.

 

Post one or two of the .txt diskpart script.

JFYI, later (i.e. once the diskpart scripts/commands are tested and work) it is possible to embed them within the batch.

See:

https://msfn.org/board/topic/126069-updated-on-feb-27-2011-ordering-messed-drive-letter-batch-file/page/2/?tab=comments#comment-817142

https://msfn.org/board/topic/126069-updated-on-feb-27-2011-ordering-messed-drive-letter-batch-file/page/2/?tab=comments#comment-817388

You need "better" control of the input, if the user by mistake inputs "strange" characters there may be issues, though it is possible to better validate set /p input, In windows post-XP there is (in case) the choice command which accepts input without needing the [ENTER], maybe it would be more suited than set /p (as it has - besides input validation - also a timeout and a default provision):
https://ss64.com/nt/choice.html

jaclaz

P,S, : ONLY for the fun of it, this is how I would have written your batch (mind you everyone has his/her own "style", not necessarily one is better than the other):

@ECHO OFF
SETLOCAL

:debut
CLS
SET my_120GB=1 120 GB c:/Project/120.txt
SET my_200GB=2 200 GB x:/diskpart/200.txt
SET my_450GB=3 450 GB x:/diskpart/450.txt
SET my_1000GB=4 1000 GB x:/diskpart/1000.txt
SET my_2000GB=5 2000 GB x:/diskpart/2000.txt

ECHO *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ECHO "DISK CAPACITY AVAILABLE"
ECHO *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
ECHO.
ECHO 1^)  120 GB
ECHO 2^)  200 GB
ECHO 3^)  450 GB
ECHO 4^) 1000 GB
ECHO 5^) 2000 GB
ECHO.
ECHO *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Choice /T 60 /D 1 /C 12345 /M "Choose your disk:"
ECHO *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

CALL :MyChoice %Errorlevel%

ECHO DONE.
PAUSE
:fin

GOTO :EOF

:MyChoice
FOR /F "tokens=2,3,4 delims= " %%A IN ('SET my_ ^|FIND "GB=%1"') DO (
ECHO.
ECHO "you have chosen: %%A %%B"
ECHO diskpart /s %%C
)
GOTO :EOF

 

Edited by jaclaz
  • Like 1

Share this post


Link to post
Share on other sites

Hi,

OK thank you.

Here's the code inside the 120.txt file

select disk 1
clean
creat part prim size=2048
select part 1
format fs=ntfs quick label=SYSTEME
active
creat part prim
select part 2
format fs=ntfs quick label=DATA
list part
exit) > c:/Project/120a.txt

And this the code inside the 200.txt which similar to 120.txt file.

select disk 1
clean
creat part prim size=2048
select part 1
format fs=ntfs quick label=SYSTEME
active
creat part prim
select part 2
format fs=ntfs quick label=DATA
list part
exit) > c:/Project/200a.txt

As I said both are working well, but no drive displayed on Windows.

Capture.PNG.17de48c15d2cf6eef34dfdfb4399c4db.PNG

As you can see in VmWare I have the 5 disks ready (Hard disk 3, Hard disk 2, Hard disk 5, Hard disk 4, Hard disk 6)

Capture1.PNG.364275f8d37704fc9e9536e6ef4d9ffd.PNG

 

Share this post


Link to post
Share on other sites
Posted (edited)

You usually need to assign a drive letter in diskpart:
https://www.windowscentral.com/how-clean-and-format-storage-drive-using-diskpart-windows-10

Or you can use (externally) MountVol:
https://ss64.com/nt/mountvol.html

Since you only have to deal with "normal" volume/partitions on physicaldrives, you won't need anything else, however, and just in case, in this thread it is discussed at length on the various NT devices and DOS ones, besides providing a number of possibly useful tools:
http://reboot.pro/topic/19622-vmount/

starting from around here:
http://reboot.pro/topic/19622-vmount/?p=214603

 

jaclaz

Edited by jaclaz

Share this post


Link to post
Share on other sites

Verify disk numbers.
The 120 GB and 200 GB disks aren't likely to have the same disk number. In both script, you are using Disk 1.

Share this post


Link to post
Share on other sites
2 hours ago, Tripredacus said:

Verify disk numbers.
The 120 GB and 200 GB disks aren't likely to have the same disk number. In both script, you are using Disk 1.

To be fair, once "in production" the Windows 10 will be installed at a time where only one disk to be partitoned/formatted is connected, but it wouldn't be a bad idea to actually verify the disk sizes and avoid the possible operator error.

jaclaz

Share this post


Link to post
Share on other sites

OK, so for a production scenario, the program should be tested in that environment. Not on a VM with 5 disks attached to it.

Also the scope defined by op:

Quote

A menu will allow the user of this medium to choose his hard disk from the disks installed on the workstation. The following disks may be encountered: 120 GB, 200 GB, 450 GB, 1 TB and 2 TB.

Does not specifically state what combinations of disks may be present. If the VM example showing 6 disks is because there may be computers with a various amount of disks, not only do you have to find the supported disk sizes but also which Disk # that disk is. So if there is a system with a 120 GB, 200 GB and a 1 TB, you'd need to know which disk # matches to which disk. Is there a possibility of a system with 2 or more of the same disk sizes present? Is there the possibility that a system with a 200 GB and 1 TB disk has the 1 TB disk appear as Disk 0 and the 200 GB is disk 1? Is there the possibility that a system has a card reader that is detected by WinPE as disk 0 and the HDDs as Disk 1 and 2, or the card reader is Disk 1 and the HDDs are Disk 0 and 2?

Because in the example code, this is using absolute disk numbering. It is taking for granted that the disk numbers and disk sizes attached to those numbers are expected and makes no consideration for the possibility they are not.

Share this post


Link to post
Share on other sites
6 minutes ago, Tripredacus said:

OK, so for a production scenario, the program should be tested in that environment. Not on a VM with 5 disks attached to it.

Also the scope defined by op:

Does not specifically state what combinations of disks may be present. If the VM example showing 6 disks is because there may be computers with a various amount of disks, not only do you have to find the supported disk sizes but also which Disk # that disk is. So if there is a system with a 120 GB, 200 GB and a 1 TB, you'd need to know which disk # matches to which disk. Is there a possibility of a system with 2 or more of the same disk sizes present? Is there the possibility that a system with a 200 GB and 1 TB disk has the 1 TB disk appear as Disk 0 and the 200 GB is disk 1? Is there the possibility that a system has a card reader that is detected by WinPE as disk 0 and the HDDs as Disk 1 and 2, or the card reader is Disk 1 and the HDDs are Disk 0 and 2?

Because in the example code, this is using absolute disk numbering. It is taking for granted that the disk numbers and disk sizes attached to those numbers are expected and makes no consideration for the possibility they are not.

Sure, but the most basic scenario is that OP has to configure 100 (1000 or 10,000) similar machines that all come with one single disk BUT which size can be any of 120 GB, 200 GB, 450 GB, 1 TB and 2 TB. 

The main possible issue is IMHO - besides and before the case of more than one disk - that the user wrongly chooses the disk capacity.

Then, there is no check to whether diskpart sees the disk(s) correctly and/or with the "right" number

In cases like this - since (roughly) the capacity of an unpartitioned/unformatted disk can be easily found by diskpart - and adding your correct comment about the possible error about selecting the wrong disk I would go the other way round, first fire up diskpart looking for disks and specifically for disks unpartitioned/unformatted and then give the user only the option to partition/format that disk, automatically calculating the size of the second partition.

This said, if the scenario is similar to the above, It might be easier/better/faster/etc. to use a FFU image instead:
https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/deploy-windows-using-full-flash-update--ffu

https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/wim-vs-ffu-image-file-formats

Various tests and considerations on FFU use:
 http://reboot.pro/topic/22182-capture-and-apply-windows-full-flash-update-ffu-images/

BTW, whilst in the FFU case it is needed, even in the "normal" approach seen above, the diskpart extend command may be used, if size is omittd it will default to "all available size on the right", thus filling the disk to the brim without needing any calculation.

Of course it needs to be tested, but very likely partition/format/deploy FFU/extend partition will be faster than partition/format/deploy WIM or take the same time.
 

jaclaz

Share this post


Link to post
Share on other sites

On second thought, re-reading the two example diskpart scripts, they are identical, and have the same identical effect, so there is no need to choose a disk size at all. 

The first part always create a 2048 MB 1st, primary, active, partition with label "Systeme".

The second part always creates a 2nd, primary partition with label "Data" with the whole rest of the disk (i.e. variable in function of the size of the disk).

jaclaz
 

Share this post


Link to post
Share on other sites

I do not know if you could use this. Here is a HTA I cobble together. It a HTA that uses VBS script

to make it work.  I added a text document named DemoInstall.hta.txt rename to DemoInstall.hta to make it active. I will help on any scripting problems you might have with this.

<TITLE>&#160;&#171;&#160;Windows 10 Install &#160;&#187;&#160;</TITLE>
 <HTA:APPLICATION ID="Win10Install"
  APPLICATIONNAME="Win10_Install"
  Border="Thin"
  BORDERSTYLE ="Complex"
  Caption="Yes"
  Icon="%ProgramFiles%\Windows Media Player\wmplayer.exe"
  INNERBORDER ="No"
  MaximizeButton="No" 
  MinimizeButton="Yes" 
  Scroll="No" 
  SCROLLFLAT ="No"        
  SingleInstance="Yes"
  SysMenu="Yes"           
  WindowState="Normal"/> 
<STYLE type="text/css">
  Body
   {
    Padding-Top:1pt;Padding-Bottom:1pt;Margin:1pt;
    Font-Size:10.25pt;Font-Weight:Bold;
    Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;
    Color:Black;BackGround-Color:#EFE9E3;
    Text-Align:Center;Vertical-Align:Top;
   }
  .List1{
    Color:#0000A9;BackGround-Color:#C9C9C9;
    Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;
   }
  .List2{
    Color:#00A900;BackGround-Color:#E9E9E9;
    Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;
   }
</STYLE>
<SCRIPT Language="VBScript">
'-> Resize And Place In Approx Center Of Screen
 Dim Wth, Hht :Wth = int(287) :Hht = int(200)
  window.ResizeTo Wth, Hht
  MoveTo((Screen.Width / 2) - (Wth / 2)),((Screen.Height / 2) - (Hht / 2))
'-> Get The Path Of The HTA
'-> Script From https://gallery.technet.microsoft.com/scriptcenter/7a7f9937-0c6f-4f1e-a953-d29e47b2f5d5
 Dim F1, F2, ArrFn, Sd
  F1 = replace(Win10Install.commandLine,chr(34),"")  
  ArrFn=split(F1,"\")  
  F2 = ArrFn(ubound(ArrFn))  
  Sd=replace(F1,F2,"")
  Function Window_onLoad()
   BLAH.InnerHTML = "Hta Path : " & Sd
  End Function  
'-> Function For The Select 
  Function Install_Select()
   On Error Resume Next 
    Dim i
    For i = 0 To Select01.options.length 
     If Select01.options(i).selected Then
       alert(Select01.options(i).value)
      End if
    Next
  End Function
</SCRIPT>
<BODY>
<!-- Main Text Body -->
 <TABLE><TD Title='' Style='Font:8.25pt;Font-weight:bold;'>
  Select A Disk Size To Install To</TD></TABLE>
<!-- Select Body -->
 <TABLE><TD Title='Select a disk size you want to install Windows 10 to.'>
  <SELECT size='5' ID='Select01' name="Select01" OnChange='Install_Select()' 
   Style='Width:105;Text-Align:Center;Font-Size:8.05pt;Font-Weight:Bold;'>
   <OPTION Class='List1' value="Install Script For 120 GB">&#160;&#187;&#160;120&#160;GB</OPTION>
   <OPTION Class='List2' value="Install Script For 240 GB">&#160;&#187;&#160;240&#160;GB</OPTION> 
   <OPTION Class='List1' value="Install Script For 450 GB">&#160;&#187;&#160;450&#160;GB</OPTION> 
   <OPTION Class='List2' value="Install Script For One TB">&#160;&#187;&#160;One&#160;TB</OPTION>
   <OPTION Class='List1' value="Install Script For Two TB">&#160;&#187;&#160;Two&#160;TB</OPTION>  
  </Select>
 </TD></TABLE>
<!-- Lower Body Text -->
  <TABLE><TD Title='' Style='Font:8.25pt;Font-weight:bold;'>
  Some more space for instuctions on what the app does and other information
  </TD></TABLE>
  <TABLE><TD Title='' Style='Font:8.25pt;Font-weight:bold;'>
  <SPAN ID=BLAH></SPAN></TD></TABLE> 
</BODY>

 

Win10InstallApp.png

DemoInstall.hta.txt

Share this post


Link to post
Share on other sites

I have updated the original HTA.

1:\ Made it so it runs command and other resources from a folder called Resource, I also included a icon for the HTA.

In the resource folder there are 5 CMD files that are just examples to run upon selection

2:\ It self closes upon completion of command 

<TITLE>&#160;&#171;&#160;Windows 10 Install &#160;&#187;&#160;</TITLE>
 <HTA:APPLICATION ID="Win10Install"
  APPLICATIONNAME="Win10_Install"
  Border="Thin"
  BORDERSTYLE ="Complex"
  Caption="Yes"
  Icon="Resource/AppIcon01.ico"
  INNERBORDER ="No"
  MaximizeButton="No" 
  MinimizeButton="Yes" 
  Scroll="No" 
  SCROLLFLAT ="No"        
  SingleInstance="Yes"
  SysMenu="Yes"           
  WindowState="Normal"/> 
<STYLE type="text/css">
  Body
   {
    Padding-Top:1pt;Padding-Bottom:1pt;Margin:1pt;
    Font-Size:10.25pt;Font-Weight:Bold;
    Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;
    Color:Black;BackGround-Color:#EFE9E3;
    Text-Align:Center;Vertical-Align:Top;
   }
  .List1{
    Color:#0000A9;BackGround-Color:#C9C9C9;
    Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;
   }
  .List2{
    Color:#00A900;BackGround-Color:#E9E9E9;
    Font-Family:Segoe Ui, Arial,Tahoma,Comic Sans MS;
   }
</STYLE>
<SCRIPT Language="VBScript">
'-> Script Run Time Objects 
 Dim Act :Set Act = CreateObject("Wscript.Shell")
 Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
'-> Resize And Place In Approx Center Of Screen
 Dim Wth, Hht :Wth = int(319) :Hht = int(175)
  window.ResizeTo Wth, Hht
  MoveTo((Screen.Width / 2) - (Wth / 2)),((Screen.Height / 2) - (Hht / 2))
'-> Get The Path Of The HTA
'-> Script From https://gallery.technet.microsoft.com/scriptcenter/7a7f9937-0c6f-4f1e-a953-d29e47b2f5d5
 Dim F1, F2, F3, ArrFn, Sd
  F1 = replace(Win10Install.commandLine,chr(34),"")  
  ArrFn = split(F1,"\")  
  F2 = ArrFn(ubound(ArrFn))  
  Sd = Replace(F1,F2,"")
  F3 = "<font Style='Color:1D6937';>"
  Function Window_onLoad()
   BLAH.InnerHTML = Replace(F3,"1D6937", "0B7DAD") & "Hta Path : " & Sd & "</FONT>"
   'Win10Install.Icon = Sd & "Resource\AppIcon01.ico"
  End Function  
'-> Function For The Select 
  Function Install_Select()
    Dim i
    For i = 0 To Select01.options.length 
     If Select01.options(i).selected Then
      If Not Select01.options(i).value = "DiskSelect" Then
       BLAH.InnerHTML = F3 & "Processing Selection</FONT>"
'-> Passes varible To The Work Function
       Work(Select01.options(i).value)
       Exit For
      End If 
     End if      
    Next
  End Function
'-> Run Selected Cmd Function And Reports Missing Files
  Function Work(f)
   If Fso.FileExists(Sd & f) Then
    Act.Run(Sd & f),1,true
    window.close()
   Else
    BLAH.InnerHTML = Replace(F3,"1D6937", "ED0647") & "Missing Install Cmd Error"
    Act.Popup "Missing This File :" & f & vbCrLf &_
    "Contact The System Administator" ,7, "Missing Install Command",4128    
    window.close()
   End If   
  End Function 
</SCRIPT>
<BODY>
<!-- Main Text Body -->
 <TABLE><TD Title='' Style='Font:9.25pt;Font-weight:bold;'>
  Windows 10 Disk Selection</TD></TABLE>
<!-- Select Body -->
 <TABLE><TD Title='Select a disk size you want to install Windows 10 to.'>
  <SELECT size='1' ID='Select01' name="Select01" OnChange='Install_Select()' 
   Style='Width:113;Text-Align:Center;Font-Size:8.05pt;Font-Weight:Bold;'>
   <OPTION Class='List2' value="DiskSelect">&#160;Select A Disk&#160;</OPTION> 
   <OPTION Class='List1' value="Resource\Win10_Install_01.cmd">&#160;&#187;&#160;120&#160;GB</OPTION>
   <OPTION Class='List2' value="Resource\Win10_Install_02.cmd">&#160;&#187;&#160;240&#160;GB</OPTION> 
   <OPTION Class='List1' value="Resource\Win10_Install_03.cmd">&#160;&#187;&#160;450&#160;GB</OPTION> 
   <OPTION Class='List2' value="Resource\Win10_Install_04.cmd">&#160;&#187;&#160;001&#160;TB</OPTION>
   <OPTION Class='List1' value="Resource\Win10_Install_05.cmd">&#160;&#187;&#160;002&#160;TB</OPTION>  
  </Select>
<!-- User Message Body -->
  <TD Style='Font:8.25pt;Font-weight:bold;' >
  Select the disk size that you want to use to install Windows 10 to.
  This application self closes upon completion of the command.</TD>
 </TD></TABLE>
  <TABLE><TD Title='' Style='Font:8.25pt;Font-weight:bold;Padding-Top:3pt;'>
  <SPAN ID=BLAH></SPAN></TD></TABLE> 
</BODY>

DemoHtaInstall.zip

Win10InstallApp2.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...