Jump to content











Photo
- - - - -

O/S detection from Windows PE


  • Please log in to reply
25 replies to this topic

#1 bil0

bil0

    Newbie

  • Members
  • 21 posts
  •  
    Canada

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 steve6375

steve6375

    Platinum Member

  • Developer
  • 3,763 posts
  • Location:UK
  • Interests:computers (!), programming (masm,vb6,C,vbs), OSes, photography,TV,films,guitars
  •  
    United Kingdom

Posted 27 April 2012 - 09:41 PM

Why not just look for a Windows folder on all volumes?

#3 misty

misty

    Frequent Member

  • Expert
  • 130 posts
  •  
    United Kingdom

Posted 28 April 2012 - 09:19 AM

As an alternative to looking for a WINDOWS folder, what about searching all drives for boot specific files, e.g.
  • NTLDR (for Windows 2000/XP/2003)
  • BOOTMGR (for Windows Vista/2008/7/8)
It's easy to produce a batch file to search for one (or both) of these files.

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 MedEvil

MedEvil

    Platinum Member

  • .script developer
  • 7,687 posts

Posted 28 April 2012 - 09:32 AM

Both are slightly bad ideas, as they are not reliable.
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

:cheers:

#5 steve6375

steve6375

    Platinum Member

  • Developer
  • 3,763 posts
  • Location:UK
  • Interests:computers (!), programming (masm,vb6,C,vbs), OSes, photography,TV,films,guitars
  •  
    United Kingdom

Posted 28 April 2012 - 09:37 AM

Well, you could look for ANY file or folder and if found just list them (dir) for the user to see and ask if OK to format?

#6 bil0

bil0

    Newbie

  • Members
  • 21 posts
  •  
    Canada

Posted 30 April 2012 - 02: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). 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 steve6375

steve6375

    Platinum Member

  • Developer
  • 3,763 posts
  • Location:UK
  • Interests:computers (!), programming (masm,vb6,C,vbs), OSes, photography,TV,films,guitars
  •  
    United Kingdom

Posted 30 April 2012 - 02:42 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.

#8 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 8,784 posts
  • Location:The Outside of the Asylum
  •  
    Italy

Posted 30 April 2012 - 03:20 PM

if exist c:windowsnul

... remembering that checking for nul (though working in - say - 99% of cases) is not 100% reliable:
http://www.msfn.org/...-functionality/
http://www.msfn.org/...end/page__st__9
http://www.msfn.org/...ch-programming/

:cheers:
Wonko

#9 Tripredacus

Tripredacus

    Frequent Member

  • Expert
  • 143 posts
  • Interests:K-Mart-ian Legend
  •  
    United States

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 u2o

u2o

    Frequent Member

  • .script developer
  • 230 posts
  • Location:Argentina
  •  
    Argentina

Posted 01 May 2012 - 05:11 AM

Maybe a more accurate method to obtain the version of Windows... is get the version of one file
\WINDOWS\system32\ntdll.dll

Windows XP Sp3 = 5.1.2600.6055

You can do it with AutoIt / vb6 / c++ / etc...

#11 bil0

bil0

    Newbie

  • Members
  • 21 posts
  •  
    Canada

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 u2o

u2o

    Frequent Member

  • .script developer
  • 230 posts
  • Location:Argentina
  •  
    Argentina

Posted 03 May 2012 - 05:52 AM

Edited for modifications on the BatchScript's code
 
 
 
 
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
Only need BatchScript

* 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 bil0

bil0

    Newbie

  • Members
  • 21 posts
  •  
    Canada

Posted 03 May 2012 - 02:11 PM

This is absolutely fantastic, I love it !!

Batch is much better than PowerShell in my situation.. thank you so much for taking the time to help me, YOU ARE MY HERO!!!! :clap:

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 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 8,784 posts
  • Location:The Outside of the Asylum
  •  
    Italy

Posted 03 May 2012 - 03:14 PM

@u2o
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.

:cheers:
Wonko

#15 bil0

bil0

    Newbie

  • Members
  • 21 posts
  •  
    Canada

Posted 03 May 2012 - 03:17 PM

I was able to combine u2o scripts and make something that meets my needs:


@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 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 8,784 posts
  • Location:The Outside of the Asylum
  •  
    Italy

Posted 03 May 2012 - 03:56 PM

Would be great that instead of having the user "press any key" I could have him to type the word: WIPE

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.



:cheers:
Wonko

#17 bil0

bil0

    Newbie

  • Members
  • 21 posts
  •  
    Canada

Posted 03 May 2012 - 07:19 PM

FANTASTIC !

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.



:cheers:
Wonko



#18 u2o

u2o

    Frequent Member

  • .script developer
  • 230 posts
  • Location:Argentina
  •  
    Argentina

Posted 04 May 2012 - 04:40 AM

In 8 years working in the technical area in pc repair, I found many variations on Windows installations.

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.

Posted Image


Posted Image


Posted Image


Posted Image


Posted Image


Posted Image


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 paraglider

paraglider

    Gold Member

  • .script developer
  • 1,585 posts
  • Location:NC,USA
  •  
    United States

Posted 04 May 2012 - 12:08 PM

You could always use my settargetroot program with the /f parameter:

http://wb.paraglider...pts/scripts.htm

#20 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 8,784 posts
  • Location:The Outside of the Asylum
  •  
    Italy

Posted 04 May 2012 - 12:20 PM

You could always use my settargetroot program with the /f parameter:

http://wb.paraglider...pts/scripts.htm

And/or running it twice, once without and once with the /v parameter, to detect first NT/2K/XP and then Vista :ph34r: and 7/8 and later. :unsure:
If I get it right :dubbio:, if using this approach the (very few ;)) peeps still running 9x/Me will have their drives wiped anyway... :whistling:


Seriously, does the /f parameters recognize *all* windows?
Can you disclose which items does settargetroot check?

:cheers:
Wonko

#21 bil0

bil0

    Newbie

  • Members
  • 21 posts
  •  
    Canada

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 panreyes

panreyes

    Member

  • Members
  • 52 posts
  •  
    Spain

Posted 04 May 2012 - 03:01 PM

After you've recognized Windows folder you can use this advices to find out the Windows version and edition:

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) :D

#23 paraglider

paraglider

    Gold Member

  • .script developer
  • 1,585 posts
  • Location:NC,USA
  •  
    United States

Posted 05 May 2012 - 02:34 AM

Settargetroot scans all root directories on all drives looking for a sub folder system32config that contains files system, default,software, sam, security.

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 wendy

wendy

    Frequent Member

  • Lady
  • 236 posts
  • Location:one mile from the QR main line
  • Interests:Operating systems, Weights and Measures, Geometry
  •  
    Australia

Posted 05 May 2012 - 07:51 AM

You could read boot.ini to see what windows installs are on the machine. It should be possible to have three or four different windows installs in the same volume without too much interference - done this.

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 skyhacker

skyhacker
  • Members
  • 1 posts
  •  
    Portugal

Posted 18 June 2012 - 01:46 PM

Paraglider your script seems to be very nice, thanks

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