[英]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.