Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-02-22
2
Medium Priority
?
456 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 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

705 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