示例#1
0
        /// <summary>
        /// Sets the full path to the designated folder on the installation target drive.
        /// </summary>
        /// <exception cref="ArgumentException">the folder was not found in the Directory table</exception>
        /// <exception cref="InvalidHandleException">the Session handle is invalid</exception>
        /// <remarks><p>
        /// Setting the target path of a directory changes the path specification for the directory
        /// in the in-memory Directory table. Also, the path specifications of all other path objects
        /// in the table that are either subordinate or equivalent to the changed path are updated
        /// to reflect the change. The properties for each affected path are also updated.
        /// </p><p>
        /// If an error occurs in this function, all updated paths and properties revert to
        /// their previous values. Therefore, it is safe to treat errors returned by this function
        /// as non-fatal.
        /// </p><p>
        /// Do not attempt to configure the target path if the components using those paths
        /// are already installed for the current user or for a different user. Check the
        /// ProductState property before setting the target path to determine if the product
        /// containing this component is installed.
        /// </p><p>
        /// Win32 MSI API:
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msisettargetpath.asp">MsiSetTargetPath</a>
        /// </p></remarks>
        public void SetTargetPath(string directory, string value)
        {
            if (string.IsNullOrWhiteSpace(directory))
            {
                throw new ArgumentNullException("directory");
            }

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            this.ValidateSessionAccess();

            uint ret = RemotableNativeMethods.MsiSetTargetPath((int)this.Handle, directory, value);

            if (ret != 0)
            {
                if (ret == (uint)NativeMethods.Error.DIRECTORY)
                {
                    throw InstallerException.ExceptionFromReturnCode(ret, directory);
                }
                else
                {
                    throw InstallerException.ExceptionFromReturnCode(ret);
                }
            }
        }