Jump to content
Sign in to follow this  
BigDaddyO

Outlook, Get UserName

Recommended Posts

BigDaddyO

I have been looking for probably 2 hours not to find something that I thought would be easy.

I want to find out if Outlook is installed, If so is it configured, If it's configured what UserName is it configured to use.

Why is this so hard!!!

Finding if outlook is installed was easy. Just call the Outlook Com object and ensure it was created. It's after that where I'm stuck.

MSDN Link to the Outlook UserName info

my failing attempt so far. I have been going round and round for too long...

$oOutlook = ObjCreate("Outlook.Application")
if IsObj($oOutlook) Then
    $user = $oOutlook.Application.GetNameSpace("MAPI");.CurrentUser
    $id1 = $user.Account.UserName
    MsgBox(0, "UserName", $id1);$oOutlook.Account.UserName)
EndIf

Thanks for any help you can provide.

Mike


Share this post


Link to post
Share on other sites
big_daddy

Try this:

#include <IE.au3>

_IEErrorHandlerRegister()
$oOutlook = ObjCreate("Outlook.Application")
If Not IsObj($oOutlook) Then
    MsgBox(0, "", "Unable to create object!")
    Exit
EndIf

$oNameSpace = $oOutlook.GetNameSpace ("MAPI")
$oAccounts = $oNameSpace.Accounts
$iCount = $oAccounts.Count
$i = 1
$sProp = ""
For $oAccount In $oAccounts
    With $oAccount
        $sProp &= "Account #: " & $i & @CR
        $sProp &= "Account Type: " & .AccountType & @CR
        $sProp &= "Class: " & .Class & @CR
        $sProp &= "Display Name: " & .DisplayName & @CR
        $sProp &= "SMTP Address: " & .SmtpAddress & @CR
        $sProp &= "User Name: " & .UserName
        If $i <> $iCount Then $sProp &= @CR & @CR
    EndWith
    $i += 1
Next

ConsoleWrite($sProp & @CR)

Share this post


Link to post
Share on other sites
BigDaddyO

Big_Daddy,

Thanks for the attempt but I just get this in the scite Console

edit: updated the cosole data: I origionally had this pasted at the bottom of a test script so the line numbers were off.

--> COM Error Encountered in Testing.au3
----> $IEComErrorScriptline = 11
----> $IEComErrorNumberHex = 80020006
----> $IEComErrorNumber = -2147352570
----> $IEComErrorWinDescription = Unknown name.
----> $IEComErrorDescription = 
----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 
----> $IEComErrorLastDllError = 0

--> COM Error Encountered in Testing.au3
----> $IEComErrorScriptline = 12
----> $IEComErrorNumberHex = 000000A9
----> $IEComErrorNumber = 169
----> $IEComErrorWinDescription = Variable must be of type 'Object'.
----> $IEComErrorDescription = 
----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 
----> $IEComErrorLastDllError = 0

--> COM Error Encountered in Testing.au3
----> $IEComErrorScriptline = 15
----> $IEComErrorNumberHex = 000000A9
----> $IEComErrorNumber = 169
----> $IEComErrorWinDescription = Variable is not of type 'Object'.
----> $IEComErrorDescription = 
----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 
----> $IEComErrorLastDllError = 0

I have been working on this more this morning and I finally got some code that will retrieve the UserName but it throws an Outlook security box, so sadly I can't use it.

;Works but prompts the user with a security message
$oOutlook = ObjCreate("Outlook.Application")
$oSession = ObjCreate("Redemption.RDOSession")
$oAddress = $oOutlook.GetNamespace("MAPI").CurrentUser.Name
MsgBox(0, "", $oAddress)
Edited by MikeOsdx

Share this post


Link to post
Share on other sites
big_daddy

Works perfectly for me, I get something like this.

Account #: 1
Account Type: 0
Class: 105
Display Name: Microsoft Exchange Server
SMTP Address: someone@somewhere.com
User Name: UserName

Account #: 2
Account Type: 2
Class: 105
Display Name: someone@somewhere.com
SMTP Address: someone@somewhere.com
User Name: UserName

Account #: 3
Account Type: 2
Class: 105
Display Name: someone@somewhere.com
SMTP Address: someone@somewhere.com
User Name: UserName

Account #: 4
Account Type: 2
Class: 105
Display Name: someone@somewhere.com
SMTP Address: someone@somewhere.com
User Name: UserName

What version of Outlook are you testing on?

Share this post


Link to post
Share on other sites
BigDaddyO

Works perfectly for me, I get something like this.

What version of Outlook are you testing on?

I am using Outlook 2003 with Office 2007, but the Office 2007 shouldn't make a difference.

edit: and I am connected directly to an Exchange server, not POP3

Mike

Edited by MikeOsdx

Share this post


Link to post
Share on other sites
big_daddy

Hmmm.... I'm using Outlook 2007 so maybe that is the difference. I'll see if I can figure out the difference when I get home, I have Outlook 2003 installed on an old machine there.

Share this post


Link to post
Share on other sites
big_daddy

See if this works for you.

#include <IE.au3>

_IEErrorHandlerRegister()
$oOutlook = ObjCreate("Outlook.Application")
If Not IsObj($oOutlook) Then
    MsgBox(0, "", "Unable to create object!")
    Exit
EndIf

$oNameSpace = $oOutlook.GetNameSpace ("MAPI")
$oUser = $oNameSpace.CurrentUser
If Not IsObj($oUser) Then
    MsgBox(0, "Error", "There is no current user.")
    Exit
EndIf

ConsoleWrite($oUser.Name & @CR)

Share this post


Link to post
Share on other sites
BigDaddyO

See if this works for you.

#include <IE.au3>

_IEErrorHandlerRegister()
$oOutlook = ObjCreate("Outlook.Application")
If Not IsObj($oOutlook) Then
    MsgBox(0, "", "Unable to create object!")
    Exit
EndIf

$oNameSpace = $oOutlook.GetNameSpace ("MAPI")
$oUser = $oNameSpace.CurrentUser
If Not IsObj($oUser) Then
    MsgBox(0, "Error", "There is no current user.")
    Exit
EndIf

ConsoleWrite($oUser.Name & @CR)
That code pulls the user name but like the sample I put in post#3, I get a security warning that the user must hit OK to. So sadly I can't really use it.

I think I am going to send an e-mail to the Scripting Guys on Microsofts Website, then convert it to AutoIT of course. It's just stupid how difficult this is.

Thanks,

Mike

Edited by MikeOsdx

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.