Run Outlook as a different user

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
JohnTitor
Posts: 153
Joined: Fri Nov 17, 2017 8:49 pm

Run Outlook as a different user

Post by JohnTitor » Wed Feb 06, 2019 4:08 pm

We have two IDs. Our primary ID and our Admin ID

I have a form that I have to launch as my admin ID

Is there a way to run outlook as my primary ID using an button event?

Code: Select all


$timestamp = Get-Date
$ol = New-Object -comObject Outlook.Application

#Create the new email
$mail = $ol.CreateItem(0)

$mail.To = 'me@asdf.com'

#Optional, set the subject
$mail.Subject = "$($labelBanner.Text)"

#Optional, set the body
$mail.Body = "Username: $env:USERNAME
Computername: $($textboxcomputername.Text)
Date of use: $timestamp
Comments:
"

#Get the new email object
$inspector = $mail.GetInspector

#Bring the message window to the front
$inspector.Display()

User avatar
jvierra
Posts: 13790
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Run Outlook as a different user

Post by jvierra » Wed Feb 06, 2019 4:28 pm

No. To run as a different account might start Outlook but it would be inaccessible due to process isolation.

User avatar
JohnTitor
Posts: 153
Joined: Fri Nov 17, 2017 8:49 pm

Re: Run Outlook as a different user

Post by JohnTitor » Wed Feb 06, 2019 4:41 pm

I was able to get around it by using send-mailmessage and a few other tricks

Locked