<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS: запуск «Диспетчера устройств» с отображением скрытых устройств]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=6096&amp;type=atom" />
	<updated>2014-03-02T19:16:19Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=6096</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS: запуск «Диспетчера устройств» с отображением скрытых устройств]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=80481#p80481" />
			<content type="html"><![CDATA[<p>Упрощённый вариант на основе предыдущего:<br /></p><div class="quotebox"><blockquote><p>2. Более сложный способ при помощи скрипта VBScript, автоматически устанавливающий флажок «Показать скрытые устройства»</p></blockquote></div><div class="codebox"><pre><code>Option Explicit

Dim objMenuItem
Dim strTempFileName


With WScript.CreateObject(&quot;WScript.Shell&quot;).Environment(&quot;Process&quot;)
    .Item(&quot;DEVMGR_SHOW_NONPRESENT_DEVICES&quot;) = &quot;1&quot;
    .Item(&quot;DEVMGR_SHOW_DETAILS&quot;) = &quot;1&quot;
End With

With WScript.CreateObject(&quot;MMC20.Application&quot;)
    .Load &quot;devmgmt.msc&quot;
    
    With .Document
        With .ActiveView
            .Frame.Maximize
            
            For Each objMenuItem In .ScopeNodeContextMenu
                If objMenuItem.Path = &quot;Вид-&gt;Показать скрытые устройства&quot; Then
                    If objMenuItem.Enabled = 1 Then
                        objMenuItem.Execute
                        
                        Exit For
                    End If
                End If
            Next
        End With
        
        If .IsSaved = 0 Then
            strTempFileName = GetTemporaryFileName()
            .SaveAs strTempFileName
            
            WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;).DeleteFile strTempFileName, True
        End If
    End With
    
    .UserControl = 1
End With

WScript.Quit 0
&#039;=============================================================================

&#039;=============================================================================
Function GetTemporaryFileName()
    Const TEMP_FOLDER = 2
    
    Dim strTempFile
    
    
    With WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;)
        Do
            strTempFile = .BuildPath(.GetSpecialFolder(TEMP_FOLDER), .GetTempName)
        Loop While .FileExists(strTempFile)
    End With
    
    GetTemporaryFileName = strTempFile
End Function
&#039;=============================================================================
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2014-03-02T19:16:19Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=80481#p80481</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBS: запуск «Диспетчера устройств» с отображением скрытых устройств]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50431#p50431" />
			<content type="html"><![CDATA[<p><strong>Запуск «Диспетчера устройств» с отображением скрытых устройств и вкладки «Сведения» («Details») в свойствах устройства.</strong></p><p>Как известно, по умолчанию «Диспетчера устройств» отображает не все устройства. К скрытым устройствам относятся не Plug&amp;Play устройства и фантомные устройства (отсутствующие сейчас, но когда-либо ранее подключавшиеся к системе устройства). Иногда нужно включить это отображение, дабы удалить то или иное неиспользуемое устройство.</p><p>Для отображения не Plug&amp;Play устройств требуется установить флажок «Показать скрытые устройства» («Show hidden devices») в меню «Вид» («View») «Диспетчера устройств». Для отображения фантомных устройств — дополнительно задать переменную окружения «DEVMGR_SHOW_NONPRESENT_DEVICES» равной единице перед вызовом «Диспетчера устройств»:<br /></p><div class="codebox"><pre><code>set DEVMGR_SHOW_NONPRESENT_DEVICES=1
start devmgmt.msc</code></pre></div><p>Кроме того, в Windows 2000, Windows XP SP1 и в Windows Server 2003 вкладка «Сведения» («Details») в свойствах устройства по умолчанию не отображается <em>[для более поздних версий — напротив, эта вкладка по умолчанию отображается]</em>. Для отображения вкладки «Сведения» («Details») в свойствах устройства требуется задать переменную окружения «DEVMGR_SHOW_DETAILS» так же равной единице перед вызовом «Диспетчера устройств»:<br /></p><div class="codebox"><pre><code>set DEVMGR_SHOW_DETAILS=1
start devmgmt.msc</code></pre></div><p>1. Простой способ при помощи пакетного файла:<br /></p><div class="codebox"><pre><code>@echo off
setlocal

set DEVMGR_SHOW_NONPRESENT_DEVICES=1
set DEVMGR_SHOW_DETAILS=1

start &quot;&quot; &quot;%SystemRoot%\SYSTEM32\mmc.exe&quot; &quot;%SystemRoot%\SYSTEM32\devmgmt.msc&quot;

endlocal
exit /b 0</code></pre></div><p>Минус этого способа — всё равно приходится вручную устанавливать в меню флажок «Показать скрытые устройства».</p><p>2. Более сложный способ при помощи скрипта VBScript, автоматически устанавливающий флажок «Показать скрытые устройства»:<br /></p><div class="codebox"><pre><code>Option Explicit

Const SW_HIDE = 0


Dim elem
Dim strNewEnvironment

Dim objSWbemObjectEx
Dim lngProcessID

Dim objMenuItem

Dim strTempFileName


If Not WScript.Arguments.Named.Exists(&quot;ShowDevMgmt&quot;) Then
    With GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2&quot;)
        strNewEnvironment = _
            &quot;DEVMGR_SHOW_NONPRESENT_DEVICES=1&quot; &amp; vbCrLf &amp; _
            &quot;DEVMGR_SHOW_DETAILS=1&quot;
        
        For Each elem In WScript.CreateObject(&quot;WScript.Shell&quot;).Environment(&quot;Process&quot;)
            If Left(elem, 1) &lt;&gt; &quot;=&quot; Then
                strNewEnvironment = strNewEnvironment &amp; vbCrLf &amp; elem
            End If
        Next
        
        
        Set objSWbemObjectEx = .Get(&quot;Win32_ProcessStartup&quot;).SpawnInstance_
        
        objSWbemObjectEx.ShowWindow           = SW_HIDE
        objSWbemObjectEx.EnvironmentVariables = Split(strNewEnvironment, vbCrLf)
        
        If .Get(&quot;Win32_Process&quot;).Create( _
            &quot;wscript.exe &quot;&quot;&quot; &amp; WScript.ScriptFullName &amp; &quot;&quot;&quot; /ShowDevMgmt&quot;, Null, objSWbemObjectEx, lngProcessID _
            ) &lt;&gt; 0 Then
            
            WScript.Echo &quot;Process [wscript.exe &quot;&quot;&quot; &amp; WScript.ScriptFullName &amp; &quot;&quot;&quot;] could not be created.&quot;
        End If
        
        Set objSWbemObjectEx = Nothing
    End With
Else
    With WScript.CreateObject(&quot;MMC20.Application&quot;)
        .Load &quot;devmgmt.msc&quot;
        
        With .Document
            With .ActiveView
                .Frame.Maximize
                
                For Each objMenuItem In .ScopeNodeContextMenu
                    If objMenuItem.Path = &quot;Вид-&gt;Показать скрытые устройства&quot; Then
                        If objMenuItem.Enabled = 1 Then
                            objMenuItem.Execute
                            
                            Exit For
                        End If
                    End If
                Next
            End With
            
            If .IsSaved = 0 Then
                strTempFileName = GetTemporaryFileName()
                .SaveAs strTempFileName
                
                WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;).DeleteFile strTempFileName, True
            End If
        End With
        
        .UserControl = 1
    End With
End If

WScript.Quit 0
&#039;=============================================================================

&#039;=============================================================================
Function GetTemporaryFileName()
    Const TEMP_FOLDER = 2
    
    Dim strTempFile
    
    
    With WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;)
        Do
            strTempFile = .BuildPath(.GetSpecialFolder(TEMP_FOLDER), .GetTempName)
        Loop While .FileExists(strTempFile)
    End With
    
    GetTemporaryFileName = strTempFile
End Function
&#039;=============================================================================</code></pre></div><p>3. Комбинированный метод, JScript внутри пакетного файла (кодировка пакетного файла из-за JScript должна быть «win-1251»!):<br /></p><div class="codebox"><pre><code>@set @x=0 /*
@echo off
setlocal enableextensions enabledelayedexpansion

set DEVMGR_SHOW_NONPRESENT_DEVICES=1
set DEVMGR_SHOW_DETAILS=1

cscript.exe /nologo /e:javascript %0

set DEVMGR_SHOW_DETAILS=
set DEVMGR_SHOW_NONPRESENT_DEVICES=

endlocal
exit /b 0
*/

with (WScript.CreateObject(&quot;MMC20.Application&quot;)) {
    Load(&quot;devmgmt.msc&quot;);

    with (Document) {
        with (ActiveView) {
            Frame.Maximize();

            with (new Enumerator(ScopeNodeContextMenu)) {
            for (; !atEnd(); moveNext())
                with (item())
                    if (Path == &quot;Вид-&gt;Показать скрытые устройства&quot;)
                        if (Enabled == 1) {
                            Execute();
                            break;
                        }
            }
        }

        if (IsSaved == 0) {
            strTempFileName = GetTemporaryFileName();
            SaveAs(strTempFileName);

            WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;).DeleteFile(strTempFileName, true);
        }
    }

    UserControl = 1;
}

WScript.Quit(0)

function GetTemporaryFileName()
{
    var strTempFile;

    with (WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;)) {
        do {
            strTempFile = BuildPath(GetSpecialFolder(2), GetTempName());
        } while (FileExists(strTempFile));
    }

    return (strTempFile);
}</code></pre></div><p>Код всех трёх скриптов находится также в приложенном архиве.</p><p><em>Ссылки по теме:</em><br /><a href="http://msdn.microsoft.com/en-us/library/ff553955(v=VS.85).aspx">Viewing Hidden Devices</a><br /><a href="http://msdn.microsoft.com/en-us/library/ff541419(v=VS.85).aspx">Device Manager Details Tab</a></p><p><a href="http://support.microsoft.com/kb/241257/ru">Диспетчер устройств не отображает отсутствующие в данный момент устройства в Windows 2000</a> (<a href="http://support.microsoft.com/kb/241257">Device Manager Does Not Display Devices Not Currently Present in Windows 2000</a>)<br /><a href="http://support.microsoft.com/kb/315539/ru">Диспетчер устройств не отображает устройства, не подключенные к компьютеру под управлением Windows XP</a> (<a href="http://support.microsoft.com/kb/315539">Device Manager does not display devices that are not connected to the Windows XP-based computer</a>)</p><p><a href="http://support.microsoft.com/kb/304514/ru">Настройка диспетчера устройств для получения подробной информации</a> (<a href="http://support.microsoft.com/kb/304514">How to Configure Device Manager to Display Detailed Information</a>)</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-08-07T04:05:34Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50431#p50431</id>
		</entry>
</feed>
