2011-01-24 4 views
0

Je rencontre un problème avec les modèles Trend OfficeScan qui remplissent le lecteur C: \ (aucun autre lecteur disponible pour changer de répertoire) et j'obtiens une erreur d'autorisation refusée en accédant à "C: \ Program Files \ Trend Micro \ OfficeScan \ PCCSRV \ WSS \ patterns "exécutant le script ci-dessous. Comme je vais utiliser ce script pour quelques sites, et pour le rendre facile à mettre en œuvre pour mes collègues, je ne veux pas jouer avec l'ajout de diverses autorisations.Autorisation vbscript filesystemobject refusée

J'ai essayé de changer: PatternLocation = (strValue & "WSS\patterns\") à PatternLocation = ("""" & strValue & "WSS\patterns\""") et j'obtiens 'Chemin non trouvé'. Y at-il des experts VBScript qui peuvent être en mesure de recommander une méthode d'emprunt d'identité pour surmonter les autorisations refusées?

' 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 
+0

Quelle est la valeur de chemin réel retour de la clé de Registre? – unrealtrip

Répondre

0

Ceci est le script de travail avec quelques changements pour tous ceux qui pourraient trouver utile:

'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