Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass parameters for a managed code dll in installshield?
    primarykey
    data
    text
    <p>I have a dotnet script which is for encryption and decryption. I have to pass the parameters for the setvalues function in installshield. How can I achieve this? Dotnet code is as follows. I have the assembly (.dll) file.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; using System.Security; using System.Xml; using System.Collections.Specialized; namespace EncryptionDecryption { public class EncrptionHelper { #region Member variables static byte[] entropy = { 0, 8, 2, 3, 5 }; #endregion #region Public Methods public static void SetValue(string configFilePathName, string appSettingKey, string appSettingValue) { appSettingValue = EncryptString(ToSecureString(appSettingValue)); SetSetting(appSettingKey, appSettingValue, configFilePathName); } public static string GetValue(string configFilePathName, string appSettingKey) { string value = GetSetting(appSettingKey, configFilePathName); value = ToInsecureString( DecryptString(value)); return value; } #endregion #region Private Methods private static bool SetSetting(string Key, string Value, string configFilePath) { bool result = false; try { // System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(configFilePath); // config.AppSettings.File = configFilePath; // config.AppSettings.Settings[Key].Value = Value; // config.Save(ConfigurationSaveMode.Modified); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(configFilePath); xmlDoc.SelectSingleNode("//appSettings/add[@key='" + Key +"']").Attributes["value"].Value = Value; xmlDoc.Save(configFilePath); ConfigurationManager.RefreshSection("appSettings"); result = true; } finally { } return result; } private static string GetSetting(string Key, string configFilePath) { string result = null; try { XmlDocument appSettingsDoc = new XmlDocument(); appSettingsDoc.Load(configFilePath); XmlNode node = appSettingsDoc.SelectSingleNode("//appSettings"); XmlElement value = (XmlElement)node.SelectSingleNode(string.Format("//add[@key='" + Key + "']")); result = (value.GetAttribute("value").ToString()); } finally { } return result; } private static SecureString ToSecureString(string input) { SecureString secure = new SecureString(); foreach (char c in input) { secure.AppendChar(c); } secure.MakeReadOnly(); return secure; } private static string ToInsecureString(SecureString input) { string returnValue = string.Empty; IntPtr ptr = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(input); try { returnValue = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(ptr); } finally { System.Runtime.InteropServices.Marshal.ZeroFreeBSTR(ptr); } return returnValue; } private static string EncryptString(System.Security.SecureString input) { byte[] encryptedData = System.Security.Cryptography.ProtectedData.Protect( System.Text.Encoding.Unicode.GetBytes(ToInsecureString(input)), entropy, System.Security.Cryptography.DataProtectionScope.CurrentUser); return Convert.ToBase64String(encryptedData); } private static SecureString DecryptString(string encryptedData) { try { byte[] decryptedData = System.Security.Cryptography.ProtectedData.Unprotect( Convert.FromBase64String(encryptedData), entropy, System.Security.Cryptography.DataProtectionScope.CurrentUser); return ToSecureString(System.Text.Encoding.Unicode.GetString(decryptedData)); } catch { return new SecureString(); } } #endregion } } Update: Action start 14:31:36: Encryption. MSI (c) (84:40) [14:31:36:525]: Invoking remote custom action. DLL: C:\Users\&lt;username&gt;\AppData\Local\Temp\MSIE259.tmp, Entrypoint: m1 InstallShield: Attempting to load through CLR 4 APIs... InstallShield: Getting meta host... InstallShield: Enumerating available runtimes... InstallShield: Highest available runtime: v4.0.30319 InstallShield: Trying to use highest runtime... InstallShield: Using highest version runtime... InstallShield: Loading assembly Security.Encryption from resource 4097 InstallShield: Calling method with parameters [(System.String)C:\Program Files (x86)\&lt;Installdir&gt;\&lt;configfilename&gt;.config, (System.String)VWFPassword, (System.String)] InstallShield: Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---&gt; System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Program Files (x86)\&lt;Installdir&gt;\&lt;configfilename&gt;.config'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy) at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver) at System.Threading.CompressedStack.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state) at System.Xml.XmlTextReaderImpl.OpenUrl() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.Load(String filename) at Security.Encryption.EncrptionHelper.SetSetting(String appSettingKey, String appsettingValue, String configFilePathName) at Security.Encryption.EncrptionHelper.SetValue(String configFilePathName, String appSettingKey, String appSettingValue) --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct&amp; sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at InstallShield.ClrHelper.CustomActionHelper.CallMethod(EntryPointInfo info) at InstallShield.ClrHelper.CustomActionHelper.RunAction(UInt32 installHandle, Int32 entryNumber, Int64 instanceHandle) InstallShield: Managed code threw an unhandled exception. </code></pre> <p>This is the error I receive after doing all that is mentioned in the screenshots below and doing some R&amp;D. The directory mentioned "C:\Program Files (x86)\\.config" exists when the encryption custiom action is being called but it throws an exception.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload