2016-12-26 1 views
-2

私はショートカットを作成しようとしていますが、「デスクトップを表示」と「デスクトップアイコンを隠す」を切り替えることができます。.batを使用してデスクトップウィンドウがフォアグラウンドになっていることを確認する

set mypath=%cd% 
cd C:\Program Files\oneClickHD\ 
start ShowDesktop.lnk 
if "%mypath%"=="C:\Users\admin\Desktop" goto GO 
:GO 
start HideDesktopIcons.exe 

ファイルのコードのこの作品は、本当に私はので、私は3つの方法を考え、それを実行するためのショートカットを使用している場合は文句を言わない変更バットのディレクトリとして機能していないが、それらを実装することはできませんこれらのメソッドは、次のとおりです。

1 )存在する場合はウィンドウが開いているかどうかを検出してからshowdesktop.lnk をトグルするか、または現在のフォアグラウンドウィンドウがデスクトップトグルでない場合

2)だけではなく、解決策を見つけるため

デスクトップ切り開くショーデスクトップの使用何かを切り替えshowdesktop.lnkを使用しての)デスクトップが最前面にあるかどうかを確認し、はい

3 hideIcons.exe

を実行する場合、私nircmdを使用して、アクティブなウィンドウの値を返す方法や、デスクトップがアクティブであるかどうかを確認する方法が見つからない場合は、nircmd win min alltopnodesktop が動作するように見えますが、私はちょうど奇妙な方法で動作する壁紙を見ることができます。 私はまた、VBスクリプトを使用すると思ったが、Windows関連のものには.batを使う方が良いと分かった。 私はまた、powershellを使用してみましたが、それは私のPC上のように見えません。

+1

のウィンドウです。あなたのバッチはいくつかのルールに悪影響を及ぼします: - スペースを含むパスは、常に二重引用符で囲む必要があります。 - startは、引用符の最初の引数がウィンドウのタイトルになることを期待します。 - 次のステートメントへの移動は、それは自然です。 - デスクトップにはウィンドウがありませんが、ウィンドウが表示されるキャンバス/背景です。 - [windows + m(inimize)](http://stackoverflow.com/a/2284108/6811411)のショートカットにはSendMessageが必要です。実際に何をしているのかを明確にする必要があります。 – LotPings

+0

'スペースを含むパスは常に二重引用符で囲む必要があります - 通常はtrueですが、' cd'では必須ではありませんが、害はありません。) 'startは、ウィンドウのタイトルとなる最初の引数を引用符で囲むことを期待していますが、OPのポストには何も入れずにstart-with-any-quotesのインスタンスはありません。 – Magoo

+0

IIRCでは、デスクトップは実際にはウィンドウとして実装されています。 [GetDesktopWindow](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633504(v = vs.85).aspx)を参照してください。 –

答えて

1

ウィンドウがサポートされていないものは、ウィンドウのサポートが最小のものよりも優れています。

実際のプログラムを作成する必要があります。これは、フォアグラウンドウィンドウのハンドル、クラス名、およびウィンドウのタイトルを示します。

は、VBScript How to find the window Title of Active(foreground) window using Window Script Host

のようなCOM言語はGetForegroundWindow.basというファイルを作成ための方法をここに私の答えを参照してください。これをこれに入れてください。

Imports System 
Imports System.IO 
Imports System.Runtime.InteropServices 
Imports Microsoft.Win32 

Public Module MyApplication 
    Public Declare Function GetForegroundWindow Lib "user32" As Integer 
    Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long 
    Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long 

Sub Main() 
     Dim hWnd as Long, WT as String, CN as String, Length as Long 
     On Error Resume Next 
     hWnd=GetForegroundWindow() 
     WT = Space(512) 
     Length = GetWindowText(hwnd, WT, 508) 
     WT = Left$(WT, Length) 
     If WT = "" Then WT = Chr(171) & "No Window Text " & Err.LastDllError & Chr(187) 
     CN = Space(512) 
     Length = GetClassName(hwnd, CN, 508) 
     CN = Left$(CN, Length)  
     If CN = "" Then CN = "Error=" & Err.LastDllError 
     Console.Out.WriteLine(hWnd & "," & WT & "," & CN) 
'This shows how to toggle desktop, etc 
'This will work as a vbscript if you remove "as object" 

    Dim ShellApp as Object 
    ShellApp = CreateObject("Shell.Application") 
    ShellApp.MinimizeAll() 
    ShellApp.UndoMinimizeAll() 
    ShellApp.ToggleDesktop() 

End Sub 
End Module 

上記のファイルをデスクトップに置いてください。コマンドプロンプトを起動し、次のように入力します。

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /platform:anycpu /sdkpath:C:\Windows\Microsoft.NET\Framework\v4.0.30319 /target:exe /out:"%userprofile%\desktop\GetForegroundWindow.exe" "%userprofile%\desktop\GetForegroundWindow.bas" /verbose 

このような出力が得られます。

C:\Windows\system32>"C:\Users\User\Desktop\GetForegroundWindow.exe" 
593444,Administrator: Command Prompt - "C:\Users\User\Desktop\GetForegroundWindow.exe",ConsoleWindowClass 

あなたはFor /fループで解析することができます。 For /?を参照してください。

C:\Windows\system32>@for /f "Tokens=1-3 Delims=," %A in ('"C:\Users\User\Desktop\GetForegroundWindow.exe"') Do @Echo %C 
ConsoleWindowClass 

これらは、私は少し困惑してるシェル

Order Level WindowText ClassName HWnd ParentHWnd ProcessID ParentProcessID ThreadID ModuleNameHWin EXENameProcess 

21  «No Window Text 0» Shell_TrayWnd 41227310 52039984 12336 5532 10668 «Not Available Error=126» explorer.exe 
22   Start Start 43979912 41227310 12336 5532 10668 «Not Available Error=126» explorer.exe 
23   «No Window Text 0» TrayDummySearchControl 73536804 41227310 12336 5532 10668 «Not Available Error=126» explorer.exe 
24    Search Windows Button 56497500 73536804 12336 5532 10668 «Not Available Error=126» explorer.exe 
25    «No Window Text 0» Edit 11736392 73536804 12336 5532 10668 «Not Available Error=126» explorer.exe 
26    «No Window Text 0» ToolbarWindow32 23991502 73536804 12336 5532 10668 «Not Available Error=126» explorer.exe 
27   Task View TrayButton 33362614 41227310 12336 5532 10668 «Not Available Error=126» explorer.exe 
28   «No Window Text 0» TrayNotifyWnd 34476878 41227310 12336 5532 10668 «Not Available Error=126» explorer.exe 
29    10:06 AM TrayClockWClass 24449812 34476878 12336 5532 10668 «Not Available Error=126» explorer.exe 
30    «No Window Text 0» TrayShowDesktopButtonWClass 40899346 34476878 12336 5532 10668 «Not Available Error=126» explorer.exe 
31    Tray Input Indicator TrayInputIndicatorWClass 46273942 34476878 12336 5532 10668 «Not Available Error=126» explorer.exe 
32     «No Window Text 0» Button 28185460 46273942 12336 5532 10668 «Not Available Error=126» explorer.exe 
33     «No Window Text 0» Button 25170502 46273942 12336 5532 10668 «Not Available Error=126» explorer.exe 
34    «No Window Text 0» SysPager 21238280 34476878 12336 5532 10668 C:\Users\David Candy\Desktop\Editor\EditorSdi\Ed.exe explorer.exe 
35     User Promoted Notification Area ToolbarWindow32 25628972 21238280 12336 5532 10668 «Not Available Error=126» explorer.exe 
36    «No Window Text 0» Button 21107412 34476878 12336 5532 10668 «Not Available Error=126» explorer.exe 
37     «No Window Text 0» Button 32313836 21107412 12336 5532 10668 «Not Available Error=126» explorer.exe 
38    System Promoted Notification Area ToolbarWindow32 16781596 34476878 12336 5532 10668 «Not Available Error=126» explorer.exe 
39    Notification Center TrayButton 18157900 34476878 12336 5532 10668 «Not Available Error=126» explorer.exe 
40    Touch keyboard TIPBand 21697390 34476878 12336 5532 10668 «Not Available Error=126» explorer.exe 
41   «No Window Text 0» ReBarWindow32 9375916 41227310 12336 5532 10668 «Not Available Error=126» explorer.exe 
42    Running applications MSTaskSwWClass 24842334 9375916 12336 5532 10668 «Not Available Error=126» explorer.exe 
43     Running applications MSTaskListWClass 18485304 24842334 12336 5532 10668 «Not Available Error=126» explorer.exe 
44    Favorites ToolbarWindow32 12193824 9375916 12336 5532 10668 «Not Available Error=126» explorer.exe 
45    Desktop ToolbarWindow32 25497672 9375916 12336 5532 10668 «Not Available Error=126» explorer.exe 
関連する問題