下面的例子似乎不适用于我的Windows Server 2008 SP2,也不适用于我的Windows 7 Pro Sp1。
命令:
$shellapp = new-object -com shell.application $shellapp
输出:
Application Parent ----------- ------ System.__ComObject System.__ComObject
命令:
$zipfile = $shellapp.namespace("c:\temp\file.zip") $zipfile
输出:没有输出? (我假设它没有工作,$ zipfile为空)
命令:
$zipfile.copyhere("c:\temp\file.txt")
输出:
You cannot call a method on a null-valued expression. At line:1 char:18 + $zipfile.copyhere <<<< ("file.txt") + CategoryInfo : InvalidOperation: (copyhere:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
我试图重新关联.zip与指示: 如何恢复Windows默认的Zip文件function? 。
我也试图重新注册regsvr32.dll zipfldr.dll没有成功。
这不是创build一个新的zip文件。 这是将文件添加到现有的zip文件。 在你的例子中,C:\ temp \ file.zip必须已经存在。
编辑:
function New-Zip { param([string]$zipfilename) set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) (dir $zipfilename).IsReadOnly = $false }