Win10+ Setup Disk (Works with UEFI Secure Boot / BIOS / Install.wim over 4 GB)

Discussion in 'MDL Projects and Applications' started by rpo, Mar 18, 2019.

  1. uffbros

    uffbros MDL Senior Member

    Aug 9, 2010
    455
    59
    10
    Can you explain how your doing it? Do you put this script in same folder as extracted .iso of Windows? Or do you put it in same folder as the .iso? What are the steps? Does the files have to be on C drive or can it be run from anywhere?
     
  2. Jack Schitt

    Jack Schitt MDL Novice

    Nov 26, 2010
    35
    20
    0
    #42 Jack Schitt, Jun 9, 2019
    Last edited: Jun 9, 2019
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,606
    2,676
    60
    It should run from anywhere.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,606
    2,676
    60
    Try running this Powershell script mentioned by @Jack Schitt first.

    Code:
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. uffbros

    uffbros MDL Senior Member

    Aug 9, 2010
    455
    59
    10
    It doesn't thou....Jack s**tt's post is way over my head..I just want the freekin thing to work....Thanks anyways..I can live without it.
     
  6. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,606
    2,676
    60
    #46 freddie-o, Jun 9, 2019
    Last edited: Jul 30, 2019
    If Windows installation disk [script] does NOT run:

    By default, Windows clients restricts the execution of powershell scripts to prevent the execution of malicious scripts.
    In case there is a problem running the Windows Installation Disk [script], run this Powershell command first
    Code:
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
    
    to remove the restriction and allow you to execute the script. (The Windows Installation Disk script first creates "script.ps1" in your Temp folder and it is this powershell script that creates the installation disk.)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. Jack Schitt

    Jack Schitt MDL Novice

    Nov 26, 2010
    35
    20
    0
    #47 Jack Schitt, Jun 9, 2019
    Last edited: Jun 11, 2019
    Unless you fix this you will live without any PowerShell Scripting.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. uffbros

    uffbros MDL Senior Member

    Aug 9, 2010
    455
    59
    10
    #48 uffbros, Jun 10, 2019
    Last edited: Jun 11, 2019
    Thanks all..I was able to finally figure it out and got my USB Boot Install done. Last question. Say next week the next build of Win 10 1903 comes out. What would I have to do now? Do I just need to extract the iso to the USB drive like I did before using Rufus or do I need to start this script all over again to do this? If in fact that is all I need to do....would I leave the Fat32 drive that is labeled Boot alone and only extract the new build of 1903 to the Install labeled drive?
     
  9. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,606
    2,676
    60
    Run the Windows boot disk script again.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,606
    2,676
    60
    I'm working on modifying the script so as to have just one GUI to create the Windows installation disk. So far, with my very limited knowledge of scripting, this is as far as I got.

    Code:
    @echo off
    (
    echo #
    echo #    This script must be executed with admin privilege
    echo #
    echo #    Test Administrator privileges
    echo If ^(-NOT ^([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent^(^)^).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"^)^)
    echo {
    echo #    Restart the script to get Administrator privileges and exit
    echo     Start-Process 'powershell.exe' -Verb runAs -ArgumentList ^("-NoLogo -WindowStyle Normal -noprofile -file " + """" + $PSCommandPath + """"^)
    echo     exit
    echo }
    echo #    We have Administrator privileges
    echo #
    echo [console]::ForegroundColor = "Yellow"
    echo [console]::BackgroundColor = "blue"
    echo #
    echo Add-Type -AssemblyName System.Windows.Forms # Load the class System.Windows.Forms
    echo # Filebrowser dialog
    echo $FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
    echo    Multiselect = $false # One file can be chosen
    echo     Filter = 'ISO images ^(*.iso^)^|*.iso' # Select iso files
    echo }
    echo #
    
    echo clear-host
    echo #    Select the USB disk
    echo $USBDiskForm=New-Object System.Windows.Forms.Form # Create the screen form ^(window^)
    echo # $USBDiskForm ^|gm;pause
    echo # Set the title and size of the window:
    echo $USBDiskForm.Text='Windows installation disk^'
    echo $USBDiskForm.Width=490 ; $USBDiskForm.Height=210
    echo $USBDiskForm.AutoSize=$true # AutoSize property to make the form automatically stretch, if the elements on the form are out of bounds
    echo # Create a drop-down list and fill it
    echo $USB=$Null
    echo $USBDisks=@^(^) # array with USB disk number
    echo $Disks=Get-Disk ^| Where-Object {^($_.BusType -eq "USB"^) -and ^($_.OperationalStatus -eq "Online"^)}
    
    echo $USBDiskList=New-Object System.Windows.Forms.ComboBox
    echo # $USBDiskList^|gm
    echo $USBDiskList.Width=450
    echo Foreach ^($USBDisk in $Disks^) {
    echo     $FriendlyName=^($USBDisk.FriendlyName^).PadRight^(30," "^).substring^(0,30^)   
    echo     $Partitions = Get-Partition ^| Where-Object { $_.DiskNumber -eq $USBDisk.DiskNumber}
    echo     If ^($Partitions^) {
    echo         Foreach ^($Partition in $Partitions^) {
    echo         $Volumes=get-volume ^| Where-Object {$Partition.AccessPaths -contains  $_.path }
    echo         Foreach ^($Volume in $Volumes^) {
    echo             $USBDisks+=$USBDisk.DiskNumber
    echo             $USBDiskList.Items.Add^(^(" {0,-30}| {1,1}:| {2,-30}| {3:n2} GB" -f $FriendlyName, ^($Partition.DriveLetter^), $Volume.FileSystemLabel.PadRight^(30," "^).substring^(0,30^), ^($Partition.Size/1GB^)^)^)^|out-null
    echo             }       
    echo         }
    echo     } Else {
    echo         $USBDisks+=$USBDisk.DiskNumber
    echo         $USBDiskList.Items.Add^(^(" {0,-30}| {1,1}| {2,-30}| {3:n2} GB" -f $FriendlyName, " ", " ",^($USBDisk.Size/1GB^)^)^)^|out-null
    echo     }
    echo }
    
    echo $SelectUSBDisk=New-Object System.Windows.Forms.Label # Put the SelectUSBDisk label on the form
    echo $SelectUSBDisk.Location=New-Object System.Drawing.Size^(10,20^)
    echo $SelectUSBDisk.Text="Select USB disk";$SelectUSBDisk.Font='Segoe UI,10'
    echo $SelectUSBDisk.width=200;$SelectUSBDisk.height=20;
    echo $USBDiskForm.Controls.Add^($SelectUSBDisk^)
    
    echo $USBDiskList.DropDownStyle=[System.Windows.Forms.ComboBoxStyle]::DropDownList;
    echo $USBDiskList.Location=New-Object System.Drawing.Point^(10,40^)
    echo $USBDiskList.width=450;$USBDiskList.height=20
    echo $USBDiskList.backColor="blue" ; $USBDiskList.ForeColor="White"
    echo $USBDiskList.Font='Segoe UI,10'
    echo $USBDiskForm.Controls.Add^($USBDiskList^)
    
    echo $SelectISOButton=New-Object System.Windows.Forms.Button # Put the SelectISO button on the form
    echo $SelectISOButton.Location=New-Object System.Drawing.Size^(10,100^)
    echo $SelectISOButton.Text="Select ISO";$SelectISOButton.Font='Segoe UI,10'
    echo $SelectISOButton.width=80;$SelectISOButton.height=60;
    echo $USBDiskForm.Controls.Add^($SelectISOButton^)
    echo $SelectISOButton.Add_Click^({$global:SelectISO=$true;$USBDiskForm.close^(^)}^)
    echo $USBDiskForm.Controls.Add^($SelectISO^)
    
    echo $CreateUSBDiskButton=New-Object System.Windows.Forms.Button # Put the SelectISO button on the form
    echo $CreateUSBDiskButton.Location=New-Object System.Drawing.Size^(350,130^)
    echo $CreateUSBDiskButton.Text="Create USB Disk";$CreateUSBDiskButton.Font='Segoe UI,10'
    echo $CreateUSBDiskButton.width=110;$CreateUSBDiskButton.height=30;
    echo $USBDiskForm.Controls.Add^($CreateUSBDiskButton^)
    echo $CreateUSBDiskButton.Add_Click^({$global:SelectISO=$true;$USBDiskForm.close^(^)}^)
    echo $USBDiskForm.Controls.Add^($SelectISO^)
    
    echo $CancelButton=New-Object System.Windows.Forms.Button # Put the Cancel button on the form
    echo $CancelButton.Location=New-Object System.Drawing.Size^(260,130^)
    echo $CancelButton.Size=New-Object System.Drawing.Size^(120,20^)
    echo $CancelButton.Text="Cancel";$CancelButton.Font='Segoe UI,10'
    echo $CancelButton.width=60;$CancelButton.height=30;
    echo $USBDiskForm.Controls.Add^($CancelButton^)
    echo $CancelButton.Add_Click^({$global:SelectISO=$False;$USBDiskForm.close^(^)}^)
    echo [void]$USBDiskForm.ShowDialog^(^) # Display the form on the screen
    echo if ^(!$global:SelectISO^){$wshell.Popup^("Operation cancelled",0,"Error"^) ^| Out-Null;exit}
    echo #
    echo [void]$FileBrowser.ShowDialog^(^)
    echo #
    echo $ImagePath = $FileBrowser.FileName;
    echo $ISO=":"
    echo If^($FileBrowser.FileNames -like "*\*"^) {
    echo #  Check if iso already mounted
    echo     $ISO = ^(Get-DiskImage -ImagePath $ImagePath ^| Get-Volume^).DriveLetter
    echo #    Mount iso
    echo     IF ^(!$ISO^) {Mount-DiskImage -ImagePath $ImagePath -StorageType ISO ^|out-null
    echo     $ISO = ^(Get-DiskImage -ImagePath $ImagePath ^| Get-Volume^).DriveLetter}
    echo     $ISO=$ISO+":"
    echo }
    echo if ^($ISO -eq ":"^) {$wshell.Popup^("No ISO image mounted or operation cancelled",0,"Error"^) ^| Out-Null;exit}
    echo $USB=$USBDisks[$USBDiskList.SelectedIndex]
    echo #    Clear the USB stick
    echo Clear-Disk $usb -RemoveData -RemoveOEM -Confirm:$false
    echo Stop-Service ShellHWDetection
    echo #    Create the fat32 boot partition
    echo $usbfat32=^(New-Partition -DiskNumber $usb -Size 1GB -AssignDriveLetter -IsActive ^| Format-Volume -FileSystem FAT32 -NewFileSystemLabel "BOOT"^).DriveLetter + ":"
    echo #    Create the ntfs intall partition
    echo $usbntfs=^(New-Partition -DiskNumber $usb -UseMaximumSize -AssignDriveLetter ^| Format-Volume -FileSystem NTFS -NewFileSystemLabel "INSTALL"^).DriveLetter + ":"
    echo Start-Service ShellHWDetection
    echo # Read-Host "Eject the iso if it is mounted. When ready press Enter"
    echo # $Volumes = ^(Get-Volume^).Where^({$_.DriveLetter}^).DriveLetter
    echo # Read-Host "Mount the iso. When ready press Enter"
    echo # $ISO = ^(Compare-Object -ReferenceObject $Volumes -DifferenceObject ^(Get-Volume^).Where^({$_.DriveLetter}^).DriveLetter^).InputObject
    echo # $ISO = ^(get-volume^| Where-Object {^($_.DriveType -eq "CD-ROM"^) -and ^($_.filesystemlabel -ne ""^) -and ^($_.OperationalStatus -eq "OK"^)} ^|Out-GridView -Title 'Select Cd-Rom image' -OutputMode Single^).DriveLetter + ":"
    echo # Copy-Item -Path $ISO\* -Destination "$($usbntfs)" -Recurse -Verbose
    echo # Copy-Item -Path $ISO"\bootmgr" -Destination $usbfat32"\" -Verbose
    echo # Copy-Item -Path $ISO"\bootmgr.efi" -Destination $usbfat32"\" -Verbose
    echo # Copy-Item -Path $ISO"\boot" -Destination $usbfat32"\boot" -Recurse  -Verbose
    echo # Copy-Item -Path $ISO"\efi" -Destination $usbfat32"\efi" -Recurse  -Verbose
    echo # new-item $usbfat32"\sources" -itemType Directory
    echo # Copy-Item -Path $ISO"\sources\boot.wim" -Destination $usbfat32"\sources\boot.wim"  -Verbose
    echo robocopy $iso $usbntfs /e
    echo robocopy $iso"\" $usbfat32"\" bootmgr bootmgr.efi
    echo robocopy $iso"\boot" $usbfat32"\boot" /e
    echo robocopy $iso"\efi" $usbfat32"\efi" /e
    echo robocopy $iso"\sources" $usbfat32"\sources" boot.wim
    echo # Eject the mounted iso image
    echo # ^(New-Object -ComObject Shell.Application^).Namespace^(17^).ParseName^($ISO^).InvokeVerb^("Eject"^)
    echo DisMount-DiskImage -ImagePath $ImagePath ^|out-null
    echo Remove-item ^($env:TEMP + "\script.ps1"^)     
    )>"%temp%\script.ps1"
    powershell "%temp%\script.ps1" -ExecutionPolicy Bypass -WindowStyle Normal
    
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,505
    1,528
    60
    Please replace script line 25 by
    Code:
    echo $wshell=New-Object -ComObject Wscript.Shell
     
  12. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,606
    2,676
    60
    Line 25 is a blank.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. rpo

    rpo MDL Expert

    Jan 3, 2010
    1,505
    1,528
    60
    If you prefer, add after script line 25 or 26 or ...
    Code:
    echo $wshell=New-Object -ComObject Wscript.Shell
    since $wshell is referenced but but defined.
     
  14. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,606
    2,676
    60
    The script in the OP?

    Code:
    echo $wshell=New-Object -ComObject Wscript.Shell
    is already in line 26.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  15. vigipirate

    vigipirate MDL Senior Member

    Feb 24, 2011
    403
    100
    10
    thank script verry works usb simply uefi bios
     
  16. vigipirate

    vigipirate MDL Senior Member

    Feb 24, 2011
    403
    100
    10
    Restore FullControl to Administrators and set owner to TrustedInstaller
    Impossible de convertir la valeur «SERVICE» en type «System.Security.Principal.SecurityIdentifier». Erreur: «La valeur
    n'était pas valide.
    Nom du paramètre : sddlForm »
    Au caractère Ligne:7 : 26
    + ... le 2;$i++){ $usr[$i]=[System.Security.Principal.SecurityIdentifier]$s ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument : :)) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastConstructorException

    Impossible de convertir l'argument «identity» (valeur «0») de «SetOwner» en type «
    System.Security.Principal.IdentityReference»: «Impossible de convertir la valeur «0» du type «System.Int32» en type «
    System.Security.Principal.IdentityReference».»
    Au caractère Ligne:14 : 34
    + $reg.SetAccessControl($acl); } $sec[0].SetOwner($usr[0]); $reg.SetA ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: :)) [], MethodException
    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
     
  17. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,606
    2,676
    60
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. AveYo

    AveYo MDL Expert

    Feb 10, 2009
    1,836
    5,737
    60
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. freddie-o

    freddie-o MDL Expert

    Jul 29, 2009
    1,606
    2,676
    60
    #60 freddie-o, Jul 31, 2019
    Last edited: Jul 31, 2019
    So I replaced

    Code:
    set "args="%~f0" %*" & call set "args=%%args:"=\"%%"
    fsutil dirty query %systemdrive%>nul||(if "%?%" neq "y" powershell -c "start cmd -ArgumentList '/c set ?=y&call %args%' -verb runas" &exit)
    with

    Code:
    set "args="%~f0" %*" & call set "args=%%args:"=\""%%"
    reg query HKU\S-1-5-19>nul||(if "%?%" neq "y" powershell -c "start cmd -ArgumentList '/c set ?=y&call %args%' -verb runas" &exit)
    and this window popped up

    Code:
    ERROR: Access is denied.
    before the UAC window.
    But it worked after allowing the script to run.

    Code:
    reg query HKU\S-1-5-19>nul||(if "%?%" neq "y" powershell -c "start cmd -ArgumentList '/c set ?=y&call %args%' -verb runas" &exit)
    caused the ERROR window
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...