Re: detect (and install) office 2003 PIAS - newbie to setup projects

From: Ricardo Drizin (ricardoSPAMyourass_at_linux.ime.usp.br)
Date: 11/10/04


Date: Wed, 10 Nov 2004 10:09:36 -0200


Some code/ideas that may be helpful to someone:

1) Detecting Office Interops

 public class Class1 //: System.Configuration.Install.Installer
 {
  [STAThread]
  static void Main(string[] args)
  {
   System.Reflection.Assembly x, y, z;
   // these strongnames you can find in file __AssemblyInfo__.ini at
C:\WINDOWS\assembly\GAC\Microsoft.Office.Interop.Excel\11.0.0.0__71e9bce111e
9429c
   try
   {
    x = System.Reflection.Assembly.Load("Microsoft.Office.Interop.Excel,
Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
    y = System.Reflection.Assembly.Load("office, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c");
    z = System.Reflection.Assembly.Load("Microsoft.Office.Interop.Access,
Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429cs");
    // etc...
   }
   catch (Exception)
   {
    MessageBox.Show("Interops not installed.\n" +
     "Read instructions at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrtskInstallingOfficePrimaryInteropAssemblies.asp");
   }
  }

2) Installing Office Interops. (Not sure if it is the best practice, but..
it works... anyone has comments on this?)

- In the Setup Project, open the "File System" (View - Editor - File
System), Add Special Folder (right-click) "Global Assembly Cache", and add
the needed DLLs to the folder. Since you cannot directly refer to the DLLs
that are in your GAC, you can copy (from DOS PROMPT) from GAC to another
directory.
(ex: COPY
C:\WINDOWS\ASSEMBLY\GAC\Microsoft.Office.Interop.Excel\11.0.0.0__71e9bce111e
9429c\Microsoft.Office.Interop.Excel.dll C:\interops\ )

3) Script to register FullTrust on your assembly hash:

' Script for registering FullTrust on assembly dll
' Works even being run from shell (command prompt) as from windows installer
' For Windows Installer you should put this as as a "Custom Action" under
"Commit" folder. Also put "[TARGETDIR]" on "CustomActionData" property, so
the script can find your dll.
'

strPath=""
on error resume next
strPath = Wscript.scriptfullname ' Wscript is only for shell
on error goto 0

if len(strPath)=0 then ' Registering from Windows Installer
    strPath = Session.Property("CustomActionData")
else ' Registering from Shell
    set fso = CreateObject("Scripting.Filesystemobject")
    strPath = fso.GetParentFolderName( strPath ) ' of course you
should put a relative path from this script to the dll
    strPath = fso.GetParentFolderName( strPath )
end if

set obj=CreateObject("WScript.Shell")
appname="MyAppName"
dllname = "mydll"
params=" -u -addgroup ""All_Code"" -hash SHA1 -file """ & strPath & "\bin\"
& dllname & ".dll"" FullTrust -name """ & appname & """ -description """ &
appname & """"
' Unregistering previous versions
call obj.Exec("%WINDIR%\Microsoft.NET\Framework\v1.1.4322\caspol.exe -pp
off -u -rg """ & appname & """")
hora = now() + cdate("00:00:05") ' HACK - since Exec calls are async,
wait a few secs so unregistering comes before registering.
while (now()<hora)
wend
' Registering
set caspol =
obj.Exec("%WINDIR%\Microsoft.NET\Framework\v1.1.4322\caspol.exe -pp off" &
params)

b=caspol.stdout.readall
' There's no ExitCode being returned ? same ExitCode on success or failure,
so we'll check for string in output.
Select Case InStr(b,"ERRO") ' works in English (ERROR) or Portuguese (ERRO)
   Case 0 'MsgBoX("Successfully registered assembly.")
   Case Else MsgBox("Error registering assembly.")
End Select

--------------------------

Maybe that is helpful for setup projects.

Ricardo Drizin
Mondial Informática

"Iouri Simernitski (MS)" <iouris@micro.nospam.soft.com> escreveu na mensagem
news:w1x7D6tsEHA.2092@cpmsftngxa10.phx.gbl...
> Ricardo,
> the only supported way to install PIAs is by using Office setup. You could
> write a custom action for your installer that woud try to load the Word or
> Excel assembly by strong name to check if it is installed, but you cannot
> install it if it is missing.
> If you are using the VS setup and deployment project for installing VSTO,
> it is not supposed to alter the CAS policies. It is up to you to decide
> what policy you want to deploy. By default, in a development invironment,
> the assembly is trusted by URL at project creation time. In general, it is
> wise to use stronger evidence when deploying an assembly in a production
> scenario - publisher, strong name or Authenticode.
>
> iouri
> --------------
> This posting is provided "AS IS" with no warranties, and confers no
rights.
>



Relevant Pages

  • Re: Service install -- The specified service already exists
    ... The installer should remove the existing service and install the new one. ... Unregistering type libraries ... Action start 21:26:42: RemoveODBC. ... Registering extension servers ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: regsvr32 error code 0x80004002
    ... I also have seen this error when there is a missing dll that your dll depends on. ... this invocation of regsvr32 succeeds. ... On another PC which also has VS2005 SP1 installed, an installer which was created by a VS2005 SP1 setup project did indeed insist on installing an extra copy of the redistributables. ... Sorry Norman, the context that this was happening on your development machine was lost, so I had forgotten that VS was installed. ...
    (microsoft.public.vc.mfc)
  • Re: Word Cannot Find Its Data Source ~~~.olk
    ... > I'd like some confirmation about registering this DLL. ... DLL, just in case, but regsvr32 came up with a "missing entry point" error. ... as I would like to have an address book connection method that can be ... initiated from Word and "does everything", the "initiation from Outlook" ...
    (microsoft.public.word.mailmerge.fields)
  • RE: VS2005 setup project: execute tasks without installing files?
    ... Windows Installer SDK must be installed. ... Add it into Custom Action, in the Custom Action Editor, open its ... C++ custom action and we use it to get the dll path, ... Microsoft Online Community Support ...
    (microsoft.public.vsnet.setup)
  • Re: msvcp71.dll and Python 2.4 C++ extensions
    ... >> this dll somewhere in the Python directory. ... I'm creating the installer via the distutils by calling "setup.py ... directory where other C++ extension packages might also be able to use ...
    (comp.lang.python)