+ Post New Thread
Results 1 to 2 of 2
Scripts Thread, local profile size in Coding and Web Development; hi guys i have a script that im trying to run, the idea of the script is that when a ...
  1. #1

    Join Date
    Dec 2012
    Posts
    3
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    local profile size

    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
    Last edited by rhmphrey; 17th December 2012 at 09:10 AM.

  2. #2

    Join Date
    Dec 2012
    Posts
    3
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    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 fold er)
    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 Fold er
    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 scrip t!)
       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]

SHARE:
+ Post New Thread

Similar Threads

  1. Deletion of local profiles on xp.
    By mac_shinobi in forum Scripts
    Replies: 25
    Last Post: 13th June 2007, 08:14 PM
  2. Local Profile issues
    By johnkay21 in forum Windows
    Replies: 2
    Last Post: 8th May 2007, 12:41 PM
  3. Replies: 17
    Last Post: 14th December 2006, 01:52 PM
  4. Replies: 9
    Last Post: 12th September 2006, 11:09 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •