Solved

vbs bug: object reference not set to an inatance of an object

Posted on 2011-02-22
2
441 Views
Last Modified: 2012-05-11
The below is a script I'm using to snag the locations of users PST files on user logon via startup script.  It logs output like so:

user1, c:\personal\My.pst
user2, \\server\user\outlook.pst

However, I'm getting reports from the field that some users receive a error saying "Object reference not set to an instance of an object"  (which the cscript //B should have handled)

Can you assist?
' cscript //Nologo //B \\server\share\ListPSTs.vbs > \\server\reports\pstList.csv


'list .pst files associated with users outlook profile
Set outlook = WScript.CreateObject("Outlook.Application")
Set ns = outlook.GetNamespace("MAPI")

Set wshShell = WScript.CreateObject( "WScript.Shell" )
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )


For Each store In ns.Folders
    path = HextoAscii(store.storeid)
    pos = InStr(path,":\")
    If pos then WScript.Echo strUserName & ", " & Mid (path,pos -1)
Next

Function HexToAscii(str)
    Dim i, out

    For i = 1 To Len(str) Step 2
        char = Mid(str, i, 2)
        If char <> "00" then out = out & Chr("&H" & char )
    Next

    HexToAscii = out
End Function

Open in new window

0
Comment
Question by:Marketing_Insists
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 34957537
think the switches should be after the vbs file i.e.
cscript \\server\share\ListPSTs.vbs > \\server\reports\pstList.csv //Nologo //B
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 34957963
I assume it would be Outlook not behaving properly that's causing the error you're seeing.

You're right though, I would have thought //B would suppress that.  In any case, the addition of
On Error Resume Next
at the beginning of your script will prevent users seeing that error, if you don't care about it.

Regards,

Rob.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question