简体   繁体   English

如何在MSI数据库中插入“格式”数据类型的值

[英]How to insert a value of data type 'Formatted' into the MSI database

I am trying to add a custom action in the CustomAction table of an msi.The problem is that the column name Target is of data type Formatted.It is failing when i am trying to insert a string into the column since the requested type is Formatted. 我试图在MSI的CustomAction表中添加一个自定义操作。问题是列名称Target的数据类型为Formatted。由于请求的类型为Formatted,因此我尝试向该列中插入字符串时失败。

WindowsInstaller.Installer ins = (WindowsInstaller.Installer)new Installer();

string strFileMsi = @"D:\Pack.msi";


 Database db3 = ins.OpenDatabase(strFileMsi, WindowsInstaller.MsiOpenDatabaseMode.msiOpenDatabaseModeDirect);
            System.Console.WriteLine("testing 1");



  WindowsInstaller.View vw3 = db3.OpenView("INSERT INTO CustomAction (Action,Type,Target) VALUES ('DeleteAction',3174,'\'Option Explicit\n\n'On Error Resume Next\nDim objFSO, strappfolder, WshShell, strprogramfiles, WshProcessenv\nDim intFilesCount, intSubFolderCount, intFileCount, objGetFolder, ObjFolder\nSet objFSO = CreateObject(\"Scripting.FileSystemObject\") \nset WshShell = CreateObject(\"Wscript.Shell\")\nset WshProcessenv = WshShell.Environment(\"Process\")\nstrprogramfiles = WshProcessenv(\"PROGRAMFILES(x86)\")\n\nIf ObjFSO.FileExists(strprogramfiles & \"\\datavision -BMS\\err.txt\") Then\nobjFSO.DeleteFile strprogramfiles & \"\\datavision -BMS\\err.txt\"\nEnd If\n\nIf ObjFSO.FileExists(strprogramfiles & \"\\datavision -BMS\\out.txt\") Then\nobjFSO.DeleteFile strprogramfiles & \"\\datavision -BMS\\out.txt\"\nEnd If\n\n If ObjFSO.FolderExists(strprogramfiles & \"\\datavision -BMS\") Then\n\n    Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n\n   Set objGetFolder = objFSO.GetFolder(strprogramfiles & \"\\datavision -BMS\")\n\n    ObjFSO.DeleteFolder strprogramfiles & \"\\datavision -BMS\"\n   End If')");

            vw3.Execute(null);
            System.Console.WriteLine("testing");

             db3.Commit();
            vw3.Close();   

It is always throwing exception.I am able to add values into Action Type without any problem.The problem comes with Target which is of formatted data type. 它总是抛出异常。我能够毫无问题地将值添加到操作类型中。问题来自于格式化数据类型的目标。

If it's the view.Execute that throws the exception, then say so, just to be explicit. 如果是view.Execute抛出异常,那么就这么明确地说。 Also somewhere in the exception itself (or the inner exception) there should be an MSI-related error number or text that says something about the details of the exception in MSI terms. 此外,在异常本身(或内部异常)中的某处,应该有一个与MSI相关的错误号或文字,其中用MSI术语说明了有关异常的详细信息。

Anyway, Target is Formatted, which is text. 无论如何,目标是格式化的,即文本。 The maximum length of a text string is 255 characters, and the length of your text is more than 255 characters by my count. 文字字符串的最大长度为255个字符,根据我的计算,您的文字长度超过255个字符。 That's most likely the issue. 这很可能是问题所在。 You could test with a very small string to verify. 您可以使用很小的字符串进行测试以进行验证。 Your alternative would be to insert the script into the Binary table and alter the custom action accordingly. 您的替代方法是将脚本插入Binary表并相应地更改自定义操作。

i dont reformat the string so check it before using it : 我不重新格式化字符串,所以在使用前先检查一下:

WindowsInstaller.View vw3 = db3.OpenView("SELECT * FROM CustomAction");

        vw3.Execute(null);

        Record record = ins.CreateRecord(4);

        record.StringData[1] = "DeleteAction";
        record.IntegerData[2] = 3174;
        record.StringData[4] = "Option Explicit\n\n'On Error Resume Next\nDim objFSO, strappfolder, WshShell, strprogramfiles, WshProcessenv\nDim intFilesCount, intSubFolderCount, intFileCount, objGetFolder, ObjFolder\nSet objFSO = CreateObject(\"Scripting.FileSystemObject\") \nset WshShell = CreateObject(\"Wscript.Shell\")\nset WshProcessenv = WshShell.Environment(\"Process\")\nstrprogramfiles = WshProcessenv(\"PROGRAMFILES(x86)\")\n\nIf ObjFSO.FileExists(strprogramfiles & \"\\datavision -BMS\\err.txt\") Then\nobjFSO.DeleteFile strprogramfiles & \"\\datavision -BMS\\err.txt\"\nEnd If\n\nIf ObjFSO.FileExists(strprogramfiles & \"\\datavision -BMS\\out.txt\") Then\nobjFSO.DeleteFile strprogramfiles & \"\\datavision -BMS\\out.txt\"\nEnd If\n\n If ObjFSO.FolderExists(strprogramfiles & \"\\datavision -BMS\") Then\n\n    Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n\n   Set objGetFolder = objFSO.GetFolder(strprogramfiles & \"\\datavision -BMS\")\n\n    ObjFSO.DeleteFolder strprogramfiles & \"\\datavision -BMS\"\n   End If";

        vw3.Modify(MsiViewModify.msiViewModifyInsert, record);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM