Installing and Using the Macros
This topic describes how to install and use the IPFullTrust and SignCode macros for use with the Microsoft Office InfoPath 2003 Toolkit for Visual Studio .NET. Both macros are run from within the Visual Studio .NET environment. To begin working with the macros, open your InfoPath project in Visual Studio.
Installing the Macros
Perform the following steps once to install the InfoPathSDK macro project.
Open the \My Documents\Visual Studio Projects\VSMacros71 folder, and create a new folder named InfoPathSDK.
Copy the file InfoPathSDK.vsmacros from <drive>:\Program Files\Microsoft Office 2003 Developer Resources\Microsoft Office InfoPath 2003 SDK\Macros into the InfoPathSDK folder created in step 1.
On the Tools menu, point to Macros, click Load Macro Project, and then open the InfoPathSDK.vsmacros file.
A warning message is displayed to notify you that the InfoPathSDK.vsmacros macro project contains event handling code.
Click Enable event handling code, and then click OK.
Using the IPFullTrust Macro
Debugging a form template with managed code that uses object model members that require privileged access, such as writing to a file, requires that the InfoPath project is to full trust and registered on the system. The IPFullTrust macro automates the process of modifying the manifest file (.xsf file) and the form template file in your InfoPath project so that it is set for full trust, and then the macro automatically registers the form template.
- To use the IPFullTrust macro, first close the design mode instance of InfoPath associated with the project. When InfoPath is in design mode, it locks the manifest.xsf file and prevents the macro from making changes, so it must be closed.
- In Visual Studio .NET, on the Tools menu, point to Macros, and then click Macro Explorer.
- In the Macro Explorer window, expand the InfoPathSDK node, and then expand the IPFullTrust node. The IPFullTrust macro is denoted with a cassette icon and the name IPFullTrust.
- Right-click the IPFullTrust macro and then click Run.
Once the IPFullTrust macro has been run successfully on the project, the form template will be registered on the development computer. Ongoing code changes can be made without the need to re-run the macro. The full trust level will be maintained.
Using the SignCode Macro
The SignCode macro is dependent on the signcode.exe utility included with the .NET Framework SDK. Full information on the utility is found in the MSDN article, "File Signing Tool (Signcode.exe)" <link to http://msdn.microsoft.com/library/en-us/cptools/html/cpgrfFileSigningToolSigncodeexe.asp\ . The .NET Framework SDK is installed by default when you install Visual Studio .NET. However, if you chose not to install the .NET Framework SDK, the macro will not function. If you have moved the signcode.exe utility to a different location, be sure the directory is included in your local path environment variable.
Signing an InfoPath project requires a code signing certificate file (.cer). A code signing certificate can be obtained from a certificate authority such as Verisign or from an internal corporate certificate authority. For debug and test purposes, a code signing certificate can also be created using the makecert.exe utility included in the .NET Framework SDK. A certificate created using makecert.exe is not suitable for publishing signed forms but will work fine for debugging and testing on a developer's computer.
To create a certificate with the makecert.exe utility, first a trusted root certificate authority must be created.
Open the Command Prompt, type the following, and then press ENTER:
makecert -n "CN=TrustedRootCA" -r -cy authority -a sha1 -sky signature -m 1 -sv certRoot.pvk certRoot.cer -ss ROOT
The Create Private Key Password dialog box is displayed. Click None.
A Security Warning message is displayed stating "You are about to install a certificate from a certification authority (CA) claiming to represent: TrustedRootCA". Click Yes to install the certificate to the Trusted Root Certification Authorities store.
To create a certificate used for signing, type the following, and then press ENTER:
makecert -n "CN=TestCert" -cy end -a sha1 -sky signature -m 1 -iv Certroot.pvk -ic certroot.cer -ss MY -sv MyKey.pvk MyCertificate.cer
The Create Private Key Password dialog box is displayed. Because this is just a debug and test certificate, it is recommended that you use a blank password to make the signing process simpler. To do that, click None.
The files MyCertificate.cer and MyKey.pvk are created in the directory where you issued the command in step 4. Copy them to the project directory of any InfoPath project you wish to sign.
Important The certificate created with this procedure is only suitable for testing and debugging. Be sure to obtain a legitimate code signing certificate from a certificate authority if you need to sign any release versions of your project. Additional information on the code signing process can be found in the MSDN article, "Signing and Checking Code with Authenticode" <link to http://msdn.microsoft.com/workshop/security/authcode/signing.asp\ .
The SignCode macro is configured to run when a build of a project is successfully completed. Once you've copied your certificate and key file to your project directory, your project will be automatically signed when it is built. The SignCode macro is hard coded to look for certificate and private key files named MyCertificate.cer and MyKey.pvk located in the current project directory. To sign your project with a legitimate code signing certificate's files, you can either rename the files to these names, or can modify the CertificateFileName and KeyFileName constants