Changes

7-Zip

5,555 bytes added, 08:32, 9 April 2013
no edit summary
</source>
=== File Associations== === Via VBScript === This simple script requires two parameters: <script_name>.vbs ASSIGN|REMOVE <path_to_list_of_extensions>  Running it ASSIGNs or REMOVEs file extension handlers from registry. The extensions must be listed in <path_to_list_of_extensions> file, via batch ie. "filetypes-definitions.txt": <source lang="dos">0017zarjbz2bzip2cabcpiodebdmggzfatgzgziphfsisolhalzhlzmantfsrarrpmsplitsquashfsswmtartaztbztbz2tgztpztxzvhdwimxarxz#z # let the Windows handle zip files#zip # let the Windows handle zip files</source> Best way to use script with WPKG would be to:  * run it as ASSIGN with server-based list on install * copy server-based list to local installation folder * on uninstall, run it as REMOVE with local list That way, on uninstall we remove only the originally assigned extensions: <source lang="xml"><!-- Register file handlers from server list --><install cmd='%CMD_CSCRIPT% "%PKG_SOURCE%\filetypes-register.vbs" ASSIGN "%PKG_SOURCE%\filetypes-definitions.txt"' /> <!-- Copy date-of-install definitions into local disk, we'll use it at reinstallation --><install cmd='%CMD_COPY% "%PKG_SOURCE%\filetypes-definitions.txt" "%PKG_DESTINATION%"' /> <!-- Try to unregister file handlers from local list --><remove cmd='%CMD_CSCRIPT% "%PKG_SOURCE%\filetypes-register.vbs" REMOVE "%PKG_DESTINATION%\filetypes-definitions.txt"'> <exit code="any"/></remove></source> The script code, '''please note''' that it uses standard Windows zip icon for files (standardizes user experience): <source lang="vb">' Common system objects, comment unused'Set objNetwork = CreateObject("WScript.Network")'Set objShellAp = CreateObject("Shell.Application")Set objWShell = CreateObject("WScript.Shell")'Set objConnection = CreateObject("ADODB.Connection")'Set objCommand = CreateObject("ADODB.Command")'Set objSysInfo = CreateObject("ADSystemInfo")'Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")Set objFSO = CreateObject("Scripting.FileSystemObject") 'Set colOS = objWMIService.ExecQuery( "Select * from Win32_OperatingSystem" )Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") ' Registry defaultsConst HKEY_LOCAL_MACHINE = &H80000002strBaseRegKey = "Software\Classes\"strKeyDefault = "" ' Program files pathstrProgramFiles = objWShell.ExpandEnvironmentStrings( "%ProgramFiles%" ) ' Require and verify arguments, if arguments incorrect or missing - quitIf WScript.Arguments.Count >= 2 Then  Select Case WScript.Arguments.Item( 0 ) Case "REMOVE" boolDelete = True Case "ASSIGN" boolDelete = False Case Else WScript.Quit( 2 ) End Select strFileTypes = WScript.Arguments.Item( 1 ) Else WScript.Quit( 2 )End If ' If types definition file does not exist, quitIf Not objFSO.FileExists( strFileTypes ) Then WScript.Quit( 1 ) ' Open text file and proceed with each lineSet objFileTypes = objFSO.OpenTextFile( strFileTypes, 1 ) Do While objFileTypes.AtEndOfStream <> True  ' Get a line, trimmed from all whitespace and comments ("#*") strFileType = TrimEx( objFileTypes.ReadLine ) ' If line not empty or commented If strFileType <> "" Then ' Check what we want to do If Not boolDelete Then ' Create all necessary keys objReg.CreateKey HKEY_LOCAL_MACHINE, strBaseRegKey & "." & strFileType objReg.SetStringValue HKEY_LOCAL_MACHINE, strBaseRegKey & "." & strFileType, strKeyDefault, "7-Zip" & "." & strFileType objReg.SetStringValue HKEY_LOCAL_MACHINE, strBaseRegKey & "." & strFileType, "PerceivedType", "compressed" objReg.SetStringValue HKEY_LOCAL_MACHINE, strBaseRegKey & "." & strFileType, "Content Type", "application/x-" & strFileType & "-compressed" objReg.CreateKey HKEY_LOCAL_MACHINE, strBaseRegKey & "7-Zip" & "." & strFileType objReg.SetStringValue HKEY_LOCAL_MACHINE, strBaseRegKey & "7-Zip" & "." & strFileType, strKeyDefault, UCase( strFileType ) & " archive" objReg.CreateKey HKEY_LOCAL_MACHINE, strBaseRegKey & "7-Zip" & "." & strFileType & "\DefaultIcon" objReg.SetStringValue HKEY_LOCAL_MACHINE, strBaseRegKey & "7-Zip" & "." & strFileType & "\DefaultIcon", strKeyDefault, "%SystemRoot%\system32\zipfldr.dll" objReg.CreateKey HKEY_LOCAL_MACHINE, strBaseRegKey & "7-Zip" & "." & strFileType & "\shell\open\command" objReg.SetStringValue HKEY_LOCAL_MACHINE, strBaseRegKey & "7-Zip" & "." & strFileType & "\shell\open\command", strKeyDefault, """" & strProgramFiles & "\7-Zip\7zFM.exe"" ""%1""" Else ' Delete all necessary keys recursively DeleteKeyRecursive HKEY_LOCAL_MACHINE, strBaseRegKey & "." & strFileType DeleteKeyRecursive HKEY_LOCAL_MACHINE, strBaseRegKey & "7-Zip" & "." & strFileType End If End If Loop WScript.Quit( 0 ) Sub DeleteKeyRecursive( objHive, strBaseRegKey )  objReg.EnumKey objHive, strBaseRegKey, arrSubKeys  If IsArray( arrSubKeys ) Then For Each strSubKey In arrSubKeys DeleteKeyRecursive objHive, strBaseRegKey & "\" & strSubKey Next End If objReg.DeleteKey objHive, strBaseRegKey End Sub Function TrimEx( strText ) Set objRE = New RegExp objRE.Multiline = False objRE.Global = True ' Trim whitespaces objRE.Pattern = "\s*" strText = objRE.Replace( strText, "" ) ' Trim all comments (if comment char is first in the line, it will return empty string) objRE.Pattern = "#.*$" strText = objRE.Replace( strText, "" ) TrimEx = strText End Function</source> === Via Batch file ===
<source lang="dos">
* This data will be used to automatically add the desired values to the registry.
=== File Associations, via registry Via REGEDIT (.reg file) ===
<source lang="xml">