![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | folderLastAccessed script (Access is denied) I have written the following script to be able to find out the last time our shared folders were accessed. I would like to get it to work so that I can specify the letter of a network drive I have mapped and it will return the last time all of the first level folders were accessed. When I try to execute it by specifying a letter (H:\ or S: \) I get accessed is denied. But when I specify one of the root folders (H:\Folder1) it will work fine. Anyone know why this may be happening? Option Explicit Dim WshShell Dim fs, f, s, strfolder, oFolder, folderLastAccessed, subfolders, objExcel, objSheet, strExcelPath, strFolderProd Dim objNet, strDomain, strUserName Set WshShell = WScript.CreateObject("WScript.Shell") Set fs = CreateObject("Scripting.FileSystemObject") strFolder = "\\sr42alpine\dkaloust$" Set f = fs.GetFolder(strFolder) CreateExcelSpreadsheet strfolder Dim folderAmount folderAmount = 1 For Each oFolder In fs.GetFolder(strFolder).SubFolders folderAmount = folderAmount + 1 folderLastAccessed = UCase(strFolder & oFolder.Name) & vbCrLf folderLastAccessed = f.DateLastAccessed 's = UCase(strFolder & oFolder.Name) & VbCrLf _ ' & "Created: " & oFolder.DateCreated & VbCrLf _ '& "Last Accessed: " & oFolder.DateLastAccessed & VbCrLf _ '& "Last Modified: " & oFolder.DateLastModified 'WScript.Echo s 'WScript.Echo folderAmount UpdateExcelSpreadsheet strfolder, folderAmount Next GetUserName CloseExcelSpreadsheet folderLastAccessed = UCase(strFolderProd) & vbCrLf folderLastAccessed = f.DateLastAccessed 'strExcelPath = "C:\Documents and Settings\dkaloust\Desktop\New Folder \TestFolderScript.xls" 'Creates Excel Spreadsheet Sub CreateExcelSpreadsheet(strFolderProd) Set objExcel = CreateObject("Excel.Application") ' Create a new workbook objExcel.Workbooks.Add ' Bind to worksheet Set objSheet = objExcel.ActiveWorkbook.Worksheets(1) ' Naming worksheet objSheet.Name = "File Shares" 'Formatting Excel Columns objExcel.Columns(1).ColumnWidth = 50 objExcel.Columns(2).ColumnWidth = 50 ' Populate spreadsheet cells with information objSheet.Cells (1, 1).Value = "Folder" '(Row #, Column#) objSheet.Cells (1, 2).Value = "Date Last Accessed" End Sub 'Sub routine to update spreadsheet with values Sub UpdateExcelSpreadsheet(strFolderProd, folderAmount) 'Int folderAmount objSheet.Cells (folderAmount, 1).Value = oFolder objSheet.Cells (folderAmount, 2).Value = folderLastAccessed End Sub 'Subroutine to save and close excel workbook Sub CloseExcelSpreadsheet() 'Debugging code to make sure strUseName variable is being passed and accepted at location 'WScript.Echo "Returning" & strUserName & "Yay" strExcelPath = "C:\Documents and Settings\" & strUsername &"\Desktop \TestFolderScript.xls" objExcel.ActiveWorkbook.SaveAs strExcelPath ' Saves excel spreadsheet objExcel.ActiveWorkbook.Close ' Closes workbook objExcel.Application.Quit 'Quits the excel application End Sub ' Subroutine to get the username of the user running the script Sub GetUserName() Set objNet = WScript.CreateObject("WScript.Network")' create network object for vars strDomain = UCase(objNet.UserDomain)' pull user domain from environment variable strUserName = UCase(objNet.UserName)' pull user name from environment variable End Sub WScript.Echo "Done" |
My System Specs![]() |
| | #2 (permalink) |
| | Re: folderLastAccessed script (Access is denied) <dkaloustian@xxxxxx> wrote in message news:7f8b7be8-f15e-4c46-b3ab-083383dc1889@xxxxxx Quote: >I have written the following script to be able to find out the last > time our shared folders were accessed. I would like to get it to work > so that I can specify the letter of a network drive I have mapped and > it will return the last time all of the first level folders were > accessed. When I try to execute it by specifying a letter (H:\ or S: > \) I get accessed is denied. But when I specify one of the root > folders (H:\Folder1) it will work fine. Anyone know why this may be > happening? > > Option Explicit > Dim WshShell > Dim fs, f, s, strfolder, oFolder, folderLastAccessed, subfolders, > objExcel, objSheet, strExcelPath, strFolderProd > Dim objNet, strDomain, strUserName > > > Set WshShell = WScript.CreateObject("WScript.Shell") > Set fs = CreateObject("Scripting.FileSystemObject") > > strFolder = "\\sr42alpine\dkaloust$" > > Set f = fs.GetFolder(strFolder) > > CreateExcelSpreadsheet strfolder > > Dim folderAmount > folderAmount = 1 > > For Each oFolder In fs.GetFolder(strFolder).SubFolders > > folderAmount = folderAmount + 1 > > folderLastAccessed = UCase(strFolder & oFolder.Name) & vbCrLf > folderLastAccessed = f.DateLastAccessed > > 's = UCase(strFolder & oFolder.Name) & VbCrLf _ > ' & "Created: " & oFolder.DateCreated & VbCrLf _ > '& "Last Accessed: " & oFolder.DateLastAccessed & VbCrLf _ > '& "Last Modified: " & oFolder.DateLastModified > 'WScript.Echo s > 'WScript.Echo folderAmount > > UpdateExcelSpreadsheet strfolder, folderAmount > > > > Next > > GetUserName > > CloseExcelSpreadsheet > > folderLastAccessed = UCase(strFolderProd) & vbCrLf > folderLastAccessed = f.DateLastAccessed > > 'strExcelPath = "C:\Documents and Settings\dkaloust\Desktop\New Folder > \TestFolderScript.xls" > > 'Creates Excel Spreadsheet > > Sub CreateExcelSpreadsheet(strFolderProd) > > Set objExcel = CreateObject("Excel.Application") > > ' Create a new workbook > > objExcel.Workbooks.Add > > ' Bind to worksheet > > Set objSheet = objExcel.ActiveWorkbook.Worksheets(1) > > ' Naming worksheet > > objSheet.Name = "File Shares" > > 'Formatting Excel Columns > > objExcel.Columns(1).ColumnWidth = 50 > objExcel.Columns(2).ColumnWidth = 50 > > ' Populate spreadsheet cells with information > > objSheet.Cells (1, 1).Value = "Folder" > '(Row #, Column#) > objSheet.Cells (1, 2).Value = "Date Last Accessed" > > End Sub > > 'Sub routine to update spreadsheet with values > > Sub UpdateExcelSpreadsheet(strFolderProd, folderAmount) > > 'Int folderAmount > > objSheet.Cells (folderAmount, 1).Value = oFolder > objSheet.Cells (folderAmount, 2).Value = folderLastAccessed > > End Sub > > 'Subroutine to save and close excel workbook > > Sub CloseExcelSpreadsheet() > > 'Debugging code to make sure strUseName variable is being passed and > accepted at location > 'WScript.Echo "Returning" & strUserName & "Yay" > > strExcelPath = "C:\Documents and Settings\" & strUsername &"\Desktop > \TestFolderScript.xls" > > objExcel.ActiveWorkbook.SaveAs strExcelPath ' Saves excel spreadsheet > objExcel.ActiveWorkbook.Close ' Closes workbook > objExcel.Application.Quit 'Quits the excel application > > End Sub > > ' Subroutine to get the username of the user running the script > > Sub GetUserName() > > Set objNet = WScript.CreateObject("WScript.Network")' create network > object for vars > > strDomain = UCase(objNet.UserDomain)' pull user domain from > environment variable > strUserName = UCase(objNet.UserName)' pull user name from environment > variable > > End Sub > > WScript.Echo "Done" accessed. There is no such information available for a drive letter - you MUST specify a folder name. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: folderLastAccessed script (Access is denied) On Nov 21, 11:22*am, "Pegasus \(MVP\)" <I....@xxxxxx> wrote: Quote: > <dkaloust...@xxxxxx> wrote in message > > news:7f8b7be8-f15e-4c46-b3ab-083383dc1889@xxxxxx > > > > > Quote: > >I have written the following script to be able to find out the last > > time our shared folders were accessed. *I would like to get it to work > > so that I can specify the letter of a network drive I have mapped and > > it will return the last time all of the first level folders were > > accessed. *When I try to execute it by specifying a letter (H:\ or S: > > \) I get accessed is denied. *But when I specify one of the root > > folders (H:\Folder1) it will work fine. *Anyone know why this may be > > happening? Quote: > > Option Explicit > > Dim WshShell > > Dim fs, f, s, strfolder, oFolder, folderLastAccessed, subfolders, > > objExcel, objSheet, strExcelPath, strFolderProd > > Dim objNet, strDomain, strUserName Quote: > > Set WshShell = WScript.CreateObject("WScript.Shell") > > Set fs = CreateObject("Scripting.FileSystemObject") Quote: > > strFolder = "\\sr42alpine\dkaloust$" Quote: > > Set f = fs.GetFolder(strFolder) Quote: > > CreateExcelSpreadsheet strfolder Quote: > > Dim folderAmount > > folderAmount = 1 Quote: > > For Each oFolder In fs.GetFolder(strFolder).SubFolders Quote: > > folderAmount = folderAmount + 1 Quote: > > folderLastAccessed = UCase(strFolder & oFolder.Name) & vbCrLf > > folderLastAccessed = f.DateLastAccessed Quote: > > 's = UCase(strFolder & oFolder.Name) & VbCrLf _ > > *' & "Created: " & oFolder.DateCreated & VbCrLf _ > > * '& "Last Accessed: " & oFolder.DateLastAccessed & VbCrLf _ > > * '& "Last Modified: " & oFolder.DateLastModified > > *'WScript.Echo s > > *'WScript.Echo folderAmount Quote: > > *UpdateExcelSpreadsheet strfolder, folderAmount Quote: > > Next Quote: > > GetUserName Quote: > > CloseExcelSpreadsheet Quote: > > folderLastAccessed = UCase(strFolderProd) & vbCrLf > > folderLastAccessed = f.DateLastAccessed Quote: > > 'strExcelPath = "C:\Documents and Settings\dkaloust\Desktop\New Folder > > \TestFolderScript.xls" Quote: > > 'Creates Excel Spreadsheet Quote: > > Sub CreateExcelSpreadsheet(strFolderProd) Quote: > > Set objExcel = CreateObject("Excel.Application") Quote: > > ' Create a new workbook Quote: > > objExcel.Workbooks.Add Quote: > > ' Bind to worksheet Quote: > > Set objSheet = objExcel.ActiveWorkbook.Worksheets(1) Quote: > > ' Naming worksheet Quote: > > objSheet.Name = "File Shares" Quote: > > 'Formatting Excel Columns Quote: > > objExcel.Columns(1).ColumnWidth = 50 > > objExcel.Columns(2).ColumnWidth = 50 Quote: > > ' Populate spreadsheet cells with information Quote: > > objSheet.Cells (1, 1).Value = "Folder" > > '(Row #, Column#) > > objSheet.Cells (1, 2).Value = "Date Last Accessed" Quote: > > End Sub Quote: > > 'Sub routine to update spreadsheet with values Quote: > > Sub UpdateExcelSpreadsheet(strFolderProd, folderAmount) Quote: > > 'Int folderAmount Quote: > > objSheet.Cells (folderAmount, 1).Value = oFolder > > objSheet.Cells (folderAmount, 2).Value = folderLastAccessed Quote: > > End Sub Quote: > > 'Subroutine to save and close excel workbook Quote: > > Sub CloseExcelSpreadsheet() Quote: > > 'Debugging code to make sure strUseName variable is being passed and > > accepted at location > > 'WScript.Echo "Returning" & strUserName & "Yay" Quote: > > strExcelPath = "C:\Documents and Settings\" & strUsername &"\Desktop > > \TestFolderScript.xls" Quote: > > objExcel.ActiveWorkbook.SaveAs strExcelPath ' Saves excel spreadsheet > > objExcel.ActiveWorkbook.Close ' Closes workbook > > objExcel.Application.Quit 'Quits the excel application Quote: > > End Sub Quote: > > ' Subroutine to get the username of the user running the script Quote: > > Sub GetUserName() Quote: > > Set objNet = WScript.CreateObject("WScript.Network")' create network > > object for vars Quote: > > strDomain = UCase(objNet.UserDomain)' pull user domain from > > environment variable > > strUserName = UCase(objNet.UserName)' pull user name from environment > > variable Quote: > > End Sub Quote: > > WScript.Echo "Done" > The LastAccessed method returns the date when a file or folder was last > accessed. There is no such information available for a drive letter - you > MUST specify a folder name.- Hide quoted text - > > - Show quoted text - folder path as "\\servername\folder". Would that not work either? Do you have any suggestions on how to try and accomplish what I want to do? I have hundreds of DFS pointers on one file server to the folder locations on different file servers and I want to be able to return that information quickly and hopefully painlessly, so that we can run some maintenance if needed. Any suggestions would be much appreciated. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: folderLastAccessed script (Access is denied) See below. <dkaloustian@xxxxxx> wrote in message news:72dcf972-eb49-4c01-af3c-eb524ff1e6ea@xxxxxx On Nov 21, 11:22 am, "Pegasus \(MVP\)" <I....@xxxxxx> wrote: Quote: > <dkaloust...@xxxxxx> wrote in message folder path as "\\servername\folder". Would that not work either? *** Because \\ServerName\Folder is a share, same as before. *** Calling it "Folder" does not make it a folder! Try this instead: *** \\ServerName\ShareName\FolderName Do you have any suggestions on how to try and accomplish what I want to do? I have hundreds of DFS pointers on one file server to the folder locations on different file servers and I want to be able to return that information quickly and hopefully painlessly, so that we can run some maintenance if needed. Any suggestions would be much appreciated. *** Use the FSO object to obtain a list of all folders on the specified *** share, then examine each folder in turn. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| folderLastAccessed script | VB Script | |||
| can't open access control editor. Access is denied | General Discussion | |||
| Access Denied, Access Denied- like a broken record! | Vista General | |||
| When standard users access Vista registry remotely, Access Denied | Vista account administration | |||
| Access is denied message when trying to access a remote printer | Vista print fax & scan | |||