There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot computer connection crash css dell drive driver drivers email error ethernet excel explorer firefox firefox 3 hard drive internet internet explorer itunes laptop linux malware monitor network networking outlook outlook 2003 outlook express password printer problem problems ram router security slow software sound trojan usb virus vista windows windows vista windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
vb question...


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
yzzazz's Avatar
Junior Member with 1 posts.
 
Join Date: Aug 2006
15-Aug-2006, 12:18 PM #1
vb question...
I am trying to author a script that will return (among other things) the "Last Accessed Date" for subfolders of a given folder (nonrecursively).

The problem is that when running the script, all subfolders change their LAD to the current date and time... rendering the information useless.

Is there a way to avoid this? Code below if it helps...

Code:
strComputer = "."
Const MY_COMPUTER = &H11&
Const ForWriting = 2
Const WINDOW_HANDLE = 0
Const OPTIONS = 0

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Delete HTM if it is already present

If objFSO.FileExists("C:\SubfolderInfo.htm") Then
	objFSO.DeleteFile("C:\SubfolderInfo.htm")
End If

'Create popup window prompting user to select a drive or folder

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.Self
strPath2 = objFolderItem.Path

Set objShell = CreateObject("Shell.Application")
Set objFolderSelect = objShell.BrowseForFolder _
    (WINDOW_HANDLE, "Select a folder:", OPTIONS, strPath2) 

If objFolderSelect Is Nothing Then
    Wscript.Quit
End If

Set objFolderItem = objFolderSelect.Self

strPath = objFolderItem.Path

Set colSubfolders = objWMIService.ExecQuery _
    ("Associators of {Win32_Directory.Name='" & strPath & "'} " _
        & "Where AssocClass = Win32_Subdirectory " _
            & "ResultRole = PartComponent")

'Begin HTML file creation

Set objOutFile = objFSO.CreateTextFile("C:\SubfolderInfo.htm", ForWriting, True)
	objOutFile.writeline "<html>"
	objOutFile.writeline "<head>"
	objOutFile.writeline "<title>Subfolder Information for " & strPath & "</title>"
	objOutFile.writeline "</head>"
	objOutFile.writeline "<body>"
	objOutFile.writeline "<h1>Subfolder Information for " & strPath & "</h1>" & vbCrLf
	objOutFile.writeline "<h2>" & Now() & "</h2>" & vbCrLf
	objOutFile.writeline "<table border=1 cellpadding=6>" & vbCrLf
	objOutFile.writeline "<tr>" & vbCrLf
	objOutFile.writeline "<b><td>Folder Name</td><td>Size in MB</td><td>Last Modified</td>" & _
	"<td>Last Accessed</td></b></tr>" & vbCrLf

'Add rows and data for each subfolder

For Each objFolder in colSubfolders
   Set objFSO2 = CreateObject("Scripting.FileSystemObject")
   Set objFolder2 = objFSO2.GetFolder(objFolder.Name)
	intSizeInMB = objFolder2.Size / 1084576
	intSizeInMB = Round(intSizeInMB, 1)
	objOutFile.writeline "<tr>" & vbCrLf
	objOutFile.writeline "<td>" & objFolder2.Name & "</td><td align=" & chr(34) & "right" & _
	chr(34) & ">" & intSizeInMB & "</td><td>" & objFolder2.DateLastModified & "</td><td>" & _
	objFolder2.DateLastAccessed & "</td>" & vbCrLf
	objOutFile.writeline "</tr>" & vbCrLf
Next

'Complete HTML file creation

	objOutFile.writeline "</table>"
	objOutFile.writeline "</body>"
	objOutFile.writeline "</html>"

'Removed confirmation box

'MsgBox "Your results have been catalogued in C:\SubfolderInfo.htm",4096,"Scan Complete..."

'Display HTML file

Set objShell2 = Wscript.CreateObject("Wscript.Shell")
objShell2.Run "C:\SubfolderInfo.htm"
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 05:00 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.