$code = @" using System; using System.Runtime.InteropServices; // pour DllImport using System.Text; using System.ComponentModel; // pour Win32Exception namespace ns_ModifyResource{ public class c_ModifyResource { #region LoadLibraryEx/FreeLibrary public enum LoadLibraryFlags : uint { DONT_RESOLVE_DLL_REFERENCES = 0x00000001, LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010, LOAD_LIBRARY_AS_DATAFILE = 0x00000002, LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040, LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020, LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008 } // ??? If you only want to load resources from the library, specify LoadLibraryFlags.LoadLibraryAsDatafile as dwFlags. In this case, nothing is done to execute or prepare to execute the mapped file. [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr LoadLibraryEx( string lpFileName, IntPtr hReservedNull, LoadLibraryFlags dwFlags); [DllImport("kernel32.dll", SetLastError=true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FreeLibrary( IntPtr hModule); #endregion LoadLibraryEx/FreeLibrary #region Equivalent des Macro private static bool IS_INTRESOURCE(IntPtr value) { if ( ((long) value) > ((long) ushort.MaxValue)) return false; return true; } private static uint GET_RESOURCE_ID(IntPtr value) { if (IS_INTRESOURCE(value) == true) return (uint) value; throw new System.NotSupportedException("value is not an ID!"); } private static string GET_RESOURCE_NAME(IntPtr value) { if (IS_INTRESOURCE(value) == true) return value.ToString(); return Marshal.PtrToStringUni((IntPtr) value); } #endregion Equivalent des Macro #region Enumération des langues des ressources [DllImport("kernel32.dll")] static extern bool EnumResourceLanguages(IntPtr hModule, IntPtr lpszType, IntPtr lpName, EnumResLangDelegate lpEnumFunc, IntPtr lParam); private delegate bool EnumResLangDelegate( IntPtr hModule, IntPtr lpszType, IntPtr lpszName, ushort wIDLanguage, IntPtr lParam); private static bool EnumResLangCallback( IntPtr hModule, IntPtr lpszType, IntPtr lpszName, ushort wIDLanguage, IntPtr lParam) { Console.WriteLine("\t\tLanguage: {0}", wIDLanguage); //hResInfo = FindResourceEx(hModule, lpType, lpName, wLang); return true; } #endregion Enumération des langues des ressources #region Enumération des noms des ressources [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] static extern bool EnumResourceNames( IntPtr hModule, IntPtr lpszType, EnumResourceNameDelegate lpEnumFunc, IntPtr lParam); private delegate bool EnumResourceNameDelegate( IntPtr hModule, IntPtr lpszType, IntPtr lpszName, IntPtr lParam); static bool EnumResourceNameCallback( IntPtr hModule, IntPtr lpszType, IntPtr lpszName, IntPtr lParam) { Console.WriteLine("\tName: {0}", GET_RESOURCE_NAME(lpszName)); bool bret = EnumResourceLanguages(hModule, lpszType, lpszName, new EnumResLangDelegate(EnumResLangCallback), lParam); if (bret == false) { throw new Win32Exception(Marshal.GetLastWin32Error()); } return true; } private delegate bool EnumResourceTypesDelegate( IntPtr hModule, IntPtr lpszType, long lParam); #endregion Enumération des noms des ressources #region Enumération des types des ressources [DllImport("kernel32",CharSet = CharSet.Unicode, SetLastError = true)] private extern static long EnumResourceTypes(IntPtr hModule, EnumResourceTypesDelegate callback, long lParam); // Implement required logic in EnumResourceTypesCallback function. Return 0 to stop enumeration, 1 to continue enumeration. static bool EnumResourceTypesCallback(IntPtr hModule, IntPtr lpszType, long lParam) { if (IS_INTRESOURCE(lpszType)) { Console.WriteLine("Type : {0}",GET_RESOURCE_ID(lpszType)); } else { Console.WriteLine("Type : {0}",GET_RESOURCE_NAME(lpszType)); } if (EnumResourceNames(hModule, lpszType, new EnumResourceNameDelegate(EnumResourceNameCallback), IntPtr.Zero) == false) { Console.WriteLine("erreur: {0}", Marshal.GetLastWin32Error()); } return true; } // appel depuis powershell // (set hModule and lParam to required values). public static void MyEnumResources(IntPtr hModule) { long lParam = 0; EnumResourceTypes(hModule, new EnumResourceTypesDelegate(EnumResourceTypesCallback), lParam); } #endregion Enumération des types des ressources } // end class } // end namespace "@ if (-not ("ns_ModifyResource.c_ModifyResource" -as [Type])) { Add-Type -TypeDefinition $code } $dst = "C:\windows\System32\notepad.exe" [System.IntPtr] $moduleHandle = [ns_ModifyResource.c_ModifyResource]::LoadLibraryEx($dst, [IntPtr]0, [ns_ModifyResource.c_ModifyResource+LoadLibraryFlags]::LOAD_LIBRARY_AS_DATAFILE); [ns_ModifyResource.c_ModifyResource]::MyEnumResources($moduleHandle) [ns_ModifyResource.c_ModifyResource]::FreeLibrary($moduleHandle)