CreateObject Fails 
Author Message
 CreateObject Fails

When I execute the following code in an ASP document, I get the error
message "ActiveX component can't create object 'Outlook.Application'".
Outlook XP is installed on the test machine, and this code works in Visual
Basic just fine.

Any ideas as to why it would fail?

Thanks,

Mike

Sub SendMail
    Dim objOutlk 'Outlook
    Dim objMail 'Email item
    Dim strMsg
    Dim CRLF

    Const olMailItem = 0

    CRLF = chr(13) & chr(10)

    'Create a new message
    Set objOutlk = CreateObject("Outlook.Application")
    Set objMail = objOutlk.CreateItem(olMailItem)

    objMail.To = document.forms("frmQuestion").txtEmailAddress.value
    'Set up Subject Line
    objMail.subject = "Flight Standards and Training Response"
    'Add the body

document.forms("frmQuestion").txtQuestion.value _
        & CRLF & CRLF & "Answer:" & CRLF & CRLF &
document.forms("frmQuestion").txtAnswer.value
    objMail.body = strMsg
    objMail.display
    'Clean up
    Set objMail = nothing
    Set objOutlk = nothing
End Sub



Sat, 23 Jul 2005 02:26:14 GMT  
 CreateObject Fails
Before we get into your initial question, why do you have

objMail.display

in an ASP page?  Who will be at the server to see it?  No one.

Ray at work


Quote:
> When I execute the following code in an ASP document, I get the error
> message "ActiveX component can't create object 'Outlook.Application'".
> Outlook XP is installed on the test machine, and this code works in Visual
> Basic just fine.

> Any ideas as to why it would fail?

> Thanks,

> Mike

> Sub SendMail
>     Dim objOutlk 'Outlook
>     Dim objMail 'Email item
>     Dim strMsg
>     Dim CRLF

>     Const olMailItem = 0

>     CRLF = chr(13) & chr(10)

>     'Create a new message
>     Set objOutlk = CreateObject("Outlook.Application")
>     Set objMail = objOutlk.CreateItem(olMailItem)

>     objMail.To = document.forms("frmQuestion").txtEmailAddress.value
>     'Set up Subject Line
>     objMail.subject = "Flight Standards and Training Response"
>     'Add the body

> document.forms("frmQuestion").txtQuestion.value _
>         & CRLF & CRLF & "Answer:" & CRLF & CRLF &
> document.forms("frmQuestion").txtAnswer.value
>     objMail.body = strMsg
>     objMail.display
>     'Clean up
>     Set objMail = nothing
>     Set objOutlk = nothing
> End Sub



Sat, 23 Jul 2005 02:31:32 GMT  
 CreateObject Fails
I'm using this to debug, just to make sure the email is being created
properly. I planned to change it when I've finished the code.

The routine is part of a project to allow instructors to answer questions
posted by pilots. The questions are stored in a database on the server and
retrieved by the instructors.

The code is currently set to execute on the client, since each instructor
will be working from his own work station, or even from home. Is this a
problem?

I also tried adding a Project Reference to MS Outlook, but I got an error
and the ASP page wouldn't even load with the META statement in Global.asa. I
tried moving it to the header of the ASP page, but that wouldn't work
either. When I remove the reference, the page loads.

Thanks,

Mike



Quote:
> Before we get into your initial question, why do you have

> objMail.display

> in an ASP page?  Who will be at the server to see it?  No one.

> Ray at work



> > When I execute the following code in an ASP document, I get the error
> > message "ActiveX component can't create object 'Outlook.Application'".
> > Outlook XP is installed on the test machine, and this code works in
Visual
> > Basic just fine.

> > Any ideas as to why it would fail?

> > Thanks,

> > Mike

> > Sub SendMail
> >     Dim objOutlk 'Outlook
> >     Dim objMail 'Email item
> >     Dim strMsg
> >     Dim CRLF

> >     Const olMailItem = 0

> >     CRLF = chr(13) & chr(10)

> >     'Create a new message
> >     Set objOutlk = CreateObject("Outlook.Application")
> >     Set objMail = objOutlk.CreateItem(olMailItem)

> >     objMail.To = document.forms("frmQuestion").txtEmailAddress.value
> >     'Set up Subject Line
> >     objMail.subject = "Flight Standards and Training Response"
> >     'Add the body

> > document.forms("frmQuestion").txtQuestion.value _
> >         & CRLF & CRLF & "Answer:" & CRLF & CRLF &
> > document.forms("frmQuestion").txtAnswer.value
> >     objMail.body = strMsg
> >     objMail.display
> >     'Clean up
> >     Set objMail = nothing
> >     Set objOutlk = nothing
> > End Sub



Sat, 23 Jul 2005 02:49:46 GMT  
 CreateObject Fails
at the server it's:   Server.CreateObject


Quote:
> When I execute the following code in an ASP document, I get the error
> message "ActiveX component can't create object 'Outlook.Application'".
> Outlook XP is installed on the test machine, and this code works in Visual
> Basic just fine.

> Any ideas as to why it would fail?

> Thanks,

> Mike

> Sub SendMail
>     Dim objOutlk 'Outlook
>     Dim objMail 'Email item
>     Dim strMsg
>     Dim CRLF

>     Const olMailItem = 0

>     CRLF = chr(13) & chr(10)

>     'Create a new message
>     Set objOutlk = CreateObject("Outlook.Application")
>     Set objMail = objOutlk.CreateItem(olMailItem)

>     objMail.To = document.forms("frmQuestion").txtEmailAddress.value
>     'Set up Subject Line
>     objMail.subject = "Flight Standards and Training Response"
>     'Add the body

> document.forms("frmQuestion").txtQuestion.value _
>         & CRLF & CRLF & "Answer:" & CRLF & CRLF &
> document.forms("frmQuestion").txtAnswer.value
>     objMail.body = strMsg
>     objMail.display
>     'Clean up
>     Set objMail = nothing
>     Set objOutlk = nothing
> End Sub



Sat, 23 Jul 2005 03:25:22 GMT  
 CreateObject Fails
I pasted your code into a .vbs file, and it works fine (after I replaced the
.Form calls with strings).  Are you unable to create the object on the same
machine that it works on okay in VB?

Perhaps it is failing because IUSR_ doesn't have permissions, since he's
probably just a member of guests.

Here's one thing though.  Are you planning on using .send?  If so, this will
fail.  Outlook 2002 (not XP) has a security "feature" that will not allow
you to programatically send e-mail unless you install a third party COM
add-in for Outlook, such as "Outlook Redemption."  I won't go off about how
horrible of a "feature" this is...

Is there any particular reason you are using Outlook as opposed to CDO?

Ray at work


Quote:
> I'm using this to debug, just to make sure the email is being created
> properly. I planned to change it when I've finished the code.

> The routine is part of a project to allow instructors to answer questions
> posted by pilots. The questions are stored in a database on the server and
> retrieved by the instructors.

> The code is currently set to execute on the client, since each instructor
> will be working from his own work station, or even from home. Is this a
> problem?

> I also tried adding a Project Reference to MS Outlook, but I got an error
> and the ASP page wouldn't even load with the META statement in Global.asa.
I
> tried moving it to the header of the ASP page, but that wouldn't work
> either. When I remove the reference, the page loads.

> Thanks,

> Mike



> > Before we get into your initial question, why do you have

> > objMail.display

> > in an ASP page?  Who will be at the server to see it?  No one.

> > Ray at work



> > > When I execute the following code in an ASP document, I get the error
> > > message "ActiveX component can't create object 'Outlook.Application'".
> > > Outlook XP is installed on the test machine, and this code works in
> Visual
> > > Basic just fine.

> > > Any ideas as to why it would fail?

> > > Thanks,

> > > Mike

> > > Sub SendMail
> > >     Dim objOutlk 'Outlook
> > >     Dim objMail 'Email item
> > >     Dim strMsg
> > >     Dim CRLF

> > >     Const olMailItem = 0

> > >     CRLF = chr(13) & chr(10)

> > >     'Create a new message
> > >     Set objOutlk = CreateObject("Outlook.Application")
> > >     Set objMail = objOutlk.CreateItem(olMailItem)

> > >     objMail.To = document.forms("frmQuestion").txtEmailAddress.value
> > >     'Set up Subject Line
> > >     objMail.subject = "Flight Standards and Training Response"
> > >     'Add the body

> > > document.forms("frmQuestion").txtQuestion.value _
> > >         & CRLF & CRLF & "Answer:" & CRLF & CRLF &
> > > document.forms("frmQuestion").txtAnswer.value
> > >     objMail.body = strMsg
> > >     objMail.display
> > >     'Clean up
> > >     Set objMail = nothing
> > >     Set objOutlk = nothing
> > > End Sub



Sat, 23 Jul 2005 03:28:12 GMT  
 CreateObject Fails
Yes, it is the same machine.  I have written several programs in VB6
using the same code, and it always works.  The only difference is, of
course, the way the variables are declared (no AS statement).

There are a couple of bugs in various versions of Outlook that drive me
nuts, but I wasn't aware of the .Send problem.  I'll have to take that
into account.

I've never used CDO, since I'm fairly new to VBS.  I'll be glad to try
anything that will work.  Will it generate an email if Outlook is the
mail client on the server?

Thanks,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sat, 23 Jul 2005 05:51:55 GMT  
 CreateObject Fails

Quote:

> When I execute the following code in an ASP document, I get the error
> message "ActiveX component can't create object 'Outlook.Application'".
> Outlook XP is installed on the test machine, and this code works in
> Visual Basic just fine.

> Any ideas as to why it would fail?

You can use any COM object inside IE hosted script provided you want to deal
with the IE enforced security model regarding "unsafe ActiveX...". Whether
the user allows this is strictly up to them. There is no way to do this
silently without some prior acknowledgement and permission from the end
user...

Whether you use JScript's new ActiveXObject() or VBScript's CreateObject()
or whether you get the prompt or the failure, the issues are still the
same...

Q195826 - PRB: CreateObject Fails from Client-Side Scripts
http://support.microsoft.com/default.aspx?kbid=195826

For an Intranet, network share, or local hard drive scenario, you can simply
use HTAs instead.

Note that an HTA solution is appropriate ***only*** for non-intERnet
scenarios.  End users should never be expected to execute an HTA delivered
from an intERnet source any more than expecting them to execute an EXE,
unless they have an extremely high level of trust for the originating site.

That's why accessing an HTA via IE is treated exactly like accessing an EXE.
The end user is prompted to save or open (execute) the HTA, the exact same
prompt as for as any other file type that will execute on the client.

Converting to an HTA can be as simple as saving the file with .hta instead
of .htm as the extension. .hta files are hosted by mshta.exe rather than
iexplore.exe, and have a security model comparable to a conventional Windows
desktop application. Of course accepting and executing an HTA is also up to
the end user...

Description of Internet Explorer Security Zones Registry Entries
http://support.microsoft.com/default.aspx?kbid=182569

If I need that kind of access to client resources, I develop/deploy an HTA.

Introduction to HTML Applications (HTAs)
http://msdn.microsoft.com/workshop/author/hta/overview/htaoverview.asp
HTA Reference
http://msdn.microsoft.com/workshop/author/hta/reference/hta_ref_entry...

The HTAs I deploy follow a hybrid deployment model. The HTA itself is simply
a wrapper for a trusted iframe hosting an ASP page.  The iframe page doesn't
have to be asp.  It could be ordinary htm, php, etc., whatever the server
supports.

With this model, it doesn't matter if the user saves/runs a local copy of
the HTA - the real content is delivered via http from a web server. To test
changes to the ASP content, I keep a local copy of the HTA with the base
href URL pointing to a development web server instead of the production
server.

You can use the same model for a network file server deployment as well.
Just change the base href to "\\YourFileServer" and iframe src to
"\YourShare\YourPath\YourPage.htm".

      <html>
      <head><title>YourTitle</title>
      <base href="http://YourProductionServer">
      <hta:application id="YourAppId"
        applicationName="YourAppName"
        singleInstance="yes"
        showInTaskbar="yes"
        borderStyle="fixed"
      />
      </head>
      <body scroll="no" style="margin:0px">
      <iframe width="100%" height="100%"
        frameborder="no" border="0"
        marginheight="0" marginwidth="0"
        application="yes"
        src="/YourSite/YourPath/YourPage.asp"
      ></iframe>
      </body>
      </html>

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US

Windows 2000 Scripting Guide
Microsoft? Windows?2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overvie...
Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp
Download details: System Administration Scripting Guide Scripts
http://www.microsoft.com/downloads/details.aspx?displaylang=en&Family...



Sat, 23 Jul 2005 10:45:08 GMT  
 CreateObject Fails

Thanks for the info.

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sat, 23 Jul 2005 11:11:12 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Server.createobject failed

2. server.createobject failed

3. CreateObject failing (sometimes!)

4. Server.CreateObject Failed error message - why?

5. "Server.CreateObject failed" intermittently

6. 800706bf Server.CreateObject Failed - UPDATED with details

7. Server.CreateObject failed while checking permissions

8. Server.CreateObject Failed

9. New works, CreateObject fails on COM EXE Object

10. Why New works and CreateObject fails ???

11. WSC CreateObject fails: Bug in WSH 5.6?

12. CreateObject fails but New works

 

 
Powered by phpBB® Forum Software