Solved

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

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now