Saturday, October 17, 2009

Windows 7 shared desktop and start menu folders

Although we will switch ASAP from Windows XP to Windows 7, we still have a lot of clients running XP and I think it will takes us up to two years to finally switch the last machine.

One of the problems in the automatic jobs we are using is that Windows 7 has new paths for both the shared desktop and the shared start menu.

As an easy solution for this, we are now using this batch script. It will save the correct path to the two variables DESKTOP_FOLDER and STARTMENU_FOLDER and the real job simply uses them. That way, the scripts works on either XP or Win7.

I know there is a symbolic link “Startmenu” inside \ProgramData in Win7 but some programs refuse to with the link. That’s why I’m using the “real” path here.

IF "%PUBLIC%"=="" GOTO NO_PUBLIC
GOTO PUBLIC_FOUND

:NO_PUBLIC
Rem PUBLIC env var not here, assuming XP
SET DESKTOP_FOLDER=%ALLUSERSPROFILE%\Desktop
SET STARTMENU_FOLDER=%ALLUSERSPROFILE%\Startmenu
GOTO EXEC


:PUBLIC_FOUND
Rem Public Variable found
SET DESKTOP_FOLDER=%PUBLIC%\Desktop
SET STARTMENU_FOLDER=%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu
GOTO EXEC


:EXEC
echo EXEC!
echo Desktop folder is %DESKTOP_FOLDER%
echo Start menu folder is %STARTMENU_FOLDER%

Wednesday, October 7, 2009

Installing Windows 7 drivers from the command line

If a Windows 7 PC with “unknown” (aka Driver missing) will simply connect to Windows Update, check if a matching driver is found and install it. This works fine when using this at home, but it does not work if you are inside a corporate network.

In this case, a Windows Server Update Services (WSUS) is used and it does not contain any drivers. Therefore, you need to manually download the drivers you need, put them in a folder and then use DPinst.exe to install the drivers.

To get this tool, you need to download Windows Driver Kit Version 7.0.0 – a hefty 610 MB download! Burn the ISO image to a CD or open it with WinRAR, and start the setup. Inside the setup, you only need to select “Tools”.

Once the Installation is finished, you can copy dpinst.exe from the \redist\DIFx\dpinst\MultiLin folder:

image

 

 

 

 

Each folder contains a version of DPInst.exe for the architecture the folder is named. I decided to simply rename each version of DPInst.exe and append the architecture to it, so I can copy all version to the same folder.

Create a folder on a network drive, e.g. W7_OnlineDrivers_1 and copy the renamed DPInst.exe files to it. My folder currently looks like this:

image

 

 

 

 

 

What DPInst.exe needs, is DPinst.xml with several settings it (you could also specify them on the command line, but I liked the XML idea more).

<?xml version="1.0" ?>
<dpinst>

<search>
<subDirectory>*</subDirectory>
</search>
<enableNotListedLanguages/>
<suppressEulaPage/>
<quietInstall/>

<!-- Only install drivers for online hardware -->
<scanHardware/>

<!-- No driver signature required -->
<legacyMode/>

</dpinst>

Most settings should be easy to understand, the complete reference can be found on this MSDN page. However, the scanHardware needs some explanation.

If this switch is found inside the file, DPInst.exe will only install drivers that are currently connected to the computer. All other drivers are not installed.

That’s the reason why I called the folder W7_OnlineDrivers. Since it will install only drives that are actually needed on the system, this folder can contain dozens of drivers – drivers that aren't needed will not be installed.

If scanHardware is NOT defined, DPInst.exe will install all drivers, regardless if a device is visible or not. This is basically the same as using pnputil.exe –a C:\<path>\*.inf.

Finally, we need a batch file to start DPInst.exe. I used the following in _install.bat for this:

"%~dp0dpinst_x86.exe" /c
pause

The /c parameter simply indicates that all output should go to the console instead of a log file. That way, you can easily see what is going on. As soon as I have a x64 Test machine ready, I will expand the batch file a little bit so it will execute dpinst_x64.exe on a 64 bit machine and dpinst_x86.exe on a 32 bit machine. For now I stick with the 32 bit version.

Once this is all setup, we are ready to install our first driver. The test computer I currently use had all drivers installed automatically, except for the sound card:

image

 

 

 

 

 

Right click the entry with the yellow exclamation mark and go to the “Details” tab. Inside this, select “Hardware-IDs”. These will list all PCI IDs for the device.

image

 

 

 

 

 

 

 

In this case, VEN_8086 and DEV_2445 should be enough to identify the device, so we will now search Windows Update for a driver:

http://catalog.update.microsoft.com/v7/site/Search.aspx?q=ven_8086%26dev_2445

Please note that this site is using an ActiveX control and therefore you will have to use Internet Explorer. The results of this query should look something like this:

image

Note: Normally you should be able to pick any driver and use it, however the first one I picked (Realtek) contained a file WITHOUT a digital signature and thus DPInst.exe exited with error code 80010300. So, if there is a Microsoft driver available, use it. They always work.

Simply click on the Add button of the driver you are interested in, click on View Basket and download the package, a *.CAB file.

Open the CAB file (with WinRAR for example) and expand all files in it to a new folder inside the W7_OnlineDrivers_1 folder.

Now you can give it a try and execute _Install.bat. If everything has been done right, Windows will install the driver for the sound card and activate it automatically. If not, check the output for any errors.

As a final note: If you download a new driver, just remove the folder containing the old one and execute DPInst.exe again. DPInst.exe will not just install new drivers, it also updates drivers. That’s a great way to keep the drivers current without any extra hassle.

 

UPDATE 2010-12-15: See this post why DPInst sometimes (especially with Network cards) chooses the wrong driver.

Installing and configuring language packs and settings from the command line in Windows 7

The current rollout I’m working on is based on a complete unchanged image from the Windows 7 DVD and several scripts that are running once Windows is installed.

We have done this to make sure that we are always able to update existing installations. That’s simply because it forces us to find the correct commands when Windows is already installed and not working on a WIM image.

One of these things was to install one or more language packs and then reconfigure Windows so it uses a new language (this needs to be done on the command line and not manually of course).

For this, you first need to get the language packs you want to install. Since we are using the Enterprise version of Windows 7, this was easy since there is a separate DVD (mu_windows_7_language_pack_x86_dvd_X15-73272.iso) which contains all language packs.

I simply copied the folders we want to install (de-DE, fr-FR and es-ES) from the DVD to a share. The directory structure then looked like this:

\\swdepot\Win7\LP\de-DE\lp.cab
\\swdepot\Win7\LP\fr-FR\lp.cab
\\swdepot\Win7\LP\es-ES\lp.cab

To install, simple use the lpksetup.exe utility which is included in Windows 7. Executing it with this command:

lpksetup.exe /i * /r /s /p \\swdepot\Win7\LP\

This will install all language packs inside the folder “\LP”.

In order to switch the language, we are using XML files that we basically designed for Vista but still work with Windows 7 (call me lazy…).

To set everything a German user expect (Formats, Location, Language etc.) and to apply the same settings to any new user that logs on, we use the following XML file:


<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend">
<!--User List-->
<gs:UserList>
<gs:User UserID="Current" CopySettingsToDefaultUserAcct="true" CopySettingsToSystemAcct="true"/>
</gs:UserList>
<!--User Locale-->
<gs:UserLocale>
<gs:Locale Name="de-DE" ResetAllSettings="true" SetAsCurrent="true"/>
</gs:UserLocale>

<!--Display Language-->
<gs:MUILanguagePreferences>
<gs:MUILanguage Value="de-DE" />
<gs:MUIFallback Value="en-US" />
</gs:MUILanguagePreferences>

<!--location-->
<!-- 0xF4 United States = 244 -->
<!-- 0x5E Germany = 94 -->
<gs:LocationPreferences>
<gs:GeoID Value="94"/>
</gs:LocationPreferences>

</gs:GlobalizationServices>

Most of the settings inside this file should be pretty self-explanatory, but here the link to the detailed explanation: http://www.microsoft.com/globaldev/vista/vista_tools/vista_command_line_international_configuration.mspx


The only “odd” setting inside this file is the “GeoID”. You need to retrieve the matching ID from this page: http://msdn.microsoft.com/en-us/library/ms912389%28WinEmbedded.11%29.aspx

To execute this file use the following command line:

control intl.cpl,, /f:\\swdepot\Win7\Intl_de-DE.xml

To switch back to English, simply replace “de-DE” with “en-US”, set the GeoID to the correct value and apply the new XML file with the command above.

Monday, October 5, 2009

Change Windows Features for Windows 7 / Windows Server 2008 from the command line

In case you want to add or remove feature in Windows 7 or Windows Server 2008 (R2) from the command line, the utility DISM.exe is all you need.

Normally it is used to service WIM images, but it can also execute on “Online” images which means the currently running Windows.

To get a list of features your Windows supports and there state (Enabled or disabled) simply type:

DISM.EXE /Online /Get-Features

To save the output to a file, simply use redirection:

DISM.EXE /Online /Get-Features >C:\Features.txt

To enable (install) a feature use the /Enable-Feature command :

DISM.EXE /online /Enable-Feature /FeatureName:MicrosoftWindowsPowerShellISE

To disable (uninstall) it, use the /Disable-Feature command:

DISM.EXE /online /Disable-Feature /FeatureName:MicrosoftWindowsPowerShellISE

You can enable or disable several features at once:

DISM.EXE /online /Enable-Feature /FeatureName:WindowsServerBackup /FeatureName:WindowsServerBackupCommandlet

However, depending on which feature you change it can happen that one feature requires another so you usually end up having several DISM calls.

In case you want to automate the process fully, add the “/Quiet” parameter but remember that this will restart your computer without any question when necessary:

DISM.EXE /online /Quiet /Enable-Feature /FeatureName:WindowsServerBackup /FeatureName:WindowsServerBackupCommandlet

Sometimes the names in the output of DISM are different from what you see inside the “Turn Windows feature on or off” (Windows 7) or “Add/Remove features” (Server 2008). For example, the IIS feature “Logging Tools” is called “IIS-LoggingLibraries” when using DISM.

To find out how the feature you are searching for is named, simply export the current list of features with this command:

DISM.EXE /Online /Get-Features >C:\Features_Before.txt

Then turn the feature on manually and once the installation is completed, use the following command:

DISM.EXE /Online /Get-Features >C:\Features_After.txt

A simply text compare on these two files will then show which feature has changed its state from “Disabled” to “Enabled”.