简体   繁体   English

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

[英]Getting a permission denied error when running _zipit.vbs from a batch file

I have a batch file that I'd like to use to collect some log files and then zip them up into a directory for the user. 我有一个批处理文件,我想用它来收集一些日志文件,然后将它们压缩到用户的目录中。 When I run the file I get the error 运行文件时出现错误

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

This happens on Windows 7 and Windows 10. I have tried running the .bat as administrator and with administrator permissions. 在Windows 7和Windows 10上会发生这种情况。我尝试以管理员身份并具有管理员权限运行.bat。 I have run it from cmd and from the windows explorer. 我已经从cmd和Windows资源管理器中运行了它。 I've tried pre-creating the folder(s) and granting full permissions. 我尝试过预先创建文件夹并授予完全权限。

Is there a way to avoid this error message? 有办法避免此错误消息吗? Here is the code being used 这是正在使用的代码

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

I solved the problem with the code. 我用代码解决了问题。 It was this line 是这条线

CScript _zipIt.vbs %TEMPDIR% C:\\SLW_LogFiles CScript _zipIt.vbs%TEMPDIR%C:\\ SLW_LogFiles

passing the variable TEMPDIR to the CScript was causing the error message Hard coding the path solved the problem 将变量TEMPDIR传递给CScript导致错误消息硬编码路径解决了问题

here is the correct code 这是正确的代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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