从网络更新本地 MSOffice 加载项期间出现权限被拒绝错误
我正在尝试在 PowerPoint 2003 中编写一个过程,该过程将允许自动更新已安装的加载项。大致流程如下:
卸载插件
对于 Application.AddIns 中的每个 objAddIn 如果 UCase(objAddIn.Name) = UCase(AddInName) 那么 使用 objAddIn .注册=msoFalse .AutoLoad = msoFalse .已加载=msoFalse 结束于 结束如果 下一步
从本地加载项目录中删除文件
设置 objFSO = CreateObject("Scripting.FileSystemObject")
如果 objFSO.FileExists(FileName) 那么 设置 objFSO = 无 杀死文件名 End If从网络位置复制文件
安装更新的加载项
到达步骤 2 后,任何尝试使用 FileSystemObject 或直接 Kill
卸载后删除文件不可避免地会生成运行时错误“70”:权限被拒绝
。如果我点击“调试”然后播放,它就会运行起来,就好像从来没有出现过问题一样。
旁注:我意识到我可以使用 FSO 覆盖本地文件,但这会给我带来相同的运行时错误。
我猜测问题与文件所在的某些方面有关使用,但我不知道如何“释放”旧的加载项以便可以删除底层文件。
有谁有洞察力可以提供帮助吗?
I am attempting to write a procedure in PowerPoint 2003 that will allow automatic updating of an installed add-in. The general process is as follows:
Uninstall the add-in
For Each objAddIn In Application.AddIns If UCase(objAddIn.Name) = UCase(AddInName) Then With objAddIn .Registered = msoFalse .AutoLoad = msoFalse .Loaded = msoFalse End With End If Next
Delete the file from the local Add-Ins directory
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(FileName) Then Set objFSO = Nothing Kill FileName End IfCopy over the file from the network location
Install the updated add-In
Upon reaching step 2, any attempt at deleting the file post-uninstall using either the FileSystemObject or a straight Kill
inevitably generates Run-time error '70': Permission denied
. If I hit Debug and then play, it runs through as if there was never a problem.
Side note: I realize I can use FSO to overwrite the local file, but that gives me the same run-time error.
I'm guessing the problem has to do with some aspect of the file being in use, but I can't figure out how to "release" the old add-in so that the underlying file can be deleted.
Does anyone have insight that can help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要先将其从插件集合中删除,然后才能将其物理删除。将其放在
End With
之后:You need to remove it from the Addins Collection before it can get physically deleted. Put this, right after your
End With
:此处的知识库文章引用了可用于检查锁定文件的 VBA 函数。
http://support.microsoft.com/kb/209189
它包含一个可以添加的简单功能到您的 VBA 来检查文件是否未锁定,并使用 Otaku 在其答案中提到的相同代码示例。
我要做的是...
替换代码中的 Kill Filename 行
*其中 FileLocked 是 KB209189 中提到的自定义函数
**如果这不起作用,请回复,我们还可以考虑用执行相同操作(但可能更彻底)的较低级别 Win32 函数替换上面的 Kill 语句。 :D
The KB Article that refers to a VBA function you can use to CHECK for a locked file is here.
http://support.microsoft.com/kb/209189
It contains a simple function you can add to your VBA to check that a file is not locked and uses the same code sample that Otaku refers to in his answer.
What I would do is...
Replace the Kill Filename line in your code
*Where FileLocked is a custom function referred to in KB209189
**If this doesn't work, reply back, we could also look at replacing the Kill statement above with a lower level Win32 function that does the same thing (but perhaps more throughly). :D