728x90
반응형
728x170
using System;
using System.Reflection;
using System.Runtime.InteropServices;
#region 쉘 변경 통지하기 - SHChangeNotify(eventID, flag, item1, item2)
/// <summary>
/// 쉘 변경 통지하기
/// </summary>
/// <param name="eventID">이벤트 ID</param>
/// <param name="flag">플래그</param>
/// <param name="item1">항목 1</param>
/// <param name="item2">항목 2</param>
[DllImport("Shell32.dll")]
private static extern int SHChangeNotify(int eventID, int flag, IntPtr item1, IntPtr item2);
#endregion
#region 윈도우즈 데스크톱과 탐색기 갱신하기 - RefreshWindowsDesktopAndExplorer()
/// <summary>
/// 윈도우즈 데스크톱과 탐색기 갱신하기
/// </summary>
public void RefreshWindowsDesktopAndExplorer()
{
// 데스크탑을 리프레쉬 한다.
SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
// 열려있는 윈도우즈 탐색기 창을 리프레쉬 한다.
Guid ShellApplicationCLSID = new Guid("13709620-C279-11CE-A49E-444553540000");
Type shellApplicationType = Type.GetTypeFromCLSID(ShellApplicationCLSID, true);
object shellApplication = Activator.CreateInstance(shellApplicationType);
object windows = shellApplicationType.InvokeMember("Windows", BindingFlags.InvokeMethod, null, shellApplication, new object[] { });
Type windowsType = windows.GetType();
object count = windowsType.InvokeMember("Count", BindingFlags.GetProperty, null, windows, null);
for(int i = 0; i < (int)count; i++)
{
object item = windowsType.InvokeMember("Item", BindingFlags.InvokeMethod, null, windows, new object[] { i });
Type itemType = item.GetType();
string itemName = (string)itemType.InvokeMember("Name", BindingFlags.GetProperty, null, item, null);
if(itemName == "Windows Explorer")
{
itemType.InvokeMember("Refresh", BindingFlags.InvokeMethod, null, item, null);
}
}
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] SHA256Managed 클래스 : SHA256 해시값 구하기 (0) | 2017.06.22 |
---|---|
[C#/COMMON] 객체 메소드 동적 실행하기 (0) | 2017.06.21 |
[C#/COMMON] 특정 파일을 선택해 파일 탐색기 실행하기 (0) | 2017.06.14 |
[C#/COMMON] Regex 클래스 : 모든 XML 태그를 소문자로 변경하기 (0) | 2017.06.14 |
[C#/COMMON] Dns 클래스 : GetHostAddresses 정적 메소드를 사용해 실행 호스트 IP 주소 여부 구하기 (0) | 2017.06.14 |
[C#/COMMON] TimeSpan 구조체 : 포맷 문자열을 사용해 문자열 구하기 (0) | 2017.06.13 |
[C#/COMMON] DOS 명령어 실행하기 (0) | 2017.06.12 |
[C#/COMMON] 다각형 무게 중심 구하기 (0) | 2017.06.11 |
[C#/COMMON] 다각형 면적 구하기 (0) | 2017.06.11 |
[C#/COMMON] 파비콘 다운로드 하기 (0) | 2017.06.10 |
댓글을 달아 주세요