Renato Borges
Renato Borges

Reputation: 1

Call a VBS in C# to open a itemTemplate Outlook

I need some help because I'm having some troubles..

I'm using Visual Studio 2012 and coding in C#. A little application.

I explain my issue :

I have a button who calls a script file name_script.vbs

On the name_script.vbs :

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItemFromTemplate("PATH")
myItem.Display

In C# button :

System.Diagnostics.Process.Start(@"\\Patch_to_the_script\name_script.vbs");

I have put on the top of my application :

Using Microsoft.Office.Interop.Outlook;
using Microsoft.Win32;

In my laptop is working but in other laptop not working If I open directly the script.vbs It's works ! Directly !

But in others laptops, Error: ActiveX can't create object 'Outlook.Application'..

I have launched with cscript but no changes ..

Maybe a problem in the compilation with a DLL ?

Did you have some ideas of this problem ?

Thanks in advance


I also try this :

Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application();


    Microsoft.Office.Interop.Outlook.Folder f = application.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderDrafts)
       as Microsoft.Office.Interop.Outlook.Folder;

    Microsoft.Office.Interop.Outlook.MailItem mail =
        application.CreateItemFromTemplate(@"\\Path\template.oft", f)
        as Microsoft.Office.Interop.Outlook.MailItem;

    mail.Display();

and this :

    System.Diagnostics.Process repousse= new Process();
    string targetDir = string.Format(@"\\path\");
    repousse.StartInfo.WorkingDirectory = targetDir;
    repousse.StartInfo.FileName = "script.vbs";
    repousse.StartInfo.CreateNoWindow = false;
    repousse.Start();
    repousse.WaitForExit();

And here to : Cscript

Upvotes: 0

Views: 614

Answers (1)

Mike Perrenoud
Mike Perrenoud

Reputation: 67918

The issue is that the client machine doesn't have the appropriate classes registered for Outlook interop. This could happen for an enumerable number of reasons, some of which include:

  • Office isn't even installed,
  • Outlook isn't installed,
  • The client interop libraries weren't installed when Office was installed,
  • Office needs repaired because its class id's are messed up in the registry,
  • The .vbs extension isn't registered properly,
  • The wrong version of Office is installed,
  • Etc.

Though there are other reasons that could be the culprit, I believe one of the aforementioned are likely the issue. Further, the using statements in your application are irrelevant. The .vbs file isn't going to use those using statements.

Upvotes: 1

Related Questions