Jump to content

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")

 

WithCreateObject("Shell.Application").Namespace(MY_DOCUMENTS)

   strMY_DOCUMENTS = .Self.Path

   Set objFolder = objFSO.GetFolder(strMY_DOCUMENTS)

   drv = objFolder.drive

EndWith

 

' Determine drivetype of the My Documents Folder

Description = strUsername & "'s Documents on "

If (DriveIsLocal(drv) = True) Then

   Description = Description & strComputername

Else

   Description = Description & "Fileserver"

EndIf

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)

EndFunction

 

Function DriveIsLocal(drive)

   DriveIsLocal = TRUE

   IfNotLeft(drive,2) = "\\"Then

     WithGetObject("WinMgmts:{impersonationLevel=impersonate}" _

         & "!root/cimv2:Win32_LogicalDisk='"& drive & "'")

       If .DriveType = 4Then DriveIsLocal = FALSE

     EndWith

   Else

     DriveIsLocal = FALSE

   EndIf

EndFunction

 

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

   DoWhile 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

   RemWSHShell.Run """" & csvFile & """", 1, True '(requires Excel)

EndSub

/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...