Jump to content

Recommended Posts

Posted

I have found Devcon to be an extremely useful tool for unattended installs. One of the latest uses I found for it is to automatically determine if the install is running in a VM (I use MS Virtual PC 2004 and Virtual Server 2004) and if so to install the VM additions package.

What is Devcon? Here is the official line from MS.

The DevCon utility is a command line utility that acts as an alternative to Device Manager. Using DevCon, you can enable, disable, restart, update, remove, and query individual devices or groups of devices. DevCon provides information that is relevant to the developer and is not available in Device Manager.

You can use DevCon with Windows 2000 and Windows XP. You cannot use Devcon with Microsoft Windows 95, Windows 98, or Windows Millennium Edition.

You can download Devcon from

DevCon - Command Line Utility Alternative to Device Manager

Here is the simple script I use to determine if the install is running on a VM.

From my RunOnce.Cmd script.

@ECHO Attempting to determine if the system is a VM...
@ECHO Install Microsoft Virtual PC or Server 2004 Additions if this system is a VM.
REM Since the VM additions install an updated video driver and it sets the desktop
REM to 640 x 480 x 8 bit we will use reschange after the next reboot to set the desktop to
REM 1024w x 768h x 24d x 75r
REM Virtual Server and Virtual PC both have a device named "Virtual HD"
C:\Temp\Scripts\devcon hwids * | xgrep -c "Virtual HD"
IF %errorlevel% EQU 0 CALL C:\Temp\Apps\VM\VM_Additions.Cmd
REM Lets do that again to skip the HP and IBM tests in the case we are on a VM
C:\Temp\Scripts\devcon hwids * | xgrep -c "Virtual HD"
IF %errorlevel% EQU 0 GOTO 002-Exit

And here is the actual VM_Additions.Cmd script

REM Script to install Microsoft Virtual PC/Server 2004 additions
REM Updated for the new common additions (v13.120) March 12th 2004

REM Virtual Server and Virtual PC both have the device named "Virtual HD"
C:\Temp\Scripts\devcon hwids * | xgrep -c "Virtual HD"
IF %errorlevel% EQU 0 GOTO MS_VM
IF %errorlevel% EQU 1 GOTO EXIT
IF %errorlevel% GEQ 2 GOTO ERROR

:MS_VM
REM Since the additions are the same now, this is kind of unnecessary at the moment...
REM All it does for now is logs to a different log file.
REM Determine if we have Virtual PC or Virtual Server
REM Virtual PC (by default) has a sound card, Virtual Server does not have this option.
C:\Temp\Scripts\devcon hwids * | xgrep -c "Sound Blaster 16"
IF %errorlevel% EQU 0 GOTO VPC
IF %errorlevel% EQU 1 GOTO VSRV
IF %errorlevel% GEQ 2 GOTO ERROR

:VPC
@Echo Installing Virtual PC Additions
REM Extract the archive
C:\Temp\Apps\VM\VSrv_Additions.Exe -y

REM Do silent install and reboot
C:\Temp\Apps\VM\Setup.Exe /S /V"/qb-! /L*v C:\Temp\VPC_Additions.Log"

GOTO EXIT


:VSRV
@Echo Installing Virtual Server Additions

REM Delete the VMWare SCSI drivers to avoid any conflicts during install
RMDIR /S /Q C:\Temp\Drivers\SCSI\VMWare
DEL /Q /F C:\WINDOWS\system32\drivers\vmscsi.sys

REM Extract the archive
C:\Temp\Apps\VM\VSrv_Additions.Exe -y

REM Do silent install and reboot
C:\Temp\Apps\VM\Setup.Exe /S /V"/qb-! /L*v C:\Temp\VSrv_Additions.Log"

GOTO EXIT

:ERROR
@ECHO Error occured during parsing of hardware IDs.
@ECHO Cannot determine if this system is a VM or real hardware.
pause

:EXIT

Another use I have for Devcon is determining if the system is attached to a FC SAN device which we use for clustering.

REM Clustered HP systems have a FC HBA device named "KGPSA"
C:\Temp\Scripts\devcon hwids * | xgrep -c "KGPSA"
IF %errorlevel% EQU 0 GOTO HAS-FC-HBA

REM Clustered VMs have a SCSI device named "VM Additions Accelerated SCSI Controller"
C:\Temp\Scripts\devcon hwids * | xgrep -c "VM Additions Accelerated SCSI Controller"
IF %errorlevel% EQU 0 GOTO HAS-FC-HBA

I hope this example is helpful to someone else out there and that you can adapt these ideas and examples for your own uses.

BTW xgrep is available for download @

xgrep - Small and fast text finding utility

Naturally you can substitute your favoured grep utility.


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...