O/S detection from Windows PE
#1
Posted 27 April 2012 - 07:51 PM
Hi guys,
First of all I'm super happy I found this forum, it looks amazing.
I created a recovery DVD that boots to Windows PE and automatically DiskPart the needed partitions and then installs the syspreped O/S found in a WIM image.
The recovery disk works great, everything happens without human interaction.
I want to add another feature to the recovery DVD where it scans the hard-drive and checks if an O/S is already installed before wiping and re-partitioning the hard-drive.. I will then add an optional action which I already know how to do, however I don't know how to make Windows PE scan and detect another O/S..
Anyone here knows if it's possible to do?
Many thanks,
Bil0
#2
Posted 27 April 2012 - 09:41 PM
#3
Posted 28 April 2012 - 09:19 AM
- NTLDR (for Windows 2000/XP/2003)
- BOOTMGR (for Windows Vista/2008/7/8)
This only covers searching for the above operating systems. Linux and other operating systems will use other boot files. These file based searches will obviously depend on the partition file systems being accessible from WinPE.
Good luck.
Regards,
Misty
#4
Posted 28 April 2012 - 09:32 AM
There is no need for the Windows folder to actually be called Windows and the boot loader can be installed to a different drive, than the Windows folder.
Imo, the original posters idea, to check for an installed OS, is already flawed.
I know, that i would be even more upset, if i would wipe by accident my data partition, than 'just' my system partition.
So if a check is to be done, then best, if the partition is empty or not
#5
Posted 28 April 2012 - 09:37 AM
#6
Posted 30 April 2012 - 02:23 PM
In my situation, It's always the same O/S (Windows Embedded 7) installed in the same partition (20-GB C-drive). So all answers are correct, I could look if the folder exists, if the boot files exist, even if the partition has any files in it, all those solutions would solve my problem.
However, I don't know HOW to do it, what's the best way? Is there a tool or command I can run from WinPE? Maybe a PowerShell script? Can anyone help me in the "How" department?
Many many thanks!
#7
Posted 30 April 2012 - 02:42 PM
if exist c:windowsnul echo THERE IS A WINDOWS FOLDER ON THE C: DRIVE!
if exist c:windowsnul pause
The rest of the code would depend on what actions you want to happen or what Q's you want the user to be asked, etc.
You can make the detectos.cmd run automatically by editing the startnet.cmd file in the windowssystem32 folder inside the boot.wim.
#8
Posted 30 April 2012 - 03:20 PM
... remembering that checking for nul (though working in - say - 99% of cases) is not 100% reliable:if exist c:windowsnul
http://www.msfn.org/...-functionality/
http://www.msfn.org/...end/page__st__9
http://www.msfn.org/...ch-programming/
Wonko
#9
Posted 30 April 2012 - 04:23 PM
Hi guys, thank you for the replies!
In my situation, It's always the same O/S (Windows Embedded 7) installed in the same partition (20-GB C-drive).
Even if the Windows folder is not named Windows, this path should always exist for any Win7 OS:
C:BootBCD
Note that BCD is a file and not a folder. Alternatively, this should also be present:
C:Booten-USbootmgr.exe.mui
#10
Posted 01 May 2012 - 05:11 AM
\WINDOWS\system32\ntdll.dll
Windows XP Sp3 = 5.1.2600.6055
You can do it with AutoIt / vb6 / c++ / etc...
#11
Posted 01 May 2012 - 06:45 PM
Why not make a simple shell script file - e.g. detectos.cmd
if exist c:windowsnul echo THERE IS A WINDOWS FOLDER ON THE C: DRIVE!
if exist c:windowsnul pause
The rest of the code would depend on what actions you want to happen or what Q's you want the user to be asked, etc.
You can make the detectos.cmd run automatically by editing the startnet.cmd file in the windowssystem32 folder inside the boot.wim.
Thank you, that's exactly the type of information I was looking for..
My PowerShell skills are close to ZERO.. but this is a good start for me... I don't think I will find the exact information I am looking for, I will eventually have to program it myself.
Thanks again
#12
Posted 03 May 2012 - 05:52 AM
Thank you, that's exactly the type of information I was looking for..Only need BatchScript
My PowerShell skills are close to ZERO.. but this is a good start for me... I don't think I will find the exact information I am looking for, I will eventually have to program it myself.
Thanks again
* No work with 2 OS installed on the machine) Only for example
Open notepad, copy and paste this code and save as AutoSelect.cmd . After Double Click in the saved file...
@ECHO OFF :_main CALL :_Autoselect ECHO. ECHO. Windows path: %_winpath% ECHO. pause. EXIT :_Autoselect FOR %%i IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO ( IF EXIST %%i:nul ( IF EXIST %%i:WINDOWS* ( SET _winpath= SET _winpath=%%i:WINDOWS GOTO :EOF ) ) )----------------------
*** Lines beginning with "rem" are comments. I use Notepad + + to highlight the language syntax (with different colors)
* Manual Select with verification You need this...
Open notepad, copy and paste this code and save as ManualSelect.cmd . After Double Click in the saved file...
@ECHO OFF
SET _winpath=
SET _winpath=Z:WINDOWS
:_main
Call :_changeDrive
ECHO.
ECHO. Windows path: %_winpath%
ECHO.
pause.
EXIT
:_changeDrive
@ECHO OFF
SET _winpath=
SET _winpath=Z:WINDOWS
:_main
Call :_changeDrive
ECHO.
ECHO. Windows path: %_winpath%
ECHO.
pause.
EXIT
:_changeDrive
CLS
SET _ok=
echo.
echo. Selected Windows Path [ %_winpath% ]
echo.
echo.
echo. Select Drive ( Example: C )
echo.
echo.
echo.
SET /p _ok= * Type drive letter:
rem * Verify Format required
rem +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rem * You dont type anything
IF "%_ok%" == "" (
SET _winpath=
SET _winpath=* Your bad response "%_ok%"
GOTO :_changeDrive
)
rem * Check all the possibilities ( sensitive verification for chars )
FOR %%i IN (a A b B c C d D e E f F g G h H i I j J k K l L m M n N o O p P q Q r R s S t T u U v V w W x X y Y z Z) DO (
IF "%%i" == "%_ok%" (
rem Typed char exactly equal to current letter in loop
rem * Try path exist...
IF EXIST %_ok%:WINDOWS* (
SET _winpath=
SET _winpath=%_ok%:WINDOWS
CLS
GOTO :EOF
) ELSE (
rem * dont exist path
SET _winpath=
SET _winpath=%_ok%:WINDOWS (Dont exist...)
GOTO :_changeDrive
)
)
)
rem * Response dont match
SET _winpath=
SET _winpath=* invalid format "%_ok%"
echo.
echo.
echo.
echo.
GOTO _changeDrive
You can modify the code to your liking and use it as you need.Sorry for the bad translation on the comments...
I hope you serve!
Start Guide for BatchScript: http://www.robvander.../batchfiles.php and advanced "For Loops" http://www.robvanderwoude.com/for.php
Also if you have problems with this programming language, I can help you in this area.
#13
Posted 03 May 2012 - 02:11 PM
Batch is much better than PowerShell in my situation.. thank you so much for taking the time to help me, YOU ARE MY HERO!!!!
I want to ask you 2 favours regarding the AutoSelect.cmd :
1. If Windows Folder exists, is it possible to have the user type on his keyboard WIPE before the script can continue? I want to make sure the user acknowledges that he's about to wipe his HDD.
2. if Windows Folder does not exist, is it possible to have the script continue without any user interaction, so Windows can continue to install unattended.
Thanks again, I really appreciate your time and effort to help me.
Bilo
Only need BatchScript
* No work with 2 OS installed on the machine) Only for example
<REMOVED CODE TO REDUCE QUOTE LENGTH>
You can modify the code to your liking and use it as you need.
Sorry for the bad translation on the comments...
I hope you serve!
Start Guide for BatchScript: http://www.robvander.../batchfiles.php and advanced "For Loops" http://www.robvanderwoude.com/for.php
Also if you have problems with this programming language, I can help you in this area.
Edited by bil0, 03 May 2012 - 02:44 PM.
#14
Posted 03 May 2012 - 03:14 PM
JFYI:
If exist is not reliable the way it is used in the above batch, for another reason from the one already posted, see here:
http://www.msfn.org/...e/page__st__117
(that is if in the intended environment mountvol is available, otherwise you need something else)
There is not much sense in using both small and CAPITAL letters, anyway, use IF /I instead:
IF /I "%%i" == "%_ok%"
There is no reason to clear the _winpath variable everytime.
Wonko
#15
Posted 03 May 2012 - 03:17 PM
@ECHO OFF FOR %%i IN © DO ( IF EXIST %%i:\WINDOWS\* ( SET _winpath= SET _winpath=%%i:\WINDOWS ) ELSE ( GOTO :end ) ) ECHO. ECHO. ECHO. A version of Windows was detected in the following path: ECHO. ECHO. %_winpath% ECHO. ECHO. Please any key to wipe your HDD. ECHO. Note: All files will be lost! ECHO. pause. cls ECHO. ECHO. If you're sure you want to delete all files on the HDD, press any key. ECHO. pause. EXIT :end ECHO. END Pause
Would be great that instead of having the user "press any key" I could have him to type the word: WIPE
#16
Posted 03 May 2012 - 03:56 PM
There is no need for a for loop for 1 (one) item.Would be great that instead of having the user "press any key" I could have him to type the word: WIPE
@ECHO OFF IF NOT EXIST C:WINDOWS* GOTO :do_something :LOOP CLS ECHO. ECHO. ECHO. A version of Windows was detected in C:WINDOWS ECHO. ECHO. ECHO. If you're sure you want to delete all files on the HDD, type WIPE ECHO. Note: All files will be lost! SET Confirm= SET /P Confirm=type WIPE in CAPITAL letters or Ctrl+C to terminate: IF NOT "%Confirm%"=="WIPE" GOTO :LOOP :do_something ECHO. ECHO assume that a program running your C: drive is running .... pause.
Wonko
#17
Posted 03 May 2012 - 07:19 PM
You guys are amazing!
There is no need for a for loop for 1 (one) item.
@ECHO OFF IF NOT EXIST C:\WINDOWS\* GOTO :do_something :LOOP CLS ECHO. ECHO. ECHO. A version of Windows was detected in C:\WINDOWS\ ECHO. ECHO. ECHO. If you're sure you want to delete all files on the HDD, type WIPE ECHO. Note: All files will be lost! SET Confirm= SET /P Confirm=type WIPE in CAPITAL letters or Ctrl+C to terminate: IF NOT "%Confirm%"=="WIPE" GOTO :LOOP :do_something ECHO. ECHO assume that a program running your C:\ drive is running .... pause.
Wonko
#18
Posted 04 May 2012 - 04:40 AM
If the PC where you will do the job is not yours, you do not know what can be found. So... you can't automate the work, without taking into account all possibilities, as well as also in case of problems, you may modify on the fly, without deleting data (erroneously) because you can not recover files after you delete it.
Please imagine this posibilities.






All are possible.
Obviously in a normal installation will have only installed Windows on the first partition. Or in the second partition ... in the case of the recovery partition for Windows Vista or Windows 7.
According to the Windows PE that you are using, the drive letters are assigned in different ways. And is further complicated when there are two operating systems installed on the same hard disk.
Therefore you can not use only the detection for C:\Windows . Understand what I mean?
#19
Posted 04 May 2012 - 12:08 PM
http://wb.paraglider...pts/scripts.htm
#20
Posted 04 May 2012 - 12:20 PM
And/or running it twice, once without and once with the /v parameter, to detect first NT/2K/XP and then VistaYou could always use my settargetroot program with the /f parameter:
http://wb.paraglider...pts/scripts.htm
If I get it right
Seriously, does the /f parameters recognize *all* windows?
Can you disclose which items does settargetroot check?
Wonko
#21
Posted 04 May 2012 - 02:44 PM
Therefore you can not use only the detection for C:\Windows . Understand what I mean?
Hey u2o, yes I understand exactly, me too it's been more then 10 years I work with Windows systems (I just don't know how to code batch like you), however in my case Windows is always installed on the C, so that's not a concern.
You could always use my settargetroot program with the /f parameter:
http://wb.paraglider...pts/scripts.htm
That looks very interesting, you made that!? f--k some smart people here.......
#22
Posted 04 May 2012 - 03:01 PM
You can find which Windows is from:
HKLMSoftwareMicrosoftWindows NTCurrentVersionProductName
And you can see the XP edition from:
c:windowssystem32prodspec.ini
Finally, if you want to know if it is an 64 bit version check for c:Program Files (x86)
#23
Posted 05 May 2012 - 02:34 AM
It then checks the version of system32ntdll.dll. If the version indicates its before win2k then its ignored.
It uses the presense of a subfolder syswow64 containing ntdll.dll to detect 64 bit windows.
If multiple such folders are found then you will get a dialog which asks you to choose which one to use.
It excludes the current booted system32 folder from being selected.
#24
Posted 05 May 2012 - 07:51 AM
If you're booting from an external device, the letters used by the drives should not matter.
I've also read that the bcd table is simply a registry file, so you could load and browse it in a registry program, like reg.exe.
#25
Posted 18 June 2012 - 01:46 PM
Can someone help me to besides recognizing the windows install, I need to load the registry of the windows installed so I can clean the registry to remove virus infections for example, thanks for the help
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users








