簡體   English   中英

vbscript文件系統對象權限被拒絕

[英]vbscript filesystemobject permission denied

我在趨勢科技防毒牆網絡版病毒碼填充C:\\驅動器(沒有其他驅動器可用於更改目錄)時遇到問題,並且訪問“ C:\\ Program Files \\ Trend Micro \\ OfficeScan \\ PCCSRV \\”時遇到權限被拒絕的錯誤WSS \\ patterns”運行以下腳本。 由於我將在少數幾個站點中使用此腳本,並且為了使其易於實現,所以我不想添加各種權限。

我嘗試將: PatternLocation = (strValue & "WSS\\patterns\\")更改為PatternLocation = ("""" & strValue & "WSS\\patterns\\""") ,我得到了“找不到路徑”。 是否有任何VBScript專家可以推薦一種模擬方法來克服被拒絕的權限?

' Variable to locate HLM.
const HKEY_LOCAL_MACHINE = &H80000002
Set fso = CreateObject("Scripting.FileSystemObject") 

' Checks if the operating system is x86 or x64
Set objShell = CreateObject("WScript.Shell")
osType = objShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")

' The dot refers to the computer this vbscript has been run on.
strComputer = "."

' Provides connection to the registry.
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

' Checks the bit for the operating system
If osType = "x86" Then
    ' Checks registry for Trend folder path.
    strKeyPath = "SOFTWARE\TrendMicro\OfficeScan\Service\Information"
Elseif osType = "AMD64" Then
    strKeyPath = "SOFTWARE\Wow6432Node\TrendMicro\OfficeScan\service\Information"
End if

trValueName = "Local_Path"
objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

' If the registry path is empty it won't install the scheduled task and alert you.
If IsNull(strValue) Then
    msgbox("Trend Micro is not installed.")
else
    PatternLocation = (strValue  &  "WSS\patterns\") ' folder to start deleting (subfolders will also be cleaned) 
    OlderThanDate = DateAdd("d", -2, Date)  ''# 2 days (adjust as necessary)
    DeleteOldFiles PatternLocation, OlderThanDate 
end if

Function DeleteOldFiles(folderName, BeforeDate) 
    Dim folder, file, fileCollection, folderCollection, subFolder 

    Set folder = fso.GetFolder(folderName) 
    Set fileCollection = folder.Files 
    For Each file In fileCollection 
        If file.DateLastModified < BeforeDate Then 
            fso.DeleteFile(file.Path) 
            End If 
    Next 

    Set folderCollection = folder.SubFolders 
    For Each subFolder In folderCollection 
        DeleteOldFiles subFolder.Path, BeforeDate 
    Next 
End Function

這是工作腳本,對可能會發現有用的任何人進行了一些更改:

    'Variable to locate HLM.
const HKEY_LOCAL_MACHINE = &H80000002
Set fso = CreateObject("Scripting.FileSystemObject") 

'Checks if the operating system is x86 or x64
Set objShell = CreateObject("WScript.Shell")
osType = objShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")

'The dot refers to the computer this vbscript has been run on.
strComputer = "."

'Provides connection to the registry.
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

 'Checks the bit for the operating system
If osType = "x86" Then
                'Checks registry for Trend folder path.
                strKeyPath = "SOFTWARE\TrendMicro\OfficeScan\Service\Information"
Elseif osType = "AMD64" Then
                strKeyPath = "SOFTWARE\Wow6432Node\TrendMicro\OfficeScan\service\Information"
End if
                strValueName = "Local_Path"
                objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue



'If the registry path is empty it won't install the scheduled task and alert you.
If IsNull(strValue) Then
                msgbox("Trend Micro is not installed.")

else

                PatternLocation = (strValue  &  "WSS\patterns") ' folder to start deleting (subfolders will also be cleaned) 
                'msgbox(PatternLocation)        
end if


startFolder = PatternLocation
OlderThanDate = DateAdd("d", -1, Date) ' 1 days  
DeleteOldFiles startFolder, OlderThanDate  
DeleteEmptyFolders startFolder

Function DeleteOldFiles(folderName, BeforeDate)  
Dim folder, file, fileCollection, folderCollection, subFolder  
Set folder = fso.GetFolder(folderName)  
Set fileCollection = folder.Files  
For Each file In fileCollection     
If file.DateLastModified < BeforeDate Then          
fso.DeleteFile(file.Path)   
End If  
Next  
Set folderCollection = folder.SubFolders  
For Each subFolder In folderCollection      
DeleteOldFiles subFolder.Path, BeforeDate  
Next  
End Function   
Function DeleteEmptyFolders(foldername)  
For Each Folder In fso.GetFolder(foldername).SubFolders     
DeleteEmptyFolders(Folder.Path)     
If Folder.Files.Count = 0 and Folder.SubFolders.Count = 0 Then          
fso.DeleteFolder(Folder.Path)   
End If  
Next  
End Function

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM