【问题标题】:vbscript filesystemobject permission deniedvbscript 文件系统对象权限被拒绝
【发布时间】:2011-01-24 14:07:26
【问题描述】:

趋势防毒墙网络版模式填满 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

【问题讨论】:

  • 从注册表项返回的实际路径值是多少?

标签: vbscript


【解决方案1】:

这是工作脚本,对任何可能觉得有用的人进行了一些更改:

    '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

【讨论】:

    猜你喜欢
    • 2019-01-18
    • 1970-01-01
    • 1970-01-01
    • 2019-08-24
    • 2019-08-16
    • 2015-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多