Solved

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

Posted on 2011-02-22
2
439 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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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