首页  编辑  

刷新系统文件图标

Tags: /C#/API调用/   Date Created:

using System . Runtime . InteropServices;

[ DllImport ( "shell32.dll" , CharSet = CharSet . Auto, SetLastError = true )]

internal static extern void SHChangeNotify( uint wEventId , uint uFlags ,

    IntPtr dwItem1, IntPtr dwItem2);

private const uint SHCNE_ASSOCCHANGED = 0x08000000 ;

private const uint SHCNF_IDLIST = 0x0000 ;

private const uint SHCNF_FLUSH = 0x1000 ;

private void RegistryShell()

{

    RegistryKey vRegistryKey = Registry . ClassesRoot . CreateSubKey( ".tree" );

   vRegistryKey . SetValue( "" , "Tree Document" );

   vRegistryKey = Registry . ClassesRoot . CreateSubKey(

        @"Tree Document\shell\open\command" ,

        RegistryKeyPermissionCheck . ReadWriteSubTree);

   vRegistryKey . SetValue( "" , Application . ExecutablePath + " \"%1\"" );

   vRegistryKey = Registry . ClassesRoot . CreateSubKey(

        @"Tree Document\DefaultIcon" ,

        RegistryKeyPermissionCheck . ReadWriteSubTree);

   vRegistryKey . SetValue( "" , Application . ExecutablePath + ",0" );

   SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSH,

        IntPtr . Zero, IntPtr . Zero);

}