从批处理文件运行_zipit.vbs时获取权限被拒绝错误

时间:2016-10-24 12:44:26

标签: batch-file vbscript windows-7 zip windows-10

我有一个批处理文件,我想用它来收集一些日志文件,然后将它们压缩到用户的目录中。当我运行文件时,我收到错误

  

_zipIt.vbs(4,1)Microsoft VBScript运行时错误:权限被拒绝

这种情况发生在Windows 7和Windows 10上。我尝试以管理员身份运行.bat并具有管理员权限。我从cmd和Windows资源管理器运行它。我尝试过预先创建文件夹并授予完整权限。

有没有办法避免此错误消息?这是使用的代码

Echo off 

Echo Gathering up the SolidWorks Logging files

REM Get XML Debug Dump Directory
FOR /F "skip=2 tokens=2,*" %%A IN ('reg.exe query        "HKEY_LOCAL_MACHINE\SOFTWARE\Dassault Systemes\SolidWorksPDM" /v DebugDir') DO set "XMLDIR=%%B"

REM Make the directory and subdirectories for the results
mkdir C:\Collected_Logs
mkdir C:\Collected_Logs\xmldump
mkdir C:\Collected_Logs\IEF
mkdir C:\Collected_Logs\SLW
mkdir C:\Collected_Logs\COG
mkdir C:\Collected_Logs\COG
mkdir C:\SLW_LogFiles
icacls "C:\SLW_LogFiles" /grant %USERNAME%:(OI)(CI)F /T

REM Gather the log files
xcopy /q C:\Users\%USERNAME%\ENOVIASolidWorksInteg C:\Collected_Logs\SLW
xcopy /q C:\%XMLDIR% C:\Collected_Logs\xmldump 
xcopy /q C:\Users\Administrator\ief\logs C:\Collected_Logs\IEF
xcopy /q C:\Users\%USERNAME%\appdata\local\ief C:\Collected_Logs\IEF
xcopy /q "C:\Users\%USERNAME%\AppData\Local\Dassault Systemes\Connector for   SOLIDWORKS" "C:\Collected_Logs\COG"
GOTO ZIPIT

:ZIPIT
set TEMPDIR=C:\tempzip    
mkdir %TEMPDIR% 

icacls "%TEMPDIR%" /grant %USERNAME%: (OI)(CI)F /T

xcopy /q /e C:\Collected_Logs %TEMPDIR%
Echo Set objArgs = WScript.Arguments > _zipIt.vbs
Echo InputFolder = objArgs(0) >> _zipIt.vbs
Echo ZipFile = objArgs(1) >> _zipIt.vbs
Echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile,   True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> _zipIt.vbs
Echo Set objShell = CreateObject("Shell.Application") >> _zipIt.vbs
Echo Set source = objShell.NameSpace(InputFolder).Items >> _zipIt.vbs
Echo objShell.NameSpace(ZipFile).CopyHere(source) >> _zipIt.vbs
Echo wScript.Sleep 2000 >> _zipIt.vbs
CScript  _zipIt.vbs %TEMPDIR%  C:\SLW_LogFiles

REM Pause briefly to allow ZIPIT to finish
PING 1.1.1.1 -n 1 -w 600 >NUL

REM Clean up the temporary directories we created
rmdir /S /Q %TEMPDIR%
rmdir /S /Q C:\Collected_Logs

Echo The log files have been zipped up and placed in the directory C:\SLW_LogFiles

1 个答案:

答案 0 :(得分:0)

我用代码解决了问题。就是这条线

CScript _zipIt.vbs%TEMPDIR%C:\ SLW_LogFiles

将变量TEMPDIR传递给CScript导致错误消息硬编码路径解决了问题

这是正确的代码

Echo Set objArgs = WScript.Arguments > _zipIt.vbs
Echo InputFolder = objArgs(0) >> _zipIt.vbs
Echo ZipFile = objArgs(1) >> _zipIt.vbs
Echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> _zipIt.vbs
Echo Set objShell = CreateObject("Shell.Application") >> _zipIt.vbs
Echo Set source = objShell.NameSpace(InputFolder).Items >> _zipIt.vbs
Echo objShell.NameSpace(ZipFile).CopyHere(source) >> _zipIt.vbs
Echo wScript.Sleep 2000 >> _zipIt.vbs

CScript  _zipIt.vbs  C:\Collected_Logs  C:\SLW_LogFiles\Logs.zip