Archive by Author

Troubleshoooting device driver installation with setupapilog.txt

Today I tried to install the ”HP Universal Driver PCL6″ (32-bit) on a Windows XP machine with WMI and VB.NET. All I got was the errorcode 2 and a failed installation. What does that mean? Windows errorcodes is not my (anyones?) speciality…

After some googling I found this very good post that describes the problem and a possible solution.

The key to solving this puzzle and possibly other device installation problems is the file setupapi.log in the windows folder. After running my code again I got this in my setupapi.log file (in swedish):

[SetupAPI Log]
OS-version = 5.1.2600 Service Pack 3
Plattforms-ID = 2 (NT)
Service Pack = 3.0
Svit = 0x0100
Produkttyp = 1
Arkitektur = 2006157608
[2010/01/22 14:20:41 5392.4 Driver Install]
#-198 Bearbetad kommandorad: C:\WINNT\system32\wbem\wmiprvse.exe
#I060 Ange vald drivrutin.
#I060 Ange vald drivrutin.
[2010/01/22 14:20:41 5392.5]
#-198 Bearbetad kommandorad: C:\WINNT\system32\wbem\wmiprvse.exe
#-167 SPFILENOTIFY_NEEDMEDIA: Tagg = p6i2svww.cab, Beskrivning= PDL_LANG, Källsökväg = C:\CentralPrintArea\FKPrint\HP\Universal\32bit\HP Universal, Källfil = UNIDRV.HLP, Flaggor = 0x00000000.
#E169 SPFILENOTIFY_NEEDMEDIA: returnerade FILEOP_ABORT. Fel 2: Det går inte att hitta filen.
#W187 Installationen misslyckades. Försök att återställa originalfiler utförs.

It says that I got an errorcode 2 (missing file) and which file that is missing. In this case it is missing the file ”UNIDRV.HLP” that is not available in swedish. All I had to do is to extract this file from the cab-file ”p6i2svww.cab” to the root of the driverfolder. After doing this and running the program once more everything is working and the driver installs. After this I get the following output in setupapi.log.

[SetupAPI Log]
OS-version = 5.1.2600 Service Pack 3
Plattforms-ID = 2 (NT)
Service Pack = 3.0
Svit = 0x0100
Produkttyp = 1
Arkitektur = 2006157608
[2010/01/22 14:28:43 4784.4 Driver Install]
#-198 Bearbetad kommandorad: C:\WINNT\system32\wbem\wmiprvse.exe
#I060 Ange vald drivrutin.
#I060 Ange vald drivrutin.

That looks good I suppose! At least better then before. And the driver is installed ok!

You can read and download information about setupapilog.txt at the Microsoft website. If you read the whitepaper you could possibly solve many kinds of STRANGE device driver installation problems.

This is Microsofts description of setupapilog.txt

Windows XP and later versions log system operations more extensively than previous versions of Windows do. One of the most useful log files for debugging is the SetupAPI log file (setupapi.log). This plain-text file maintains the information that SetupAPI records about device installation, service-pack installation, and hotfix installation. Specifically, the file maintains a record of device and driver changes, as well as major system changes,

If you wnat more verbose logging to the setupapi.txt file you can edit the windows registry key ”HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\LogLevel”. If you raise this value to 255 you get a lot of logging which can be useful at times.

I hope this helps someone and that HP fixes the broken driver. It must be some sort of localization problem within this driver. Or maybe that I have the wrong driver…

There is always something new to learn in the Windows world! Happy troubleshooting!

How to create a printerqueu with .NET and WMI

This is an example of how you create a printerqueue with .NET and WMI (Windows Management Instrumentation).

A list of properties can be found at MSDN Win32_Printer

Other topics:
How to install printerdrivers with wmi and VB.NET
How to create TCP/IP printerports with .NET

Imports System.Management

Dim shared as Boolean = true

Try
 Dim mp As ManagementPath = New ManagementPath("Win32_Printer")
 Dim co As ConnectionOptions = New ConnectionOptions()
 co.EnablePrivileges = True
 co.Impersonation = ImpersonationLevel.Impersonate

 Dim ms As ManagementScope = New ManagementScope("\\" + Environment.MachineName + "\root\cimv2", co)

 Dim printerObject As ManagementObject = New ManagementClass(ms, mp, Nothing).CreateInstance()
 printerObject("PortName") = "IP_192.168.0.2"
 printerObject("DriverName") = "DriverName"
 printerObject("DeviceID") = "queuename"
 printerObject("Location") = "Placement of printer"
 printerObject("Comment") = "Some comments"

 If (shared) Then
  printerObject("Shared") = True
  printerObject("ShareName") = "Sharename"
  'printerObject("Published") = False ' Publish printer
 End If

 Dim options As PutOptions = New PutOptions()
 options.Type = PutType.UpdateOrCreate
 printerObject.Put(options)

Catch ex As Exception
 ' Do something
End Try

Nagios check_nt over ssh-tunnel

I am a big fan of Nagios for host and service monitoring and this is my first post on the subject. My task was to check services on a Windows Server with Nagios and NSClient++. But the firewall only allowed me to use ssh and thats why I could not connect to port 12489 (that NSClient listens to) from my Nagios server. The only way to solve the problem was to use a SSH-tunnel that I can open and close whenever I needed to.

Workflow for my solution
1. Nagios initiates that a service should be checked.
2. Nagios executes the check_nt_by_ssh_tunnel check-command with additional parameters
3. The script creates a ssh-tunnel
4. The script checks the Windows server with the Nagios builtin command check_nt
5. The script returns the check_nt output
6. The script closes the ssh-tunnel
7. Nagios does its processing.

Prerequisites
* A fully working Nagios installation
* NSClient installed and working on the Windows Server that should be monitored
* SSH autologin is configured between the two machines
* Read my other article for details about the SSH-tunnel used in this solution.

First you have to create the check-script on the Nagios server (in the Nagios libexec-folder). See below:

check_nt_by_ssh_tunnel.sh

#!/bin/bash

# $1 = HOSTNAME, 83.121.233.2
# $2 = LOCAL PORT, 14880
# $3 = USERNAME, ex: someusername
# $4 = CHECK PARAMETERS, ex: -w 80 -c 90 -v MEMUSE

if [ -z "$1" ]
then
        echo "Missing HOSTNAME"
        exit
fi

if [ -z "$2" ]
then
        echo "Missing LOCAL PORT"
        exit
fi

if [ -z "$3" ]
then
        echo "Missing USERNAME"
        exit
fi

# Open ssh-tunnel and wait for it to open
ssh -f -N -L $2:localhost:12489 $3@$1 &
sleep 30

# Run check_nt command
CHECK="/usr/local/nagios/libexec/check_nt -H localhost -p $2 $4"
#echo $CHECK
eval $CHECK

# Close ssh-tunnel
sleep 5
CMD="ps -eo pid,args | grep 'ssh -f -N -L $2:localhost' | grep -v  'grep' | cut -c1-6"
#echo $CMD
PID=`eval $CMD`
#echo $PID
kill -9 $PID

Make it executable:
chmod 755 check_nt_by_ssh_tunnel.sh

Then verify that i works by running the command:
./check_nt_by_ssh_tunnel.sh 83.121.233.2 14880 someusername ”-w 80 -c 90 -v MEMUSE”

You should then either see a valid Nagios plugin-output or get an error-message. Make sure that is works! You may have to modify the script depending on your *nix OS.

Next modify Nagios checkcommands.cfg or similiar and add the following. This makes the command available for use in Nagios.

# USAGE: check_nt_by_ssh_tunnel!11101!username!"-l 5,80,90 -v CPULOAD"
define command{
	command_name		check_nt_by_ssh_tunnel
	command_line		PATH_TO_COMMAND/check_nt_by_ssh_tunnel.sh $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$
}

Next add a service definition that uses the check-command.

define service{
	use				       generic-service
        host_name                        MY_HOSTNAME
        service_description             Memory usage
        check_command                 check_nt_by_ssh_tunnel!11100!username!"-w 80 -c 90 -v MEMUSE"
}

The last step you need to do is to restart Nagios and check if it works.

* I recommend you to change the portnumber for each service-definition to avoid collisions. Make them unique to the service-check.

Bash script that open and close an ssh-tunnel automagically

My problem was that I needed to connect to a port on a server that only was accessible by ssh. This connection should be made in a bash-script that starts and ends within a limited timeframe. That’s why I needed to solve the problem with a SSH-tunnel. George Notaras has made an article about auto-closing ssh tunnels that describes the problem and a solution that should work for most people. However, I did not need a auto-closing ssh tunnel because I want to close the tunnel whenever I want to.

My solution is a little bit more brute because it kills the tunnel. But hey, it works! Check out the simple solution below.

Prerequisites
For this to work you need to have ssh auto login between the two servers.

I have used this solution successfully with the Nagios monitoring system. Read Nagios check_nt over ssh-tunnel.

#!/bin/bash

# Open tunnel and wait for it to open
# 12489 = remote portnumber
# 3456  = local portnumber
# increase sleep-time if slow to connect
ssh -f -N -L 3456:localhost:12489 username@somehost &
sleep 30

# Run some command that uses the opened tunnel
# telnet localhost 3456

# Close the tunnel by killing it
sleep 5
CMD="ps -eo pid,args | grep 'ssh -f -N -L 3456:localhost' | grep -v  'grep' | cut -c1-6"
#echo $CMD
PID=`eval $CMD`
#echo $PID
kill -9 $PID

You may have to change the parameters to the ps-command for this to work on your nix-machine.

Install printerports with WMI and VB.NET

This is an example of how you install TCP/IP printerports with .NET and WMI (Windows Management Instrumentation).

A list of properties can be found at MSDN Win32_TCPIPPrinterPort

Other topics:
How to install printerdrivers with wmi and VB.NET
How to create a printerqueu with .NET and WMI

Imports System.Management

Try
  Dim mp As ManagementPath = New ManagementPath("Win32_TCPIPPrinterPort")
  Dim co As ConnectionOptions = New ConnectionOptions()
  co.EnablePrivileges = True

  Dim ms As ManagementScope = New ManagementScope("\\" + Environment.MachineName + "\root\cimv2", co)

  Dim port As ManagementObject = New ManagementClass(ms, mp, Nothing).CreateInstance()
  port.SetPropertyValue("Name", "portname")
  port.SetPropertyValue("Protocol", 1)
  port.SetPropertyValue("HostAddress", "10.15.12.12")
  port.SetPropertyValue("PortNumber", "9100")

  Dim po As PutOptions = New PutOptions()
  po.UseAmendedQualifiers = True
  po.Type = PutType.UpdateOrCreate
  port.Put(po)
Catch ex As Exception
  ' do something
End Try

Marvel 6162 SATA driver for Windows 7

There isn’t any driver for the Marvel 6162 (88SE6162) SATA controller in Windows 7 (32-bit). For my motherboard (Asus M2V) I needed this driver and I could not find them on the Asus support website. I guess Asus havn’t made these available yet. Lazy bastards! After some modifications to the Vista-drivers I could use them instead.

marvel-6162-sata-driver

If you download and try to install the Vista-drivers you get a message like ”Does not support this Operating System : WNT_6.1P_MCE”. To be able to run the installer you need to edit the AsusSetup.ini file with notepad. The only thing you need to do is add a line corresponding to your Operatingsystem (WNT_6.1P_MCE) in the [OS_Language_Tag] section of the file.

I have prepared a file for Windows 7 32-bit that you can use:
Download Marvell_SATA_V10215B2 driver.

You only have to extract the files and run the AsusSetup file in the driver/x32 folder. If you run Windows 7 64-bit you can use the same files and make the same changes. If someone does this then please contribute to this post.

The driver installer then works great and the drivers are working. My SATA-drive has appeared and I am happy again.

Problem installing Windows 7 on Asus motherboards

For the last 5 hours I tried to install Windows 7 (x86, 32bit) on my home computer that has an Asus M2V motherboard. I tried everything in the book and couldn’t install it. I removed and switched hardware, reburned the DVD, updated the BIOS and did everything that I could possibly think of. The installation process always hung when the installer says ”expanding windows files”. No error messages or nothing and the installation percentage counter stops at a random number. That really pissed me of!

Finally I found an answer to this really weird behaviour. It seems that this is common problem on Asus motherboards and Windows 7.

In BIOS you have to make these changes to make it work:
* Enable the floppy drive (I had it disabled because I dont have a floppy drive).
* Disable the ”Cool and quite” feature.

After I made these changes the installation worked!

I hope this helps other people stuck with the really annoying ”Windows 7″ installer.

Hemsida till Ludvig Nordström sällskapet

Jag har nyligen hjälp en kompis med att bygga en hemsida åt Ludvig Nordström sällskapet. Så kika på den!

ludvig1

Eftersom jag är ett stort fan av att använda Wordpress (php) som CMS till enklare webbsidor åt föreningar/mindre företag så blev det givetvis den tekniska lösningen. Som vanligt blev det lite hackande i form av att mixtra med teman samt plugins/tillägg men det var ganska enkla fixar som behövde göras. Samtidigt var det kul att se alla bra nyheter i Wordpress 2.8. Det är riktigt imponerande att följa WP’s utveckling.

Semester

Jag njuter nu av att det är semestertider. Vattenskidor utövas (film nedan) och php kodas. Jag håller nu på att bygga HockeySnack version 4 och lär mig samtidigt jquery som jag tycker är riktigt underbart och användbart.

MSDN Live Sundsvall 28 maj 2009

I slutet av maj så var jag på årets MDSN Live på Åkroken i Sundsvall. Talare var ”Microsoft-evangelisterna” Dag König och Robert Folkesson. Man informerade bland annat om att man kan hitta många filmer (på svenska) om den senaste MS-tekniken på Channel9 MSDN Sweden. Även att man då och då kör MSDN Radio som är radio-sessioner där man snackar om allt mellan himmel och .NET.

msdnlive

Dagen fortsatte sedan med en kort genomgång av historiken bakom .NET Framework 1-2-3 där man visade generiska typer och metoder, delegater, WCF, WF och WPF. Med grunden lagd så fortsatte dagen med en titt på det framtida .NET Framework 4.0 och Visual Studio 2010 som fortfarande är i beta-stadiet.

I .NET Framework så kommer ”Parallel Extensions” att ingå och det hjälper oss att programmera flertrådat. Introduktion till Parallel Extensions

Dynamic Language Runtime” (DLR) är ett stöd för dynamiska språk så att dessa går att köras på CLR’en.

Utöver detta så gick grabbarna genom nyheterna i C# version 4 med nyheter som dynamiska typer (dynamic).

I sista sessionen före lunch så gick de igenom hur man använder Visual Studio i kombination med Team Foundation Server och Visual Studio Team System. Detta var innehållet i förmiddagspasset som jag tyckte var väldigt intressant. Jag hade hört det mesta sedan tidigare då Johan Lindfors var på plats för Swenug, men det var ändå många nya bitar som gjorde det ”spännande”.

Eftermiddagen började med en grundgenomgång av XAML och varför Microsoft satsar stort på ett deklarativt språk. Detta används inte bara för gränssnitt i rika klienter, utan även i tekniker som Windows Workflow och WCF. Ett flertal exempel på detta gjordes i VS och Expression Blend.

Efter, det för mig ganska tråkiga, avsnittet om XAML (svammel *smile* ) så var det en genomgång av ASP.NET MVC som är ett alternativ till webforms. Webforms är som ni vet en utveckling eller en följd av winforms där man på något sätt ska ha samma arbetssätt då man skapar applikationer vare sig det är på desktopen eller på webben.

I MVC ramverket så har du full kontroll på allt som händer och kan utveckla dina webbsidor mer ”rent”. För mig som har php-bakgrund där du måste skapa allt för hand (ja nästan allt) så känns detta helt rätt. Personligen så tycker jag att detta är det bästa som MS kommit ut med då det gäller webbutveckling. Jag har aldrig riktigt gillat tråcklandet med webforms,
att man inte har någon kontroll på den html som skapas och viewstate och annat ”störande”.

Dagens sista presentation var om Silverlight 3 och .NET RIA Services. Om jag ska vara ärlig så var inte detta så intressant så jag har inte så mkt att säga om det…

Sammanfattningsvis så var det en intressant dag. Det är alltid intressant att höra om de senaste nyheterna från Microsoft.