简体   繁体   English

如何更新RegPath类型的msi注册表表项

[英]How to update msi Registry Table Key of Type RegPath

I am updating and inserting some tables on an msi file.My issue is the registry table is having a key column which is of type RegPath .Internally it is a string but i am unable to insert or retrieve the key attribute.It throws sql exception. 我正在更新并在MSI文件上插入一些表。我的问题是注册表表的列类型为RegPath 。内部它是一个字符串,但我无法插入或检索键属性。它引发sql异常。

string query = "SELECT Name FROM Registry";
WindowsInstaller.View view1 = db3.OpenView(query);
view1.Execute(null);   

Record r1 = vw6.Fetch();
while (r1 != null)
{
    Console.WriteLine(r1.get_StringData(1));
    r1 = vw6.Fetch();
}

This code will work.But if do the same thing for key ,it is throwing sql exception. 该代码将起作用。但是,如果对key执行相同的操作,则会抛出sql异常。

string query = "INSERT into Registry(Registry,Root,Key,Name,Value,Component_) VALUES ('" + registryname + "',2,'Software\\Microsoft\\Active Setup\\Installed Components','name','value','" + compname + "')";
WindowsInstaller.View view1 = db3.OpenView(query);
view1.Execute(null);   

I think the issue is with key column which is not a string which is causing the issue.I am attaching the msdn documentation for Registry Table. 我认为问题出在列,而不是导致问题的字符串。我附上了注册表表的msdn文档。 https://msdn.microsoft.com/en-us/library/windows/desktop/aa371168(v=vs.85).aspx and also for RegPath datatype https://msdn.microsoft.com/en-us/library/windows/desktop/aa371173(v=vs.85).aspx https://msdn.microsoft.com/zh-CN/library/windows/desktop/aa371168(v=vs.85).aspx ,也适用于RegPath数据类型https://msdn.microsoft.com/zh-cn/library /windows/desktop/aa371173(v=vs.85).aspx

Found another post with the same issue. 发现了另一则相同的问题。 http://www.dreamincode.net/forums/topic/352198-issues-in-insert-values-into-msi-database/ http://www.dreamincode.net/forums/topic/352198-issues-in-insert-values-into-msi-database/

I don't know that you need the double slashes in that registry string - this isn't going to be parsed by a compiler, it's just a raw string, and it looks fine for a registry path if you look at other examples. 我不知道您是否需要在注册表字符串中使用双斜杠-编译器将不会对此进行解析,它只是一个原始字符串,如果您查看其他示例,它对于注册表路径看起来很好。

However it's more likely that you need to properly escape the keywords with the peck marks, called acute or grave characters, as in the examples here that I can't type in the post: 但是,您更有可能需要正确地打掉带有啄字符的关键字,即尖锐或严重的字符,如此处示例中我无法键入的内容所示:

https://msdn.microsoft.com/en-us/library/aa368562(v=vs.85).aspx https://msdn.microsoft.com/zh-CN/library/aa368562(v=vs.85).aspx

where both the table and the item are escaped with the peck marks (left of 1 on my keyboard). 桌子和物品都用啄标记(在我的键盘上为1的左侧)转义了。

The issue is related to ambiguity with SQL syntax, that's the reason for escaping the actual names with peck marks, and Key is certainly already a SQL reserved word. 问题与SQL语法的歧义有关,这就是用啄号转义实际名称的原因,并且Key无疑已经是SQL保留字。

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

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