![](/img/trans.png)
[英]Permission Denied Error During Update of a Local MSOffice Add-In from Network
[英]vbscript permission denied 800a0046 network
我制作了一个脚本,将文件复制到某个位置。 我将 .vbs 添加到计划进行 a.pst 备份的 taskschd.msc,但我收到错误消息
行:91 字符:7 错误:权限被拒绝 代码:800A0046 来源:Microsoft VBScript 运行时错误
<pre>
'Set the amount of pst-files you want to copy. Start counting at 0!
ReDim pst(1)
'Define the location of each pst-file to backup. Increase the counter!
pst(0) = "C:\Users\daniel.elmnas.TT\Documents\Outlook Files\de@teknotrans.se.pst"
pst(1) = "C:\Users\daniel.elmnas.TT\Documents\Outlook Files\de.pst"
'Define your backup location
BackupPath = "\\ttad-1\Gemensam\Outlook_Backup\Daniel Elmnäs"
'Keep old backups? TRUE/FALSE
KeepHistory = FALSE
'Maximum time in milliseconds for Outlook to close on its own
delay = 30000 'It is not recommended to set this below 8000
'Start Outlook again afterwards? TRUE/FALSE
start = TRUE
'===================STOP MODIFY====================================
'Close Outlook
Call CloseOutlook(delay)
'Outlook is closed, so we can start the backup
Call BackupPST(pst, BackupPath, KeepHistory)
'Open Outlook again when desired.
If start = TRUE Then
Call OpenOutlook()
End If
Sub CloseOutlook(delay)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'If Outlook is running, let it quit on its own.
For Each Process in objWMIService.InstancesOf("Win32_Process")
If StrComp(Process.Name,"OUTLOOK.EXE",vbTextCompare) = 0 Then
Set objOutlook = CreateObject("Outlook.Application")
objOutlook.Quit
WScript.Sleep delay
Exit For
End If
Next
'Make sure Outlook is closed and otherwise force it.
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Outlook.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
Set objWMIService = Nothing
Set objOutlook = Nothing
set colProcessList = Nothing
End Sub
Sub BackupPST(pst, BackupPath, KeepHistory)
Set fso = CreateObject("Scripting.FileSystemObject")
If KeepHistory = True Then
ArchiveFolder = Year(Now) & "-" & Month(Now) & "-" & Day(Now)
BackupPath = BackupPath & ArchiveFolder & "\"
End If
If fso.FolderExists(BackupPath) = False Then
fso.CreateFolder BackupPath
End If
For Each pstPath in pst
If fso.FileExists(pstPath) Then
fso.CopyFile pstPath, BackupPath, True
End If
Next
Set fso = Nothing
End Sub
Sub OpenOutlook()
Set objShell = CreateObject("WScript.Shell")
objShell.Run "Outlook.exe"
End Sub
</pre>
有人可以帮我解决这个问题吗?
先感谢您
编辑:更改文件夹的权限。
注意:这样,任何有权访问此计算机的人都可以访问该文件夹。 您可能考虑只将登录名添加到计算机的“组”或用户名列表中,而不是“所有人”。 您可能必须在有问题的PST文件上重复上述步骤。
原始帖子:
我在这里运行脚本,测试了各种问题,并且没有问题。 目前,我认为问题是源文件夹或目标文件夹(或要备份的文件)的权限。 默认情况下,用户自己无权访问Outlook数据文件。 您需要为相关文件(PST,OST等)或完整文件夹添加“读取”权限。 实际上,仅备份PST文件不足以恢复Outlook配置。 您将需要所有文件。 您可以尝试以下方法:
'===================================================================
'Description: VBS script to backup your pst-files.
'
'Comment: Before executing the vbs-file, set the location of outlook
' folder you want to backup and
' the backup location (this can also be a network path).
' See the URL below for more configuration instructions and
' how to create a Scheduled Task for it.
'
' Original author : Robert Sparnaaij
' Modified: Fred Kerber
' version: 1.1
' website: http://www.howto-outlook.com/downloads/backupscript.htm
' Changes:
' Changed var types; changed to backup full folder and not just pst files.
'===================================================================
'===================BEGIN MODIFY====================================
'Define the folder location of Outlook's data files.
sOutlookDataPath = "C:\Users\FKerber.CORP\AppData\Local\Microsoft\Outlook\"
'Define your backup location
sBackupPath = "E:\Outlook Backup\"
'Keep old backups? TRUE/FALSE
bKeepHistory = TRUE
'Maximum time in milliseconds for Outlook to close on its own
iDelay = 30000 'It is not recommended to set this below 8000
'Start Outlook again afterwards? TRUE/FALSE
bStart = True
'===================STOP MODIFY====================================
'Close Outlook
Call CloseOutlook(iDelay)
'Outlook is closed, so we can start the backup
Call BackupOutlook(sOutlookDataPath, sBackupPath, bKeepHistory)
'Open Outlook again when desired.
If bStart = TRUE Then
Call OpenOutlook()
End If
Sub CloseOutlook(iDelay)
Set objWMIService = GetObject("winmgmts:" &_
{impersonationLevel= impersonate}!\\.\root\cimv2")
'If Outlook is running, let it quit on its own.
For Each oProcess in objWMIService.InstancesOf("Win32_Process")
If StrComp(oProcess.Name,"OUTLOOK.EXE",vbTextCompare) = 0 Then
Set objOutlook = CreateObject("Outlook.Application")
objOutlook.Quit
WScript.Sleep delay
Exit For
End If
Next
'Make sure Outlook is closed and otherwise force it.
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Outlook.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
Set objWMIService = Nothing
Set objOutlook = Nothing
Set colProcessList = Nothing
End Sub
Sub BackupOutlook(sOutlook, sBackupPath, bKeepHistory)
Set ofso = CreateObject("Scripting.FileSystemObject")
If bKeepHistory = True Then
sArchiveFolder = Year(Now) & "-" & Month(Now) & "-" & Day(Now)
sBackupPath = sBackupPath & sArchiveFolder & "\"
Else
For Each oFile In ofso.GetFolder(sBackupPath).Files
ofso.DeleteFile oFile.Path, True
Next
End If
If ofso.FolderExists(sBackupPath) = False Then
ofso.CreateFolder sBackupPath
End If
For Each oFile In ofso.GetFolder(sOutlook).Files
If ofso.FileExists(oFile.Path) Then
ofso.CopyFile oFile.Path, sBackupPath, True
End If
Next
Set ofso = Nothing
End Sub
Sub OpenOutlook()
Set objShell = CreateObject("WScript.Shell")
objShell.Run "Outlook.exe"
End Sub
好像您计划脚本。 您需要以执行脚本的用户启动任务,该脚本对PST文件以及存储备份的路径具有权限。 仅使用系统帐户运行它是不够的。
还有更好的方法来备份PST文件,我使用Ruby脚本将本地副本与备份副本同步,在PST超过10GB的大文件上运行而没有问题,如果使用这样的副本进行操作可能会出现问题。
您还需要将副本备份到备份介质上,因为当PST出错(并且所有大型PST都有)时,您会将错误复制到备份上,并且可能会丢失两者。
另外,您执行以下操作
BackupPath = "\\ttad-1\Gemensam\Outlook_Backup\Daniel Elmnäs"
...
BackupPath = BackupPath & ArchiveFolder & "\"
两个第一个变量之间的\\在哪里?
我在尝试使用 VBS 删除文件时遇到了类似的问题。 我假设与我的情况一样:问题的根源是脚本试图对具有Read-only Attribute的文件或文件夹执行某些操作。 要手动解决此问题,您可以左键单击 -> 属性 -> 取消单击只读属性,然后脚本应复制文件/文件夹。 要解决 VBS 的问题:我假设文件/文件夹设置为只读,因为当前有一个程序正在使用它们。
一:这次我们可以跳过设置为只读的文件/文件夹,并希望在下次脚本运行时获取它们。 为此,我们首先检查文件/文件夹是否为只读(我从这里得到: https://social.tec.net.microsoft.com/Forums/ie/en-US/7382d452-1ef9-404a-8874- 48d38fcfe911/vbscript-verify-if-a-file-is-readonly?forum=ITCG ),如果不是,则我们执行复制操作。
Sub BackupPST(pst, BackupPath, KeepHistory)
'........
For Each pstPath in pst
If fso.FileExists(pstPath) Then
If not (fso.GetFile(pstPath).Attributes AND 1) Then 'if item is not read-only
fso.CopyFile pstPath, BackupPath, True
End If
End If
Next
Set fso = Nothing
End SubSub
二:至少这应该可以防止您收到错误。 但是,如果脚本即使在运行多次后也从不移动文件,那么文件(您尝试移动)可能始终处于只读状态,您应该更改文件的属性(您尝试移动)调用副本 function 之前的脚本,请在此处查看操作方法: https://devblogs.microsoft.com/scripting/how-can-i-change-a-read-only-file-to-a-read-write-文件/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.