on error resume next
'Option Explicit
Dim MonthName, YearName,DateName , CurrentDate , NVIGILFolderName , Diff ,
FormattedNVIGILFolderName
Dim objShell, oFSO, LogFile, objWMIService, XP
Set objShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set LogFile =oFSO.OpenTextFile("C:\NCRLogs\IndiaSecurityPolicy.log", 8, True)
' Setting permission for EJBackup folder in secondary drive
SetPermissions "N:\EJBackup","F", "SSTAuto"
SetPermissions "M:\EJBackup","F", "SSTAuto"
' This permission is required for NVigil to create and delete folders in secure
mode.
SetPermissions "N:\NVigil","F", "SSTAuto"
SetPermissions "M:\NVigil","F", "SSTAuto"
Sub SetPermissions(ResourcePath, Access, User)
If Access <> "W" And Access <> "C" And Access <> "F" Then ' Default access
to read if invalid value is specified.
Access = "RX"
End If
If User <> "Administrators" Then
User = "SSTAuto"
End If
If oFSO.FolderExists(ResourcePath) Then
If XP = True Then
LogFile.WriteLine Now & ": SetFolderAccess : cacls """ &
ResourcePath & """ /E /G " & User & ":" & Access & " /T"
objShell.Run "cacls """ & ResourcePath & """ /E /G " & User & ":"
& Access & " /T", 1, True 'Works in XP and W7. Deprecated in W7
Else
LogFile.WriteLine Now & ": SetFolderAccess : icacls """ &
ResourcePath & """ /grant "& User & ":" & Access & " /T /C /Q"
objShell.Run "icacls """ & ResourcePath & """ /grant "& User &
":" & Access & " /T /C /Q", 1, True 'Does not work in XP
objShell.Run "icacls """ & ResourcePath & """ /grant "& User & ":
(OI)(CI)(IO)" & Access & " /T /C /Q", 1, True 'Does not work in XP
End If
End If
End Sub
DeleteOldImages("N:\NVIGIL\")
LogFile.WriteLine Now & " : Setting permission to N:"
DeleteOldImages("M:\NVIGIL\")
LogFile.WriteLine Now & " : Setting permission to M:"
'Get the current Date of the system
Function DeleteOldImages(Path)
CurrentDate = now
CurrentDate = FormatDateTime(CurrentDate,2)
Dim oFolder, oSubFolder, folder
Set oFolder = oFSO.GetFolder(path) ' get the folder
Set oSubFolder = oFolder.SubFolders ' get all the sub folders in the folder cam1
' get for all the subfolders name in the folder
For Each folder in oSubFolder
'formatting accordidng to requirement
NVIGILFolderName = folder.name
YearName = Mid(NVIGILFolderName,1,4)
DateName = Right(NVIGILFolderName,2)
Monthname = Mid(NVIGILFolderName,6,2)
FormattedNVIGILFolderName = YearName & "-" & MonthName &"-"& DateName
x = isnumeric(YearName)
if x = true then
' Get the difference of days between the dates
diff = DateDiff("y", FormattedNVIGILFolderName, CurrentDate)
If diff > 0 And Day(CurrentDate) < Day(FormattedNVIGILFolderName)
Then diff = diff - 1
If NVIGILFolderName <> "" then
If diff > 60 then
oFSO.deleteFolder(path&NVIGILFolderName)
End if
end if
Next
end Function
LogFile.WriteLine Now & " : Deleting run registry Nvigil_Date_Permission entry"
objShell.run "REG DELETE ""HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\
CurrentVersion\Run"" /v Nvigil_Date_Permission /f"
'objShell.run "REG add ""HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\
CurrentVersion\RunOnceEx\1"" /v DeleteNvigilPermission_Script /d ""C:\Program
Files\NCR\DeleteNvigilPermission_Script.vbs /f"""
LogFile.Close
Set LogFile = Nothing
Set oFSO = Nothing
Set objShell = Nothing