Win32APIを使用します。
1.デスクトップ上のフォルダーのフルパス名を取得する。
2.フルパス名でウィンドウハンドルを取得。(FindWindow)
3.ウィンドウを閉じる。(PostMessage)
例.デスクトップ上のフォルダー『ABC』を閉じる場合
Option Explicit
'API宣言
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
'処理部
Const WM_CLOSE = 16
Dim MyWSShell As Object
Dim MyDesktopFolder As String
Dim hWin As Long
Dim lngRet As Long
Set MyWSShell = CreateObject("WScript.Shell")
MyDesktopFolder = MyWSShell.SpecialFolders("Desktop") & "\ABC"
Set MyWSShell = Nothing
'フルパス名でウィンドウハンドル取得
hWin = FindWindow(vbNullString, MyDesktop)
If hWin = 0 Then
lngRet = MsgBox("ウィンドウが存在しません", vbExclamation + vbOKOnly)
Exit Sub
End If
'クローズ命令
PostMessage hWin, WM_CLOSE, 0, 0
お礼
Hardkingさん ありがとうございました。 私には、C言語はまったくわかりません。 せっかくお教えいただいたのにすみません。 これで終了させていただきます。