简体   繁体   English

vbscript 权限被拒绝 800a0046.network

[英]vbscript permission denied 800a0046 network

I made a script that copying a file to a certain location.我制作了一个脚本,将文件复制到某个位置。 I add the.vbs to taskschd.msc scheduled for make a.pst backup but I get error message我将 .vbs 添加到计划进行 a.pst 备份的 taskschd.msc,但我收到错误消息

Line: 91 Char: 7 Error: Permission denied Code: 800A0046 Source: Microsoft VBScript runtime error行: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>

Could someone help me to solve this?有人可以帮我解决这个问题吗?

Thank you in advance先感谢您

EDITED: Change the permissions of the folder. 编辑:更改文件夹的权限。

  1. In windows explorer, navigate to the folder where the PST file is located. 在Windows资源管理器中,导航到PST文件所在的文件夹。
  2. In the left pane of windows explorer, right click on the folder where the PST file is located, select "Properties". 在Windows资源管理器的左窗格中,右键单击PST文件所在的文件夹,然后选择“属性”。
  3. Select the "Security" tab 选择“安全性”标签
  4. Click the button "Edit" to change permissions. 单击按钮“编辑”以更改权限。
  5. Click "Add" 点击“添加”
  6. In the object names to select box, enter "everyone" (no quotes). 在要选择的对象名称框中,输入“所有人”(不带引号)。
  7. Click "Check Names", everyone should become capitalized and underlined. 单击“检查名称”,每个人都应大写并加下划线。
  8. Click "Ok" 点击“确定”
  9. Select "Everyone" from the list of Groups or user names. 从组或用户名列表中选择“所有人”。
  10. In the "Permissions for Everyone" list, make sure "Read & Execute, List folder contents and Read, in the allow column are checked, click "Apply" 在“所有人的权限”列表中,确保选中“读取并执行,列出文件夹内容和读取,在允许列中,单击”应用”
  11. Click Ok. 单击确定。

NOTE: By doing this, anyone who has access to this computer can access the folder. 注意:这样,任何有权访问此计算机的人都可以访问该文件夹。 You might consider only adding your login to the computer to the list of Groups or usernames instead of Everyone. 您可能考虑只将登录名添加到计算机的“组”或用户名列表中,而不是“所有人”。 You may have to repeat the above steps on the PST file(s) in question. 您可能必须在有问题的PST文件上重复上述步骤。

Original Post: 原始帖子:

I ran the script here, testing for various issues and it ran without problems. 我在这里运行脚本,测试了各种问题,并且没有问题。 At this point I believe the issue is rights and permissions to either the source or destination folder (or the files you are backing up). 目前,我认为问题是源文件夹或目标文件夹(或要备份的文件)的权限。 By default, the user's themselves don't have access to Outlooks data files. 默认情况下,用户自己无权访问Outlook数据文件。 You would need to add "read" permissions to the files in question (PST,OST, and so on) or the full folder. 您需要为相关文件(PST,OST等)或完整文件夹添加“读取”权限。 In reality, just backing up the PST files isn't enough to restore an Outlook configuration; 实际上,仅备份PST文件不足以恢复Outlook配置。 you would need all of the files. 您将需要所有文件。 You can Try this: 您可以尝试以下方法:

'===================================================================
'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

Seems like you schedule the script. 好像您计划脚本。 You need to start the task with a user that executes the script which has rights on the PST file, as well as on the path where you store the backup. 您需要以执行脚本的用户启动任务,该脚本对PST文件以及存储备份的路径具有权限。 Running it with the system account won't be enough. 仅使用系统帐户运行它是不够的。

There are better ways to backup PST files also, I use a Ruby script to synchronise a local copy with a backup copy, is runs on PST's more than 10GB big without problem, might be a problem if you would do it with a copy like this. 还有更好的方法来备份PST文件,我使用Ruby脚本将本地副本与备份副本同步,在PST超过10GB的大文件上运行而没有问题,如果使用这样的副本进行操作可能会出现问题。

You need to backup the copy on a backup medium also because when the PST has errors (and all big PST have) you copy the errors to the backup and could lose both. 您还需要将副本备份到备份介质上,因为当PST出错(并且所有大型PST都有)时,您会将错误复制到备份上,并且可能会丢失两者。

Also, you do the following 另外,您执行以下操作

BackupPath = "\\ttad-1\Gemensam\Outlook_Backup\Daniel Elmnäs"
...
BackupPath = BackupPath & ArchiveFolder & "\"

Where is the \\ between the two first variables ? 两个第一个变量之间的\\在哪里?

I had a similar problem trying to delete files with VBS.我在尝试使用 VBS 删除文件时遇到了类似的问题。 I assume that as with my case: The source of the problem is that the script is trying to perform some operation on a file or folder that has a Read-only Attribute .我假设与我的情况一样:问题的根源是脚本试图对具有Read-only Attribute的文件或文件夹执行某些操作 To solve this manually you could left click -> properties -> unclick the Read-Only Attribute then the file/folder should be copied by the script.要手动解决此问题,您可以左键单击 -> 属性 -> 取消单击只读属性,然后脚本应复制文件/文件夹。 To solve the problem with VBS: I make the assumption that file/folder is set to Read-Only because there is a programme currently using them.要解决 VBS 的问题:我假设文件/文件夹设置为只读,因为当前有一个程序正在使用它们。

One : we can just skip files/folders set to read-only this time and hope to get them next time the script runs.:这次我们可以跳过设置为只读的文件/文件夹,并希望在下次脚本运行时获取它们。 For this we first check if file/folder is read-only (I got this from here: https://social.tec.net.microsoft.com/Forums/ie/en-US/7382d452-1ef9-404a-8874-48d38fcfe911/vbscript-verify-if-a-file-is-readonly?forum=ITCG ), if not then we perform the copy operation.为此,我们首先检查文件/文件夹是否为只读(我从这里得到: 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

Two : At the very least this should prevent you from getting the error.:至少这应该可以防止您收到错误。 But if the script never moves the files even after running a number of times then chances are that the files (you are trying to move) are always in read only and you should change Attribute of the file (you are trying to move) in your script before calling the copy function, see how to do that here: https://devblogs.microsoft.com/scripting/how-can-i-change-a-read-only-file-to-a-read-write-file/但是,如果脚本即使在运行多次后也从不移动文件,那么文件(您尝试移动)可能始终处于只读状态,您应该更改文件的属性(您尝试移动)调用副本 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM