K2000 Format Drive Preinstall Task that knows if a CD rom is present or not?
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.
-
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)
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
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
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
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.