Declare Long LoadLibrary In WIN32API StringDeclare Long FindResource In WIN32API Long, Long, LongDeclare Long LoadResource In WIN32API Long, LongDeclare Long SizeofResource In WIN32API Long, LongDeclare Long FreeLibrary In WIN32API LongDeclare Long FreeResource In WIN32API LongLocal lcModule, hModulem.lcModule = Getfile("EXE|DLL")m.hModule = LoadLibrary(m.lcModule)m.lnRsrc = FindResource(m.hModule, 1, 24)m.lnMem = LoadResource(m.hModule, m.lnRsrc)m.lnSize = SizeofResource(m.hModule, m.lnRsrc)m.lcManifest = Sys(2600, m.lnMem, m.lnSize)FreeResource(m.lnMem)FreeLibrary(m.hModule)?m.lcManifest
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><assemblyIdentity version="1.0.0.0" type="win32" name="Microsoft.VisualFoxPro" processorArchitecture="x86"/><description>Visual FoxPro</description><dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" language="*" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" /> </dependentAssembly></dependency></assembly>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedPrivileges> <requestedExecutionLevel level="asInvoker" uiAccess="false"/> </requestedPrivileges> </security>
<file name="regfree.dll"> <comClass description="regfree.adder"clsid="{99A4ADD8-5A6A-40C1-89FF-50B5E8267B69}"progid="regfree.adder"threadingModel="Both"/></file>
<?xml version="1.0" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="1.0.0.0" type="win32" name="Microsoft.VisualFoxPro" processorArchitecture="x86"/> <description>Visual FoxPro</description> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" language="*" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df"/> </dependentAssembly> </dependency> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <security> <requestedPrivileges> <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> </requestedPrivileges> </security> </trustInfo><file name="regfreedll.dll"> <comClass description="regfreedll.adder" clsid="{99A4ADD8-5A6A-40C1-89FF-50B5E8267B69}" progid="regfreedll.adder" threadingModel="Both"/></file></assembly>
*!* Sample UsageLOCAL loModuleResourceEditor m.loModuleResourceEditor = CREATEOBJECT("ModuleResourceEditor")m.loModuleResourceEditor.Module = GETFILE("EXE|DLL|OCX|CPL")m.loModuleResourceEditor.ExecutionLevel = 3 && Require Administrator?m.loModuleResourceEditor.AddCOMModule("D:\Documents and Settings\Craig Boyd\Desktop\RegFreeComTest\regfreedll.dll")?m.loModuleResourceEditor.CreateNewModuleManifest()?m.loModuleResourceEditor.ApplyNewManifest()?m.loModuleResourceEditor.AddStringToStringTable("RegFreeDll Adder",101)DEFINE CLASS ModuleResourceEditor AS CUSTOM DIMENSION aCOMFiles(1) && array holding the COM modules to be added to manifest for REG-Free COM COMFileCount = 0 && Used internally to dimension aCOMFiles ExecutionLevel = 1 && asInvoker default Module = "" && EXE/OCX/DLL/etc. that will have its manifest modified Manifest = "" && New manifest DefaultManifest = "" && Manifest to be used if a manifest is not found in module LastError = 0 && Error number returned from GetLastError() ******************************* FUNCTION Init()******************************* this.aCOMFiles(1) = .F.ENDFUNC******************************* FUNCTION AddCOMModule(tcCOMModuleName)******************************* IF FILE(m.tcCOMModuleName) this.COMFileCount = this.COMFileCount + 1 DIMENSION this.aCOMFiles(this.COMFileCount) this.aCOMFiles(this.COMFileCount) = m.tcCOMModuleName =ASORT(This.aCOMFiles,1,-1,0,1) RETURN .T. ELSE RETURN .F. ENDIF ENDFUNC******************************* FUNCTION RemoveCOMModule(tcCOMModuleName)******************************* LOCAL lnFoundAt m.lnFoundAt = ASCAN(this.aCOMFiles, m.tcCOMModuleName) IF m.lnFoundAt > 0 this.aCOMFiles(m.lnFoundAt) = .F. ENDIF ENDFUNC******************************* FUNCTION ApplyNewManifest()******************************* #DEFINE RT_MANIFEST 24 LOCAL hFile, lnPosition, lnSize, hModule, lcStruct, lnCounter, ; llVFPModule, lnResult, llReturn, lcManifestXML LOCAL ARRAY laVFPSections[2] m.llReturn = .F. IF !FILE(This.Module) *!* The Module property does not appear to be a file or has not been set. RETURN m.llReturn endif IF Empty(This.Manifest) *!* The Manifest property does not appear to have been set. RETURN m.llReturn endifSET STEP ON DECLARE INTEGER BeginUpdateResource IN WIN32API STRING, INTEGER DECLARE INTEGER EndUpdateResource IN WIN32API INTEGER, INTEGER DECLARE INTEGER UpdateResource IN WIN32API INTEGER, INTEGER, INTEGER, INTEGER, STRING @, INTEGER DECLARE INTEGER GetLastError IN WIN32API m.llVFPModule = .T. && Assume that the module is a VFPModule*!* Preserve APP stub and Typelib/Registration info m.hFile = FOPEN(This.Module) m.lnPosition = FSEEK(m.hFile,0,2) && Go EOF and Get Size FOR m.lnCounter = 1 TO 2 =FSEEK(m.hFile, m.lnPosition - 14, 0) m.lcStruct = FREAD(m.hFile, 14) m.lnSize = CTOBIN(SUBSTR(m.lcStruct, 11, 4), "4sr") && last 4 bytes holds the size IF m.lnSize > m.lnPosition OR m.lnSize < 0 OR (m.lnCounter = 1 AND m.lnSize = 0) m.llVFPModule = .F. EXIT ENDIF IF m.lnSize != 0 =FSEEK(m.hFile, m.lnPosition - m.lnSize, 0) m.laVFPSections[m.lnCounter] = FREAD(m.hFile, m.lnSize) IF m.lnCounter = 1 AND LEFT(m.laVFPSections[1],3) != 0hFEF2FF m.llVFPModule = .F. EXIT ENDIF ELSE m.laVFPSections[m.lnCounter] = m.lcStruct ENDIF m.lnPosition = m.lnPosition - m.lnSize ENDFOR =FCLOSE(m.hFile)*!* Update Manifest in module m.hModule = BeginUpdateResource(This.Module, 0) m.lcManifestXML = This.Manifest m.lnResult = UpdateResource(m.hModule, RT_MANIFEST, 1, 1033, @m.lcManifestXML, LEN(m.lcManifestXML)) IF EndUpdateResource(m.hModule, 0) = 0 this.LastError = TRANSFORM(GetLastError()) ELSE m.llReturn = .T. ENDIF IF m.llVFPModule*!* Restore APP stub and the Typelib m.hFile = FOPEN(This.Module, 2) m.lnPosition = FSEEK(m.hFile, 0, 2) FOR m.lnCounter = 2 TO 1 STEP -1 =FWRITE(m.hFile, m.laVFPSections[m.lnCounter]) ENDFOR =FCLOSE(m.hFile) ENDIF RETURN m.llReturn ENDFUNC*********************** FUNCTION AddStringToStringTable(tcString, tnStringIndex) && pass -1 for tnStringIndex to add to end of string table*********************** #DEFINE RT_STRING 6 LOCAL hFile, lnPosition, lnSize, hModule, lcStruct, ; lnCounter, llVFPModule, lnResult, lnReturn, lcBaseStringTable, lcNewStringTable LOCAL ARRAY laVFPSections[2] m.lnReturn = -1 IF !FILE(This.Module) *!* The Module property does not appear to be a file or has not been set. RETURN m.lnReturn endif IF Empty(m.tcString) *!* The parameter was not set. RETURN m.lnReturn endif DECLARE INTEGER BeginUpdateResource IN WIN32API STRING, INTEGER DECLARE INTEGER EndUpdateResource IN WIN32API INTEGER, INTEGER DECLARE INTEGER UpdateResource IN WIN32API INTEGER, INTEGER, INTEGER, INTEGER, STRING @, INTEGER DECLARE INTEGER GetLastError IN WIN32API m.llVFPModule = .T. && Assume that the module is a VFPModule*!* Preserve APP stub and the Typelib m.hFile = FOPEN(This.Module) m.lnPosition = FSEEK(m.hFile,0,2) && Go EOF and Get Size FOR m.lnCounter = 1 TO 2 =FSEEK(m.hFile, m.lnPosition - 14, 0) m.lcStruct = FREAD(m.hFile, 14) m.lnSize = CTOBIN(SUBSTR(m.lcStruct, 11, 4), "4sr") && last 4 bytes holds the size IF m.lnSize > m.lnPosition OR m.lnSize < 0 OR (m.lnCounter = 1 AND m.lnSize = 0) m.llVFPModule = .F. EXIT ENDIF IF m.lnSize != 0 =FSEEK(m.hFile, m.lnPosition - m.lnSize, 0) m.laVFPSections[m.lnCounter] = FREAD(m.hFile, m.lnSize) IF m.lnCounter = 1 AND LEFT(m.laVFPSections[1],3) != 0hFEF2FF m.llVFPModule = .F. EXIT ENDIF ELSE m.laVFPSections[m.lnCounter] = m.lcStruct ENDIF m.lnPosition = m.lnPosition - m.lnSize ENDFOR =FCLOSE(m.hFile) SET STEP ON m.lcBaseStringTable = This.GetStringResource(1, RT_STRING) m.lnLastStringIndex = This.GetStringTableCount(m.lcBaseStringTable) DO case CASE m.tnStringIndex < 0 m.tcString = This.GetFormattedStringForStringTable(m.tcString) m.lcNewStringTable = m.lcBaseStringTable + m.tcString CASE m.tnStringIndex > m.lnLastStringIndex m.tcString = This.GetFormattedStringForStringTable(m.tcString) m.lcNewStringTable = m.lcBaseStringTable + REPLICATE(0h0000, m.tnStringIndex - m.lnLastStringIndex) + m.tcString OTHERWISE m.lcNewStringTable = This.ReplaceStringTableString(m.lcBaseStringTable, m.tnStringIndex, m.tcString) ENDCASE*!* Update String Table in module m.hModule = BeginUpdateResource(This.Module, 0) m.lnResult = UpdateResource(m.hModule, RT_STRING, 1, 1033, @m.lcNewStringTable, LEN(m.lcNewStringTable)) IF EndUpdateResource(m.hModule, 0) = 0 this.LastError = TRANSFORM(GetLastError()) ELSE m.lnReturn = IIF(m.tnStringIndex < 0, m.lnLastStringIndex + 1, m.tnStringIndex) ENDIF IF m.llVFPModule*!* Restore APP stub and the Typelib m.hFile = FOPEN(This.Module, 2) m.lnPosition = FSEEK(m.hFile, 0, 2) FOR m.lnCounter = 2 TO 1 STEP -1 =FWRITE(m.hFile, m.laVFPSections[m.lnCounter]) ENDFOR =FCLOSE(m.hFile) ENDIF RETURN m.lnReturn ENDFUNC*********************** FUNCTION CreateNewModuleManifest()*********************** #DEFINE RT_MANIFEST 24 LOCAL lcBaseManifest, lcLevelXML, lcModuleName, lnCounter, ; lcProgID, lcNameSpace, lcFileXML, lccomClassXML, lnClassCounter, ; loDOM AS MSXML2.DOMDocument, loParentNode AS MSXML2.IXMLDOMELEMENT, ; loNode AS MSXML2.IXMLDOMELEMENT, loNewLevelNode AS MSXML2.IXMLDOMELEMENT, ; loTempNode AS MSXML2.IXMLDOMELEMENT, loTypeLib AS TLI.TypeLibInfo IF !FILE(This.Module) *!* The Module property does not appear to be a file or has not been set. RETURN .F. ENDIF This.Manifest = ""*!* Get Manifest from Module or Create one m.lcBaseManifest = This.GetStringResource(1, RT_MANIFEST) IF EMPTY(m.lcBaseManifest) IF EMPTY(this.DefaultManifest) m.lcBaseManifest = This.GetDefaultManifest() ELSE m.lcBaseManifest = this.DefaultManifest ENDIF ENDIF m.loDOM = CREATEOBJECT("MSXML2.DOMDocument.4.0") IF m.loDOM.LOADXML(m.lcBaseManifest) m.lcNameSpace = m.loDOM.firstChild.NEXTSIBLING.getAttribute("xmlns")*!* Append or Replace Execution Level IF TYPE("This.ExecutionLevel") = "N" m.loNode = m.loDOM.selectSingleNode('//*[local-name()="trustInfo"]') IF !ISNULL(m.loNode) m.loParentNode = m.loNode.parentNode m.loParentNode.removeChild(m.loNode) ENDIF m.lcLevelXML = This.GetExecutionLevelXML() m.loNewLevelNode = This.GetNodeFromXML(m.lcLevelXML, m.lcNameSpace) IF !ISNULL(m.loNewLevelNode) m.loDOM.selectSingleNode('//*[local-name()="assembly"]').appendChild(m.loNewLevelNode) ENDIF ENDIF m.loDOM.setProperty("SelectionNamespaces", "xmlns:pe='" + m.lcNameSpace + "'")*!* Append or Replace Reg-Free COM IF TYPE("This.aCOMFiles",1) = "A" m.loTypeLib = CREATEOBJECT("TLI.TypeLibInfo") IF TYPE("m.loTypeLib") = "O" FOR m.lnCounter = 1 TO ALEN(This.aCOMFiles,1) IF TYPE("This.aCOMFiles(m.lnCounter)") = "C" AND FILE(This.aCOMFiles(m.lnCounter)) m.loTypeLib.ContainingFile = This.aCOMFiles(m.lnCounter) FOR m.lnClassCounter = 1 TO m.loTypeLib.TypeInfoCount m.loTypeInfo = m.loTypeLib.TypeInfos(m.lnClassCounter) IF m.loTypeInfo.TypeKind = 5 m.lcModuleName = JUSTFNAME(m.loTypeLib.ContainingFile) m.lcProgID = m.loTypeLib.NAME + "." + m.loTypeLib.TypeInfos(m.lnClassCounter).NAME m.loNode = m.loDOM.selectSingleNode('//*[local-name()="file"][translate(@name,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")="' + LOWER(m.lcModuleName) + '"]') IF ISNULL(m.loNode) m.lcFileXML = This.GetCOMFileXML(m.lcModuleName) m.loNewLevelNode = This.GetNodeFromXML(m.lcFileXML, m.lcNameSpace) IF !ISNULL(m.loNewLevelNode) m.loNode = m.loDOM.selectSingleNode('//*[local-name()="assembly"]').appendChild(m.loNewLevelNode) ENDIF ELSE FOR EACH loTempNode IN m.loNode.childNodes IF m.loTempNode.nodeName = "comClass" IF LOWER(m.loTempNode.getAttribute("progid")) = LOWER(m.lcProgID) m.loTempNode.parentNode.removeChild(m.loTempNode) EXIT ENDIF ENDIF NEXT ENDIF m.lccomClassXML = This.GetcomClassXML(m.lcModuleName, m.lcProgID, m.loTypeInfo.GUID, m.loTypeInfo.HELPSTRING) m.loNewLevelNode = This.GetNodeFromXML(m.lccomClassXML, m.lcNameSpace) IF !ISNULL(m.loNewLevelNode) m.loNode.appendChild(m.loNewLevelNode) ENDIF ENDIF ENDFOR ENDIF ENDFOR ENDIF ENDIF This.Manifest = m.loDOM.XML ENDIF RETURN .T. ENDFUNC*********************** FUNCTION GetDefaultManifest()*********************** LOCAL lcReturn TEXT TO m.lcReturn textmerge noshow<?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><assemblyIdentity version="1.0.0.0" type="win32" name="<<tcModuleName>>" processorArchitecture="x86"/><description><<tcModuleName>></description><dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" language="*" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df"/> </dependentAssembly></dependency></assembly> ENDTEXT RETURN m.lcReturn ENDFUNC*********************** FUNCTION GetStringTableCount(tcStringTable)***********************LOCAL lnReturn, lnCounter, lnStringSizem.lnReturn = 0FOR m.lnCounter = 1 TO LEN(m.tcStringTable) STEP 2 m.lnStringSize = CTOBIN(SUBSTR(m.tcStringTable,m.lnCounter,2),"2RS") * 2 m.lnReturn = m.lnReturn + 1 m.lnCounter = m.lnCounter + m.lnStringSizeENDFORRETURN m.lnReturnENDFUNC*********************** FUNCTION GetStringTableString(tcStringTable, tnIndex)***********************LOCAL lnIndex, lnCounter, lnStringSize, lcReturnm.lnIndex = 0m.lcReturn = ""FOR m.lnCounter = 1 TO LEN(tcStringTable) STEP 2 m.lnStringSize = CTOBIN(SUBSTR(tcStringTable,m.lnCounter,2),"2RS") * 2 m.lnIndex = m.lnIndex + 1 IF m.lnIndex = m.tnIndex m.lcReturn = STRCONV(SUBSTR(m.tcStringTable, m.lnCounter + 2, m.lnStringSize),6) EXIT ENDIF m.lnCounter = m.lnCounter + m.lnStringSizeENDFORRETURN m.lcReturnENDFUNC***********************FUNCTION GetFormattedStringForStringTable(tcString)***********************LOCAL lcReturn, lnLenm.lnLen = LEN(m.tcString)m.lcReturn = BINTOC(m.lnLen,"2RS") + STRCONV(m.tcString,5) && + IIF(MOD(m.lnLen,2) = 1,0h0000,"")RETURN m.lcReturnENDFUNC*********************** FUNCTION ReplaceStringTableString(tcStringTable, tnIndex, tcReplacementString)***********************LOCAL lnIndex, lnCounter, lnStringSize, lcReturnm.lnIndex = 0m.lcReturn = ""m.tnIndex = m.tnIndex + 1FOR m.lnCounter = 1 TO LEN(tcStringTable) STEP 2 m.lnStringSize = CTOBIN(SUBSTR(tcStringTable,m.lnCounter,2),"2RS") * 2 m.lnIndex = m.lnIndex + 1 IF m.lnIndex = m.tnIndex m.lcReturn = STUFF(m.tcStringTable, m.lnCounter, m.lnStringSize + 2, This.GetFormattedStringForStringTable(tcReplacementString)) EXIT ENDIF m.lnCounter = m.lnCounter + m.lnStringSizeENDFORRETURN m.lcReturnENDFUNC*********************** FUNCTION GetStringResource(tnName, tnType)*********************** LOCAL lcModule, hModule, lcReturn, lnResource, lnSize, hGlobal DECLARE LONG LoadLibrary IN WIN32API STRING DECLARE LONG FindResource IN WIN32API LONG, LONG, LONG DECLARE LONG LoadResource IN WIN32API LONG, LONG*!* DECLARE LONG LockResource IN WIN32API LONG DECLARE LONG SizeofResource IN WIN32API LONG, LONG DECLARE LONG FreeLibrary IN WIN32API LONG DECLARE LONG FreeResource IN WIN32API LONG m.hModule = LoadLibrary(This.Module) m.lnResource = FindResource(m.hModule, tnName, tnType) m.hGlobal = LoadResource(m.hModule, m.lnResource) m.lnSize = SizeofResource(m.hModule, m.lnResource)*!* LockResource(m.lnMem) m.lcReturn = SYS(2600, m.hGlobal, m.lnSize) FreeResource(m.hGlobal) FreeLibrary(m.hModule) RETURN m.lcReturn ENDFUNC*********************** FUNCTION GetNodeFromXML(tcXML, tcNameSpace)*********************** LOCAL loDOMTemp AS MSXML2.DOMDocument, loNode AS MSXML2.IXMLDOMELEMENT m.loNode = NULL m.loDOMTemp = CREATEOBJECT("MSXML2.DOMDocument.4.0") IF m.loDOMTemp.LOADXML([<dummy xmlns="] + m.tcNameSpace + [">] + m.tcXML + [</dummy>]) m.loNode = m.loDOMTemp.firstChild.firstChild ENDIF RETURN m.loNode ENDFUNC***************************** FUNCTION GetExecutionLevelXML()******************************!**!* This.ExecutionLevel = 1 - asInvoker, 2 - highestAvailable, 3 - requireAdministrator*!**!* asInvoker — module executes with the same permissions as its parent process (formerly known as leastPrivilege)*!* highestAvailable — module executes with the highest privileges the current user can obtain*!* requireAdministrator — module executes only for administrators (includes shield overlay for module icon)*!****************************** LOCAL lcLevel, lcReturn m.lcLevel = ICASE(This.ExecutionLevel = 2, "highestAvailable", This.ExecutionLevel = 3, "requireAdministrator", "asInvoker") TEXT TO m.lcReturn TEXTMERGE NOSHOW <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <security> <requestedPrivileges> <requestedExecutionLevel level="<<m.lcLevel>>" uiAccess="false"/> </requestedPrivileges> </security> </trustInfo> ENDTEXT RETURN m.lcReturn ENDFUNC***************************** FUNCTION GetCOMFileXML(tcModuleName)***************************** LOCAL lcReturn TEXT TO m.lcReturn TEXTMERGE NOSHOW<file name="<<LOWER(JUSTFNAME(tcModuleName))>>"></file> ENDTEXT RETURN m.lcReturn ENDFUNC***************************** FUNCTION GetcomClassXML(tcModuleName, tcProgID, tcCLSID, tcDescription)***************************** LOCAL lcReturn && tcCLSID*!* m.lcCLSID = CLSIDFromProgIDEx(m.tcProgID) IF PCOUNT() < 4 m.tcDescription = m.tcProgID ENDIF TEXT TO m.lcReturn TEXTMERGE NOSHOW<comClass description="<<m.tcDescription>>" clsid="<<m.tcCLSID>>" progid="<<m.tcProgID>>" threadingModel="Both"/> ENDTEXT RETURN m.lcReturn ENDFUNC*****************************FUNCTION GetLastErrorMessage(tnError)*****************************#DEFINE FORMAT_MESSAGE_FROM_SYSTEM 0x00001000LOCAL lcBufferDECLARE INTEGER GetLastError IN win32apiDECLARE INTEGER FormatMessage IN kernel32.DLL ; INTEGER dwFlags, ; STRING @lpSource, ; INTEGER dwMessageId, ; INTEGER dwLanguageId, ; STRING @lpBuffer, ; INTEGER nSize, ; INTEGER Arguments m.lcBuffer = SPACE(128) =FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 'WINERROR.H', m.tnError, 0, @m.lcBuffer, 128 , 0) RETURN m.lcBufferENDFUNCENDDEFINE
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u