App Development Help

Page 1 of 4 123 ... LastLast

  1. Posts : 4,144
    Windows 3.1 to Windows 11
       #1

    App Development Help


    @Superfly
    I am looking to tap into your coding ability...
    I have this Batch File that exports the Hosts Drivers and then integrates them into Booted WinPE
    The problems are
    if more then 1 host OS
    if version of host OS is different then PE version (Win8.1 - Win10)
    if Arch of OS is different then PE Arch (x86 - x64)

    What I would like is a single exe - GUI - like showkey...
    to compare WinPE OS and Arch with any Available Host OS
    If a Matching OS and Arch are found then > export and integrate drivers

    currently the export is to Y (our WinPE Media Drive) but we usually run 1024 WinPECache
    so windows\%temp% is an option as batch delete Driver folder after integration

    Code:
    @ECHO OFF
    CLS
    REM Set a temporary location outside of memory as your destination (i.e. usb)
    SET destination=Y:\HostDrivers
    IF EXIST "%destination%" RMDIR "%destination%" /S /Q
    MD "%destination%"
    CHOICE /C YN /M "Would you like to load drivers from the host (if present) "
    IF %ERRORLEVEL%==1 GOTO SCAN
    IF %ERRORLEVEL%==2 GOTO ABORT
    :ABORT
    EXIT
    :SCAN
    For %%I in (C D E F G H I J K L M N O P Q R S T U V W Y Z A B) do (dir %%I:\ 1>nul 2>nul && if /i exist %%I:\Windows set image=%%I:\)
    :EXPORT
    DISM /image:%image% /Export-Driver /destination:"%destination%"
    :LOAD
    CD /D "%destination%"
    FOR /F "delims=" %%i in ('dir /b /s /a-d "*.inf"') do (
    %WinDir%\System32\pnputil.exe /add-driver "%%i" /subdirs
    )
    DEVCON /RESCAN
    DEVCON RESTART *
    RMDIR "%destination%" /S /Q
    EXIT
      My Computer


  2. Posts : 3,453
       #2

    See if this helps

    Code:
    if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
    
    $WinPEDrive = "X" #Change to C if testing outside PE
    
    $IsX86 = $false
    
    $WinPEProduct = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | select -ExpandProperty ProductName
    
    $WinPEArch = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | select -ExpandProperty BuildLabEx
    
    if ($WinPEArch.Split(".") -contains 'x86fre') {$IsX86 = $true}
    
    $Drives = Get-PSDrive -PSProvider FileSystem | Select-Object Name, Root | Where-Object {$_.Name -notcontains $WinPEDrive}
    
    foreach ($item in $Drives){
    $path = Join-Path($item.Root) -ChildPath "Windows\System32\config\SOFTWARE"
    
    if (Test-Path($path) ){
    Reg.exe load 'HKLM\TempHive' $path
    $product_name = Get-ItemProperty -Path "HKLM:\TempHive\Microsoft\Windows NT\CurrentVersion" | Select-Object -ExpandProperty ProductName
    $Arch_name = Get-ItemProperty -Path "HKLM:\TempHive\Microsoft\Windows NT\CurrentVersion" | Select-Object -ExpandProperty BuildLabEx
    Reg.exe unload 'HKLM\TempHive'
    
    #If a Matching OS and Arch are found then export and integrate drivers
    if (($product_name -eq $WinPEProduct) -and ($IsX86 -eq $Arch_name.Split(".")[1])){
    Write-Host "Export drivers from " $path.Replace("config\SOFTWARE", "Drivers")
    } 
    else {   
    Write-Host "No drivers to export "
        }
      }
    }
    Read-Host
      My Computer


  3. Posts : 4,144
    Windows 3.1 to Windows 11
    Thread Starter
       #3

    Thank You For The Time Spent Doing This !!
    Looks real good, But man, as much as I would not like to look really stupid...
    I am Totally Lost as to what to do with it...
    How to run a TEST and what system or program file requirements
      My Computer


  4. Posts : 4,144
    Windows 3.1 to Windows 11
    Thread Starter
       #4

    Honestly, I am 100% relying on you to create the App for the intended purpose...
    Dism and Devcon are in System32

    I can test with the masses and provide feedback..
      My Computer


  5. Posts : 4,144
    Windows 3.1 to Windows 11
    Thread Starter
       #5

    Ran it as test.ps1 in WinPE
    it questioned security policy - answered A yes to all
    powershell closed

    Note: we run powershell in PE unrestricted
    and we usually login as "System" although we can run as "Administrator"
      My Computer


  6. Posts : 3,453
       #6

    OIC. I wasn't sure I got the instruction rght so I just wanted a test. Note testing on installed "C"

    Anyway the above one has errors so I changed it

    Code:
    if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
    
    $WinPEDrive = "C" #Change to C if testing outside PE
    
    $IsX86 = $false
    
    $WinPEProduct = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | select -ExpandProperty ProductName
    
    $WinPEArch = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | select -ExpandProperty BuildLabEx
    
    if ($WinPEArch.Split(".") -contains 'x86fre') {$IsX86 = $true}
    
    $Drives = Get-PSDrive -PSProvider FileSystem | Select-Object Name, Root | Where-Object {$_.Name -notcontains $WinPEDrive}
    
    foreach ($item in $Drives){
    $path = Join-Path($item.Root) -ChildPath "Windows\System32\config\SOFTWARE"
    
    if (Test-Path($path) ){
    Reg.exe load 'HKLM\TempHive' $path | Out-Null
    $product_name = Get-ItemProperty -Path "HKLM:\TempHive\Microsoft\Windows NT\CurrentVersion" | Select-Object -ExpandProperty ProductName
    $Arch_name = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | select -ExpandProperty BuildLabEx
    Reg.exe unload 'HKLM\TempHive'| Out-Null
    
    if ($Arch_name.Split(".") -contains 'x86fre') {$newArch = $true} else {$newArch = $false}
    
    #If a Matching OS and Arch are found then export and integrate drivers
    
    if ($product_name -eq $WinPEProduct -and $IsX86 -eq $newArch)
    {
     Write-Host "Export drivers from " $path.Replace("config\SOFTWARE", "Drivers")
     } 
     else {   
     Write-Host "No drivers to export "
        }
     }
    }
    Write-Host "Done"
    Read-Host
    Output:

    Export drivers from D:\Windows\System32\Drivers
    Export drivers from G:\Windows\System32\Drivers
    Done
    The "Export drivers from" bit is obviously a placeholder for where we need to put the actual Export command

    The self-elevation can be dropped for PE - I just added that for testing as it's needed for loading registry hives.
    I will look into it some more later.
      My Computer


  7. Posts : 4,144
    Windows 3.1 to Windows 11
    Thread Starter
       #7

    Very Good progress....
    Booted into Win10PE v17763 x64
    On first run got Access Denied
    and then 5 - No Drivers to export messages... Done
    on second run just the 5 messages.. Done

    I have 5 Installed OS's on Host - so that seems to be making the proper amount of checks...
    4 of those OS's are Windows 10
    2 of those 4 are x64
    and I do have a 17763 x64 OS on Host

    So it seems to not be matching OS Edition and Arch - in WinPE

    Not sure Build Version will matter, just Windows Edition 8-8.1-10

    Is it possible to LIST the found OS Editions with corresponding Arch ??
    Maybe allow end user to select from list which OS to export drivers from...

    Although Best Match between WinPE and Host OS is the Goal - Not a requirement..

    Edit 1:
    Running on Host Win8.1
    4 Message.. Done..
    As no other Match Anyway..

    Edit 2:
    Running on Host Win10
    change execution policy question - a
    found and listed my 3 other win10 OS

    So OS edition matching seems to work (on Host) but really only 1 other OS matches Arch
    Last edited by Kyhi; 01 Jul 2019 at 07:15.
      My Computer


  8. Posts : 3,453
       #8

    Kyhi said:
    So OS edition matching seems to work (on Host) but really only 1 other OS matches Arch
    Typo or more like "copy-paste-o" (see bolded below) ... LOL

    Code:
    if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
    
    $WinPEDrive = 'C' #Change to C if testing outside PE
    
    $WinPEProduct = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select -ExpandProperty ProductName
    
    $WinPEArch = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | Select -ExpandProperty BuildLabEx
    
    if ($WinPEArch.Split('.') -contains 'x86fre') {$IsX86 = $true} else {$IsX86 = $false}
    
    $Drives = Get-PSDrive -PSProvider FileSystem | Select-Object Name, Root | Where-Object {$_.Name -notcontains $WinPEDrive}
    
    foreach ($item in $Drives){
    $path = Join-Path($item.Root) -ChildPath "Windows\System32\config\SOFTWARE"
    
    if (Test-Path($path))
    {
    Reg.exe load 'HKLM\TempHive' $path | Out-Null
    $product_name = Get-ItemProperty -Path "HKLM:\TempHive\Microsoft\Windows NT\CurrentVersion" | Select -ExpandProperty ProductName
    $Arch_name = Get-ItemProperty -Path 'HKLM:\TempHive\Microsoft\Windows NT\CurrentVersion' | Select -ExpandProperty BuildLabEx
    Reg.exe unload 'HKLM\TempHive' | Out-Null
    
    if ($Arch_name.Split(".") -contains 'x86fre') {$ArchX86 = $true} else {$ArchX86 = $false}
    
    Write-Host $product_name  $WinPEProduct  $IsX86  $ArchX86
    #If a Matching OS and Arch are found then export and integrate drivers
    
    if ($product_name -eq $WinPEProduct -and $IsX86 -eq $ArchX86) #Assuming we don't have ARM, $IsX86(false) = x64
    {
     Write-Host "Export drivers from " $path.Replace("config\SOFTWARE", "Drivers")
     } 
     else {   
     Write-Host "No drivers to export "
        }
      }
    }
    Write-Host "Done"
    Read-Host
    Last edited by Superfly; 01 Jul 2019 at 12:43. Reason: Removed testing w/ windows.old
      My Computer


  9. Posts : 4,144
    Windows 3.1 to Windows 11
    Thread Starter
       #9

    From Win8.1 Host - No Matches -
    App Development Help-image65.jpg

    From Win10 Host - Found 1 Match -
    App Development Help-image66.jpg

    From WinPE - Edition appears as Enterprise even if using Pro Index -
    so guess we would not find edition match in PE
    I my case it should find 2 matching OS and Arch
    App Development Help-screenshot00001.jpg
      My Computer


  10. Posts : 4,144
    Windows 3.1 to Windows 11
    Thread Starter
       #10

    And Thank You !!!!
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 18:24.
Find Us




Windows 10 Forums