/build/static/layout/Breadcrumb_cap_w.png

K2000 Format Drive Preinstall Task that knows if a CD rom is present or not?

With newer laptops and desktops, our company's hardware is shipping more and more often with no CD rom, only the 1 hdd.

The issue is the C: shows up as a different Volume number depending on the presence of a CD Rom or not.  
This means i have to have 2 images that are identical less the first Pre Install task that creates the partition and formats the drive.

No CD Rom:
select disk 0
clean
create partition primary
select volume 0
assign letter="C"
format quick fs=ntfs
active
exit


Yes CD Rom:

select disk 0
clean
create partition primary
select volume 1
assign letter="C"
format quick fs=ntfs
active
exit



Is there anyway to give it a IF EXISTS style command to reduce these 2 tasks into one?


Something like:

IF EXISTS D: (GOTO yes) ELSE (GOTO no)
:yes
select disk 0
clean
create partition primary
select volume 1
assign letter="C"
format quick fs=ntfs
active
exit

:no
select disk 0
clean
create partition primary
select volume 0
assign letter="C"
format quick fs=ntfs
active
exit


I can't for the life of me find a command that will check for volume number, or volume type that will work in a IF command.  

The simple IF EXISTS D:\ doesn't work if there isn't a disk in the CD Rom.


Any help would be greatly appreciated.



1 Comment   [ + ] Show comment
  • I've been looking around, and i might be able to do this with a VBS script from start to finish, but i have no experience with VBS. Anyone out there that can point me in the right direction? - jharrell 8 years ago

Answers (4)

Posted by: flip1001 8 years ago
Black Belt
0

I haven't tried this script in the K2000 but you can pipe it to a cmd find command to see if a cd-rom is present.


' DriveTypeList.vbs
' List drives and their type
' Script modified from 2 Microsoft script examples

Option Explicit
On Error Resume Next

WScript.Echo ShowDriveList

Function ShowDriveList
Dim fso, d, dc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set dc = fso.Drives
For Each d in dc
s = s & ShowDriveType(d) & vbCrLf
Next
ShowDriveList = s
End Function

Function ShowDriveType(drvpath)
Dim fso, d, t
Set fso = CreateObject("Scripting.FileSystemObject")
Set d = fso.GetDrive(drvpath)
Select Case d.DriveType
Case 0: t = "Unknown"
Case 1: t = "Removable"
Case 2: t = "Fixed"
Case 3: t = "Network"
Case 4: t = "CD-ROM"
Case 5: t = "RAM Disk"
End Select
ShowDriveType = "Drive " & d.DriveLetter & ": - " & t
End Function



Posted by: jharrell 5 years ago
Third Degree Blue Belt
0

Just remembered that I found a fix for this.

Its a pre-installation task that runs a PowerShell Script. 


I have 3 items in a zip as a file dependency in the task

1. CDRomCheck.ps1

2. NoCD.txt

3. YesCD.txt


The task full command line is:

%systemdrive%\Windows\System32\WindowsPowerShell\v1.0\powershell -nologo -executionpolicy bypass -noprofile -file CDRomCheck.ps1


In the Zip:

1. CDRomCheck.ps1:

$CDRom_Present = Get-WMIObject -Class Win32_LogicalDisk | Where-Object {$_.DriveType -eq5}

if($CDRom_Present-eq $null)

{DISKPART /S NoCD.txt

}

else

{

DISKPART /S YesCD.txt

}


2. NoCd.txt

SELECT DISK 0
CLEAN
CREATE PARTITION PRIMARY
SELECT VOLUME 0
ASSIGN LETTER=C
FORMAT QUICK FS=NTFS
ACTIVE

3. YesCD.txt:

SELECT DISK 0
CLEAN
CREATE PARTITION PRIMARY
SELECT VOLUME 1
ASSIGN LETTER=C
FORMAT QUICK FS=NTFS
ACTIVE

Posted by: StockTrader 8 years ago
Red Belt
0
Hello,

I'm not sure that this is really necessary (think about if the cd rom drive is there or not I mean) but to answer to your question YES it is possible.
You need to create a zip file with the following files:
No_cd.txt that contains 
select disk 0
clean
create partition primary
select volume 1
assign letter="C"
format quick fs=ntfs
active
exit

Yes_cd.txt that contains:

select disk 0
clean
create partition primary
select volume 1
assign letter="C"
format quick fs=ntfs
active
exit

Decision.bat that contains:

IF EXISTS D: (GOTO yes) ELSE (GOTO no)
:yes
diskpart /s Yes_cd.txt

:no
diskpart /s No_cd.txt

Create a pre-installation task, type application and as payload use the zip file that contains all the 3 files.

The command line is simply Decision.bat

Kind regards,

Marco - StockTrader


Comments:
  • Its the IF EXISTS D: that is failing. It will only work if there is a CD in the drive. This is what i am trying to work around. A CD Drive with no CD in it. - jharrell 8 years ago
Posted by: BHC-Austin 8 years ago
4th Degree Black Belt
0

If your KBE includes WMI commands (I can't recall if they are there by default or if you have to add them using KBE Manipulator), you can try something like this in place of the IF EXIST in StockTrader's example:

wmic logicaldisk get name | findstr /i /c:"D:" >nul
IF %ERRORLEVEL%==0 (GOTO yes) ELSE (GOTO no)

That lists all logical disk drives (including mapped drive letters) and checks to see if there is a D: drive among them.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ