Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Re: Help required with file size checking script

Reply
 
Old 11-05-2008   #1 (permalink)
Richard Mueller [MVP]


 
 

Re: Help required with file size checking script


"Jason" <spamspamspam@xxxxxx> wrote in message
news:Xns9B4DAC1F9F7A3spamspamspamSpanishI@xxxxxx
Quote:

> Hi,
>
> I'm new to VBscript & a bit rusty with programming in general, I've just
> started working on a script that will probably be run at logon & would
> like
> a few pointers before I start.
>
> I want the script to check the size of the users default pst file & if the
> size is above 1.7 Gig display a warning message &, if possible, open up an
> email to notify me of the problem.
>
> The scenario I have is that all the users here have their pst files stored
> on the C drive; they are all stored in folder "C:\PST\" with the PST file
> itself being named after the user (i.e. C:\PST\user1.pst, C:\PST\user2pst,
> etc). I could rename everyone's PST file to the same filename
> (outlook.pst)
> but we do have a few users who share a computer, so that would cause a
> problem too.
>
> Does anyone have any ideas about how to tackle this with VBscript? I
> suppose the pseudo code would be something like:
>
> What files are in the C:\PST folder that have a '.pst' extension
> Are any of them above 1.7 GB
> If so display a warning box
> When the box has been closed open up a pre-filled email to be sent to the
> IT dept
>
> I'd be interested to know what functions within VBscript would help me
> achieve my goals, particularly ones that work with the file system?
>
> Many thanks, Jason
You can use either the FileSystemObject or the CIM_Datafile class of WMI to
retrieve properties of files. Since there may be more than one user, it
seems prudent to retrieve the username from the wshNetwork object. This
allows you to specify the correct *.pst file for the user. For example,
using the FileSystemObject:
===========
Option Explicit
Dim objNetwork, strUserName, strFile, objFile, lngSize

Set objNetwork = CreateObject("Wscript.Network")
' Retrieve current user name.
strUserName = objNetwork.UserName

' Specify the pst file for this user.
strFile = "c:\PST\" & strUserName & ".pst"

' Retrieve the file size.
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Trap error if file not found.
On Error Resume Next
Set objFile = objFSO.GetFile(strFile)
If (Err.Number = 0) Then
On Error GoTo 0
lngSize = CLng(objFile.Size)
If (lngSize > 1700000000) Then
Call MsgBox("Your output *.pst file is too large")
End If
End If
On Error GoTo 0
========
The same thing using WMI would be (watch for line wrapping):
==========
Option Explicit
Dim objNetwork, strUserName, strComputer, strFile
Dim objWMIService, colFiles, objFile, lngSize

Set objNetwork = CreateObject("Wscript.Network")
' Retrieve current user name and computer name.
strUserName = objNetwork.UserName
strComputer = objNetwork.Computer

' Specify the pst file for this user.
strFile = "c:\PST\" & strUserName & ".pst"

' Retrieve the file size.
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
& strComputer & "\root\cimv2")
Set colfiles = objWMIService.ExecQuery _
("SELECT * FROM CIM_Datafile WHERE Name = '" & Replace(strFile, "\",
"\\") & "'")
lngSize = 0
For Each objFile In colFiles
lngSize = CLng(objFile.FileSize)
Next
If (lngSize > 1700000000) Then
Call MsgBox("Your output *.pst file is too large")
End If
=======
Sending email from a script is another matter. You might be able to use CDO.
See these example:

http://www.microsoft.com/technet/scr.../mssmvb01.mspx
http://www.microsoft.com/technet/scr.../mssmvb02.mspx

Since all users presumably have Outlook, you might be able to use the
Outlook object to create an email message. Someone else might have an
example:

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--



My System SpecsSystem Spec
Old 11-05-2008   #2 (permalink)
Jason


 
 

Re: Help required with file size checking script

"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
news:#CYCq92PJHA.576@xxxxxx:
Quote:

>
> "Jason" <spamspamspam@xxxxxx> wrote in message
> news:Xns9B4DAC1F9F7A3spamspamspamSpanishI@xxxxxx
Quote:

>> Hi,
>>
>> I'm new to VBscript & a bit rusty with programming in general, I've
>> just started working on a script that will probably be run at logon &
>> would like
>> a few pointers before I start.
>>
>> I want the script to check the size of the users default pst file &
>> if the size is above 1.7 Gig display a warning message &, if
>> possible, open up an email to notify me of the problem.
>>
>> The scenario I have is that all the users here have their pst files
>> stored on the C drive; they are all stored in folder "C:\PST\" with
>> the PST file itself being named after the user (i.e.
>> C:\PST\user1.pst, C:\PST\user2pst, etc). I could rename everyone's
>> PST file to the same filename (outlook.pst)
>> but we do have a few users who share a computer, so that would cause
>> a problem too.
>>
>> Does anyone have any ideas about how to tackle this with VBscript? I
>> suppose the pseudo code would be something like:
>>
>> What files are in the C:\PST folder that have a '.pst' extension
>> Are any of them above 1.7 GB
>> If so display a warning box
>> When the box has been closed open up a pre-filled email to be sent to
>> the IT dept
>>
>> I'd be interested to know what functions within VBscript would help
>> me achieve my goals, particularly ones that work with the file
>> system?
>>
>> Many thanks, Jason
>
> You can use either the FileSystemObject or the CIM_Datafile class of
> WMI to retrieve properties of files. Since there may be more than one
> user, it seems prudent to retrieve the username from the wshNetwork
> object. This allows you to specify the correct *.pst file for the
> user. For example, using the FileSystemObject:
> ===========
> Option Explicit
> Dim objNetwork, strUserName, strFile, objFile, lngSize
>
> Set objNetwork = CreateObject("Wscript.Network")
> ' Retrieve current user name.
> strUserName = objNetwork.UserName
>
> ' Specify the pst file for this user.
> strFile = "c:\PST\" & strUserName & ".pst"
>
> ' Retrieve the file size.
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> ' Trap error if file not found.
> On Error Resume Next
> Set objFile = objFSO.GetFile(strFile)
> If (Err.Number = 0) Then
> On Error GoTo 0
> lngSize = CLng(objFile.Size)
> If (lngSize > 1700000000) Then
> Call MsgBox("Your output *.pst file is too large")
> End If
> End If
> On Error GoTo 0
> ========
> The same thing using WMI would be (watch for line wrapping):
> ==========
> Option Explicit
> Dim objNetwork, strUserName, strComputer, strFile
> Dim objWMIService, colFiles, objFile, lngSize
>
> Set objNetwork = CreateObject("Wscript.Network")
> ' Retrieve current user name and computer name.
> strUserName = objNetwork.UserName
> strComputer = objNetwork.Computer
>
> ' Specify the pst file for this user.
> strFile = "c:\PST\" & strUserName & ".pst"
>
> ' Retrieve the file size.
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
> & strComputer & "\root\cimv2")
> Set colfiles = objWMIService.ExecQuery _
> ("SELECT * FROM CIM_Datafile WHERE Name = '" & Replace(strFile,
> "\",
> "\\") & "'")
> lngSize = 0
> For Each objFile In colFiles
> lngSize = CLng(objFile.FileSize)
> Next
> If (lngSize > 1700000000) Then
> Call MsgBox("Your output *.pst file is too large")
> End If
> =======
> Sending email from a script is another matter. You might be able to
> use CDO. See these example:
>
> http://www.microsoft.com/technet/scr...ssage/smtpmail
//
Quote:

> mssmvb02.mspx
>
> Since all users presumably have Outlook, you might be able to use the
> Outlook object to create an email message. Someone else might have an
> example:
>
Thanks Richard, that's a great reply, I've got more than enough there to
be able to give it a really good go.

Jason.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: PS Script to automate checking date of file and delete if old PowerShell
Error checking with WMI Lastreboot script PowerShell
Checking the Existing of files and their size ... PowerShell
Re: checking for results when executing a script PowerShell
Checking Mailbox Size Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46