<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Marcus Nyberg &#187; WMI</title>
	<atom:link href="http://www.marcusnyberg.com/category/wmi/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marcusnyberg.com</link>
	<description>Digital and dangerous</description>
	<lastBuildDate>Mon, 26 Jul 2010 11:00:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Troubleshoooting device driver installation with setupapilog.txt</title>
		<link>http://www.marcusnyberg.com/2010/01/22/troubleshoooting-device-driver-installation-with-setupapilog-txt/</link>
		<comments>http://www.marcusnyberg.com/2010/01/22/troubleshoooting-device-driver-installation-with-setupapilog-txt/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 13:40:39 +0000</pubDate>
		<dc:creator>marcus</dc:creator>
				<category><![CDATA[WMI]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/?p=402</guid>
		<description><![CDATA[Today I tried to install the &#8221;HP Universal Driver PCL6&#8243; (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&#8230; After some googling I found this very good post that describes the problem [...]]]></description>
			<content:encoded><![CDATA[<p>Today I tried to install the &#8221;HP Universal Driver PCL6&#8243; (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&#8230;</p>
<p>After some googling I found this <a href="http://www.destiny-sys.com/wordpress/2009/05/23/troubleshooting-scripted-printer-driver-installations/">very good post</a> that describes the problem and a possible solution.</p>
<p>The key to solving this puzzle and possibly other device installation problems is the file <strong>setupapi.log</strong> in the windows folder. After running my code again I got this in my setupapi.log file (in swedish):</p>
<p><code>[SetupAPI Log]<br />
OS-version = 5.1.2600 Service Pack 3<br />
Plattforms-ID = 2 (NT)<br />
Service Pack = 3.0<br />
Svit = 0x0100<br />
Produkttyp = 1<br />
Arkitektur = 2006157608<br />
[2010/01/22 14:20:41 5392.4 Driver Install]<br />
#-198 Bearbetad kommandorad: C:\WINNT\system32\wbem\wmiprvse.exe<br />
#I060 Ange vald drivrutin.<br />
#I060 Ange vald drivrutin.<br />
[2010/01/22 14:20:41 5392.5]<br />
#-198 Bearbetad kommandorad: C:\WINNT\system32\wbem\wmiprvse.exe<br />
#-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.<br />
#E169 SPFILENOTIFY_NEEDMEDIA: returnerade FILEOP_ABORT. Fel 2: Det går inte att hitta filen.<br />
#W187 Installationen misslyckades. Försök att återställa originalfiler utförs.</code></p>
<p>It says that I got an errorcode 2 (missing file) and which file that is missing. In this case it is missing the file &#8221;UNIDRV.HLP&#8221; that is not available in swedish. All I had to do is to extract this file from the cab-file &#8221;p6i2svww.cab&#8221; 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 <strong>setupapi.log</strong>.</p>
<p><code>[SetupAPI Log]<br />
OS-version = 5.1.2600 Service Pack 3<br />
Plattforms-ID = 2 (NT)<br />
Service Pack = 3.0<br />
Svit = 0x0100<br />
Produkttyp = 1<br />
Arkitektur = 2006157608<br />
[2010/01/22 14:28:43 4784.4 Driver Install]<br />
#-198 Bearbetad kommandorad: C:\WINNT\system32\wbem\wmiprvse.exe<br />
#I060 Ange vald drivrutin.<br />
#I060 Ange vald drivrutin.<br />
</code></p>
<p>That looks good I suppose! At least better then before. And the driver is installed ok!</p>
<p>You can <a href="http://www.microsoft.com/whdc/driver/install/setupapilog.mspx">read and download information about setupapilog.txt at the Microsoft website.</a> If you read the whitepaper you could possibly solve many kinds of STRANGE device driver installation problems.</p>
<p>This is Microsofts description of setupapilog.txt</p>
<blockquote><p>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, </p></blockquote>
<p>If you wnat more verbose logging to the setupapi.txt file you can edit the windows registry key &#8221;HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\LogLevel&#8221;. If you raise this value to 255 you get a lot of logging which can be useful at times.</p>
<p>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&#8230;</p>
<p>There is always something new to learn in the Windows world! Happy troubleshooting!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2010/01/22/troubleshoooting-device-driver-installation-with-setupapilog-txt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install printerports with WMI and VB.NET</title>
		<link>http://www.marcusnyberg.com/2009/12/11/install-printerports-with-wmi-and-vb-net/</link>
		<comments>http://www.marcusnyberg.com/2009/12/11/install-printerports-with-wmi-and-vb-net/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 14:06:17 +0000</pubDate>
		<dc:creator>marcus</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programmering]]></category>
		<category><![CDATA[WMI]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/?p=347</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>This is an example of how you install TCP/IP printerports with .NET and WMI (Windows Management Instrumentation).  </p>
<p>A list of properties can be found at <a href="http://msdn.microsoft.com/en-us/library/aa394492%28VS.85%29.aspx">MSDN Win32_TCPIPPrinterPort</a></p>
<p>Other topics:<br />
<a href="http://www.marcusnyberg.com/2009/11/23/install-printerdrivers-wmi/">How to install printerdrivers with wmi and VB.NET</a><br />
<a href="http://www.marcusnyberg.com/2010/01/12/how-to-create-a-printerqueu-with-net-and-wmi/">How to create a printerqueu with .NET and WMI</a></p>
<pre name="code" class="vb.net">
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
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2009/12/11/install-printerports-with-wmi-and-vb-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Install printerdrivers with WMI and VB.NET</title>
		<link>http://www.marcusnyberg.com/2009/11/23/install-printerdrivers-wmi/</link>
		<comments>http://www.marcusnyberg.com/2009/11/23/install-printerdrivers-wmi/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 08:26:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programmering]]></category>
		<category><![CDATA[WMI]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/?p=310</guid>
		<description><![CDATA[This is an example of how you install printerdrivers with .NET and WMI (Windows Management Instrumentation). Most examples on the Internet shows how this can be done with vbscript, printui.dll and such&#8230; A list of properties can be found at MSDN Win32_PrinterDriver Other topics: How to install printerports with WMI and VB.NET How to create [...]]]></description>
			<content:encoded><![CDATA[<p>This is an example of how you install printerdrivers with .NET and WMI (Windows Management Instrumentation). Most examples on the Internet shows how this can be done with vbscript, printui.dll and such&#8230;</p>
<p>A list of properties can be found at <a href="http://msdn.microsoft.com/en-us/library/aa394366(VS.85).aspx">MSDN Win32_PrinterDriver</a></p>
<p>Other topics:<br />
<a href="http://www.marcusnyberg.com/2009/12/11/install-printerports-with-wmi-and-vb-net/">How to install printerports with WMI and VB.NET</a><br />
<a href="http://www.marcusnyberg.com/2010/01/12/how-to-create-a-printerqueu-with-net-and-wmi/">How to create a printerqueu with .NET and WMI</a></p>
<pre name="code" class="vb.net">
Imports System.Management

Dim infPath  as String = "c:\driver\printerdriver.inf"
Dim mp As ManagementPath = New ManagementPath("Win32_PrinterDriver")

Dim co As ConnectionOptions = New ConnectionOptions()
co.EnablePrivileges = True

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

Dim mcPrinterDriver As New ManagementClass(ms, mp, Nothing)
mcPrinterDriver.SetPropertyValue("Name", "drivername")
mcPrinterDriver.SetPropertyValue("SupportedPlatform", "Windows NT x86") ' x86-architecture
'mcPrinterDriver.SetPropertyValue("SupportedPlatform", "Windows x64") ' x64-architecture
mcPrinterDriver.SetPropertyValue("Version", 3)
mcPrinterDriver.SetPropertyValue("FilePath", System.IO.Path.GetDirectoryName(infPath))
mcPrinterDriver.SetPropertyValue("InfName", infPath)

Dim inParams As System.Management.ManagementBaseObject = Nothing
inParams = mcPrinterDriver.GetMethodParameters("AddPrinterDriver")
inParams("DriverInfo") = CType(mcPrinterDriver, System.Management.ManagementBaseObject)
Dim outParams As System.Management.ManagementBaseObject = mcPrinterDriver.InvokeMethod("AddPrinterDriver", inParams, Nothing)

Dim uiReturnValue As UInteger = System.Convert.ToUInt32(outParams.Properties("ReturnValue").Value)
</pre>
<p>I have tested this in Windows XP, Windows 7 and Windows 2008R2. Make sure your account has privileges to install drivers.</p>
<p>On Windows XP the drivers are installed physically to:<br />
C:\WINNT\system32\spool\drivers</p>
<p>And in the registry:<br />
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Environments</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2009/11/23/install-printerdrivers-wmi/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
