Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted (edited)

hi guys i have a script that im trying to run,

 

the idea of the script is that when a user run a batch file it calculates the profile size and then write it to a CSV of my choosen location, ive missed off the bottam half of of the script as can fit on here.

 

this works on xp, although not bringing back any file size

 

on win 7 i get following error: permission denied, line 37 char 1

 

 

 

really appreciate your help

 

thanks

Edited by rhmphrey
Posted

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]

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...