<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://nsis.sourceforge.io/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Scan_for_hardware_changes</id>
	<title>Scan for hardware changes - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://nsis.sourceforge.io/mediawiki/index.php?action=history&amp;feed=atom&amp;title=Scan_for_hardware_changes"/>
	<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=Scan_for_hardware_changes&amp;action=history"/>
	<updated>2026-04-27T10:38:55Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.17</generator>
	<entry>
		<id>https://nsis.sourceforge.io/mediawiki/index.php?title=Scan_for_hardware_changes&amp;diff=18598&amp;oldid=prev</id>
		<title>ZeBoxx at 11:46, 11 June 2010</title>
		<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=Scan_for_hardware_changes&amp;diff=18598&amp;oldid=prev"/>
		<updated>2010-06-11T11:46:36Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;â† Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 11:46, 11 June 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l13&quot;&gt;Line 13:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 13:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;!define CM_LOCATE_DEVNODE_NORMAL 0x00000000&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;!define CM_LOCATE_DEVNODE_NORMAL 0x00000000&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;!define CM_REENUMERATE_NORMAL 0x00000000&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;!define CR_SUCCESS 0x00000000&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;!define CR_SUCCESS 0x00000000&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l30&quot;&gt;Line 30:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 31:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   ${Else}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   ${Else}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     ; Otherwise, Re-enumerate the devices.  This can take a few seconds&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     ; Otherwise, Re-enumerate the devices.  This can take a few seconds&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     System::Call &amp;quot;cfgmgr32::CM_Reenumerate_DevNode(ir0, &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;0&lt;/del&gt;) i.r1&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     System::Call &amp;quot;cfgmgr32::CM_Reenumerate_DevNode(ir0, &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;i${CM_REENUMERATE_NORMAL}&lt;/ins&gt;) i.r1&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     ; Check for success.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     ; Check for success.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key n22049_wiki-wiki_:diff::1.12:old-18597:rev-18598 --&gt;
&lt;/table&gt;</summary>
		<author><name>ZeBoxx</name></author>
	</entry>
	<entry>
		<id>https://nsis.sourceforge.io/mediawiki/index.php?title=Scan_for_hardware_changes&amp;diff=18597&amp;oldid=prev</id>
		<title>ZeBoxx: Created page with &#039;== Description == This is a small file that can be used as a header file for users installing device drivers.  In the event that your hardware driver must first refresh the devic…&#039;</title>
		<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=Scan_for_hardware_changes&amp;diff=18597&amp;oldid=prev"/>
		<updated>2010-06-11T11:43:23Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;== Description == This is a small file that can be used as a header file for users installing device drivers.  In the event that your hardware driver must first refresh the devic…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Description ==&lt;br /&gt;
This is a small file that can be used as a header file for users installing device drivers.&lt;br /&gt;
&lt;br /&gt;
In the event that your hardware driver must first refresh the device list before installation - to prevent a driver pre-install when the hardware is present, but the user manually removed the device from the device manager, for example - the macro below can be used to perform the same as pressing the &amp;quot;Scan for hardware changes&amp;quot; button in the Device Manager.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
* Forum discussion: http://forums.winamp.com/showthread.php?p=2670130#post2670130&lt;br /&gt;
* Microsoft support resource page: http://support.microsoft.com/kb/259697&lt;br /&gt;
&lt;br /&gt;
== The Script ==&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;&lt;br /&gt;
!include &amp;quot;LogicLib.nsh&amp;quot;&lt;br /&gt;
&lt;br /&gt;
!define CM_LOCATE_DEVNODE_NORMAL 0x00000000&lt;br /&gt;
!define CR_SUCCESS 0x00000000&lt;br /&gt;
&lt;br /&gt;
!macro scanForHardwareChanges&lt;br /&gt;
  ; Used to store the last return code&lt;br /&gt;
  Push $1             ; Stack: $2&lt;br /&gt;
  ; Used for temporary storage of DevInst handle&lt;br /&gt;
  Push $0             ; Stack: $0 $1&lt;br /&gt;
&lt;br /&gt;
  ; Locate the top node (null)&lt;br /&gt;
  System::Call &amp;quot;cfgmgr32::CM_Locate_DevNode(*i.r0, n, i${CM_LOCATE_DEVNODE_NORMAL}) i.r1&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  ; Check for success&lt;br /&gt;
  ${If} $1 &amp;lt;&amp;gt; ${CR_SUCCESS}&lt;br /&gt;
      ; If not successful, push &amp;#039;1&amp;#039; to stack to indicate error in Locate&lt;br /&gt;
      Push 1          ; Stack: 1 $0 $1&lt;br /&gt;
  ${Else}&lt;br /&gt;
    ; Otherwise, Re-enumerate the devices.  This can take a few seconds&lt;br /&gt;
    System::Call &amp;quot;cfgmgr32::CM_Reenumerate_DevNode(ir0, 0) i.r1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    ; Check for success.&lt;br /&gt;
    ${If} $1 &amp;lt;&amp;gt; ${CR_SUCCESS}&lt;br /&gt;
        ; If not successful, push &amp;#039;2&amp;#039; to stack to indicate error in Re-enumate&lt;br /&gt;
        Push 2      ; Stack: 2 $0 $1&lt;br /&gt;
    ${Else}&lt;br /&gt;
        ; Otherwise, push &amp;#039;0&amp;#039; to stack to indicate no error encountered&lt;br /&gt;
        Push 0&lt;br /&gt;
    ${EndIf}&lt;br /&gt;
  ${EndIf}&lt;br /&gt;
                      ; Stack: &amp;lt;result&amp;gt; $0 $1&lt;br /&gt;
  Exch                ; Stack: $0 &amp;lt;result&amp;gt; $1&lt;br /&gt;
  Pop $0              ; Stack: &amp;lt;result&amp;gt; $1&lt;br /&gt;
  Exch                ; Stack: $1 &amp;lt;result&amp;gt;&lt;br /&gt;
  Exch $1             ; Stack: &amp;lt;return&amp;gt; &amp;lt;result&amp;gt;&lt;br /&gt;
  Exch                ; Stack: &amp;lt;result&amp;gt; &amp;lt;return&amp;gt;&lt;br /&gt;
!macroend&lt;br /&gt;
!define scanForHardwareChanges `!insertmacro scanForHardwareChanges`&lt;br /&gt;
&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
Simply insert the following in a runtime code section to perform a device list refresh:&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;&lt;br /&gt;
${scanForHardwareChanges}&lt;br /&gt;
&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script pushes two values to the stack that you can optionally Pop to check (or leave the stack dirty if not needed, but beware of scripts that used an empty stack to check for end-of-list/array functionality).&lt;br /&gt;
&lt;br /&gt;
The top level stack item contains the result of the device list refresh.&lt;br /&gt;
* 0 = No errors&lt;br /&gt;
* 1 = An error occurred while trying to get the device instance for the machine&lt;br /&gt;
* 2 = An error occurred while trying to refresh the device list&lt;br /&gt;
&lt;br /&gt;
The second item on the stack contains the return code from the last call executed.  This return code can be compared to one of the CR_* return codes defined in cfgmgr32.h . The success return code is defined in the header, ${CR_SUCCESS}, whose value is 0x00000000 or just plain 0 (zero).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;&lt;br /&gt;
${scanForHardwareChanges}&lt;br /&gt;
Pop $0 ; macro result code&lt;br /&gt;
Pop $1 ; last call return code&lt;br /&gt;
&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing ==&lt;br /&gt;
Unless you have a custom device that you are installing/uninstalling, testing this script may seem to be a conundrum; after all, simply uninstalling some random device that your machine depends on to operate is not recommended.&lt;br /&gt;
&lt;br /&gt;
This author has safely tested operation on a laptop with a built-in modem, type &amp;quot;Agere Systems AC&amp;#039;97&amp;quot; - a Softmodem/Winmodem, which hasn&amp;#039;t ever seen use due to the ubiquity of wireless and wired internet on any remote locations, and may prove to be a similarly suitable target on other systems.&lt;br /&gt;
&lt;br /&gt;
[[Category:Code Examples]]&lt;/div&gt;</summary>
		<author><name>ZeBoxx</name></author>
	</entry>
</feed>