Const MY_DOCUMENTS = &H5&
Const ForReading = 1
Const ForWriting = 2
Dim WshNetwork, strUsername, strComputername, Description
Dim objFolder, Drv, FilePath, strFile, FolderSize1, FolderSize2
Set WshNetwork = WScript.CreateObject("WScript.Network")
'Output to share (type unc name of the shared folder)
FilePath = "C:\Localprf\"
strUsername = WshNetwork.UserName
strComputername = WshNetwork.ComputerName
Dim objFSO, strMY_DOCUMENTS, objFile ' Global scopes
Set objFSO = CreateObject("Scripting.FileSystemObject")
With CreateObject("Shell.Application").Namespace(MY_DOCUMENTS)
strMY_DOCUMENTS = .Self.Path
Set objFolder = objFSO.GetFolder(strMY_DOCUMENTS)
drv = objFolder.drive
End With
' Determine drivetype of the My Documents Folder
Description = strUsername & "'s Documents on "
If (DriveIsLocal(drv) = True) Then
Description = Description & strComputername
Else
Description = Description & "Fileserver"
End If
strFile = FilePath & "\" & Description & ".txt"
' convert byte to megabyte (1 megabyte = 1 048 576 byte)
FolderSize1 = objFolder.Size ' bytes
FolderSize2 = RoundFormatNumber(FolderSize1/1048576, 2) ' megabytes
Set objFile = objFSO.OpenTextFile(strFile, ForWriting, True)
objFile.write FolderSize1 & ",""" & Description
objFile.writeline """,""[" & FolderSize2 & " MB]"""
objFile.close: Set objFile = Nothing
' *** merge info ***
call updateTotal '(for logon scripts this line is rem'd-out)
Function RoundFormatNumber(NumberToRound, aDecimalPlaces)
' The prefixed Round() function performs round to even.
' While this function performs round to larger.
Dim nFactor
nFactor = 10 ^ aDecimalPlaces
RoundFormatNumber = FormatNumber(Int((NumberToRound * nFactor) _
+ 0.5) / nFactor, aDecimalPlaces)
End Function
Function DriveIsLocal(drive)
DriveIsLocal = TRUE
If Not Left(drive,2) = "\\" Then
With GetObject("WinMgmts:{impersonationLevel=impersonate}" _
& "!root/cimv2:Win32_LogicalDisk='"& drive & "'")
If .DriveType = 4 Then DriveIsLocal = FALSE
End With
Else
DriveIsLocal = FALSE
End If
End Function
Sub updateTotal
' merge (this part not used in the logon script!)
Dim csvFile, WSHShell, strCommand
colFiles = FilePath & "\*'s Documents on *.txt"
csvFile = FilePath & "\MY_DOCUMENTS total size.csv"
Set WSHShell = WScript.CreateObject ("WScript.Shell")
strCommand = "cmd /c Copy /b """ & colFiles & """"
strCommand = strCommand & " """ & csvFile & """"
WSHShell.Run strCommand, 0, True
Set objFile = objFSO.OpenTextFile(csvFile, ForReading)
tt1 = 0 : iCnt = 0
Do While objFile.AtEndOfStream <> True
iCnt = iCnt + 1
tt1 = tt1 + split(objFile.Readline, ",")(0)
Loop
tt2 = RoundFormatNumber(tt1/1048576, 2)
WSHShell.Run "cmd /c >>""" & csvFile & """ echo\,,", 0, True
strCommand = "cmd /c >>""" & csvFile & """ echo\" & tt1
strCommand = strCommand & ",""Users = " & iCnt
strCommand = strCommand & """,""[" & tt2 & " MB]"""
WSHShell.Run strCommand, 0, True
Rem WSHShell.Run """" & csvFile & """", 1, True '(requires Excel)
End Sub
/CODE]