- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的问题:是否可以编辑使用自定义安全描述符创建的注册表项的值?我需要打电话吗 RegSetKeyValueEx使用 SECURITY_ATTRIBUTES 结构?如果没有,那么我需要删除 key 然后重新创建它。
我正在尝试编辑(或删除然后重写)一个注册表键值,但它不起作用。一些重要信息是我使用自定义安全描述符创建了注册表项。自定义安全描述符只有 KEY_READ Registry Key Security and Access Rights设置。
但由于其 ACL 安全描述符,我什至无法删除 key 。这是一个问题,因为当我卸载时,我什至无法删除注册表项。我使用自定义安全描述符创建注册表项的原因是用户无法无意或故意更改它。 key 告诉我我的应用程序之前是否运行过。
有谁知道如何编辑/删除这种类型的注册表项?
我的代码(试图编辑我的 key 并首先显示我是如何创建 key 的):
// Code to change key value
LONG lResult = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software/MyApplication"), 0, KEY_READ, &hKey);
LONG setValueRes = RegSetValueEx(hKey, _T("FirstRunSignafier"), 0, REG_DWORD, (LPBYTE) &firstRunSignafierValue,
(DWORD) sizeof(firstRunSignafierValue));
// Error Value of setValueRes is 5. lResult succeeds
// Code that creates the registry key
int recordFirstApplicationRun()
{
tstring REG_FIRST_RUN_SIGNIFIER = _T("Software\\MyApplication");
HKEY hKey;
LONG lResult;
int res = 1;
DWORD dwValue, dwType, dwSize = sizeof(dwValue);
DWORD firstRunSignafierValue = 1;
DWORD keyAlreadyExists; // Two potential values: REG_CREATED_NEW_KEY or REG_OPENED_EXISTING_KEY
PSID pEveryoneSID = NULL;
PACL pACL = NULL;
PSECURITY_DESCRIPTOR pSD = NULL;
SECURITY_ATTRIBUTES secAttr;
createSecurityAttributes(&secAttr, pEveryoneSID, pACL, pSD);
LONG createRes = RegCreateKeyEx(HKEY_CURRENT_USER, ®_FIRST_RUN_SIGNIFIER[0], 0, NULL, REG_OPTION_NON_VOLATILE,
KEY_WRITE|KEY_WRITE, &secAttr, &hKey, &keyAlreadyExists);
if (createRes != ERROR_SUCCESS) {
//_tprintf(_T("Failed to create key: Last Error: %x, Return Val: %x\n"), GetLastError(), createRes);
CPP_Utilities::outputLastError("Failed to create key");
res = -1;
goto Cleanup;
}
//CPP_Utilities::outputLastErrorEx( (keyAlreadyExists == REG_CREATED_NEW_KEY) ? _T("Created new registry key"):_T("Registry key already exists") );
_tprintf( (keyAlreadyExists == REG_CREATED_NEW_KEY) ? _T("Created new registry key\n"):_T("Registry key already exists\n") );
// To Write a DWORD to the registry
LONG setValueRes = RegSetValueEx(hKey, _T("FirstRunSignafier"), 0, REG_DWORD, (LPBYTE) &firstRunSignafierValue,
(DWORD) sizeof(firstRunSignafierValue));
if (setValueRes != ERROR_SUCCESS) {
_tprintf(_T("B: %X\n"), setValueRes);
CPP_Utilities::outputLastError("Failed to set registry value");
res = -2;
goto Cleanup;
}
Cleanup:
if (pEveryoneSID)
FreeSid(pEveryoneSID);
if (pACL)
LocalFree(pACL);
if (pSD)
LocalFree(pSD);
if (hKey)
RegCloseKey(hKey);
return res;
}
int createSecurityAttributes(SECURITY_ATTRIBUTES* secAttr, PSID pEveryoneSID, PACL pACL, PSECURITY_DESCRIPTOR pSD)
{
// Pre: Memory release for parameters MUST be handled by caller
EXPLICIT_ACCESS ea;
DWORD dwRes;
/*PSID*/ pEveryoneSID = NULL;
/*PACL*/ pACL = NULL;
/*PSECURITY_DESCRIPTOR*/ pSD = NULL;
SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
// Create a well-known SID for the Everyone group.
if(!AllocateAndInitializeSid(&SIDAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &pEveryoneSID)) {
_tprintf(_T("AllocateAndInitializeSid Error %u\n"), GetLastError());
CPP_Utilities::outputLastError("AllocateAndInitializeSid Error");
return -1;
}
// Initialize an EXPLICIT_ACCESS structure for an ACE. The ACE will allow Everyone read access to the key.
ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS));
ea.grfAccessPermissions = KEY_READ;
ea.grfAccessMode = SET_ACCESS;
ea.grfInheritance = NO_INHERITANCE;
ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
ea.Trustee.ptstrName = (LPTSTR) pEveryoneSID;
// Create a new ACL that contains the new ACEs.
dwRes = SetEntriesInAcl(1, &ea, NULL, &pACL);
if (ERROR_SUCCESS != dwRes) {
_tprintf(_T("SetEntriesInAcl Error %u\n"), GetLastError());
CPP_Utilities::outputLastError("SetEntriesInAcl Error");
return -2;
}
// Initialize a security descriptor.
pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
if (NULL == pSD) {
_tprintf(_T("LocalAlloc Error %u\n"), GetLastError());
CPP_Utilities::outputLastError("LocalAlloc Error");
return -3;
}
if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)) {
_tprintf(_T("InitializeSecurityDescriptor Error %u\n"), GetLastError());
CPP_Utilities::outputLastError("InitializeSecurityDescriptor Error");
return -4;
}
// Add the ACL to the security descriptor.
if (!SetSecurityDescriptorDacl(pSD, TRUE, pACL, FALSE)) {
_tprintf(_T("SetSecurityDescriptorDacl Error %u\n"), GetLastError());
CPP_Utilities::outputLastError("SetSecurityDescriptorDacl Error");
return -5;
}
// Initialize a security attributes structure.
secAttr->nLength = sizeof (SECURITY_ATTRIBUTES);
secAttr->lpSecurityDescriptor = pSD;
secAttr->bInheritHandle = FALSE;
return 1;
}
最佳答案
您需要更改权限,以便用户拥有 KEY_SET_VALUE
访问权限。最简单的方法是让您的卸载程序删除安装程序添加的 ACL。
您只需要卸载程序反转安装程序执行的步骤即可。你的安装程序去了:
因此您的卸载程序需要:
关于c++ - 编辑/删除 protected 注册表键值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15728909/
我添加了编辑按钮 self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButto
我试图在运行时“干净地”更改 UIBarButtonItem 文本,以便可以切换编辑/完成模式。然而,每次我在运行时更改 title 属性时,动画看起来都很笨拙。我正在寻找模拟联系人应用程序中“编辑/
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我想更改 INI 文件中的一些值。不幸的是,我在 2 个不同的部分有键,它们共享相同的名称但需要不同的值。我的代码使用 Get-IniContent函数来自 PsIni . 示例 INI 文件: [P
是否有通知或委托(delegate)方法可用于检测表格 View 何时进入编辑状态? 我想要做的是检测表正在编辑,然后显示一个额外的行,上面写着“添加新项目”或类似的东西。 我尝试在加载 View C
例如,我试图从 svg 读取样式块,我可以获取类型但不能获取字符串。 $svgTemplate = new SimpleXMLElement($_POST['SvgTemplateImport']);
我可以使用 self.navigationItem.leftBarButtonItem = self.editButtonItem; 通过按下导航面板上的编辑按钮让 UITableViewContro
我正在使用markitup!作为 Markdown 编辑器( example )。 目前,我需要按预览按钮(绿色勾号)来显示预览面板。 我希望自动显示预览 - 我怎样才能实现这一点? 最佳答案 我没有
我的处境非常糟糕。我丢失了源代码,客户需要在应用程序中进行一些更改。想想一个编辑程序集的例子:Test.dll,然后添加代码行,最后重新编译它 所以我的问题是: -可以这样做吗? -如果可能的话,什么
我使用了一些 JavaScript 来通过按钮更改段落元素的内容。它工作正常,但我还想让按钮控制标题和附图。给我指明正确的方向吗? 这是我用来更改段落的代码 .... 谢谢! 最佳答案 尝试将 Ja
是否有任何 Emacs lisp 插件可以让我轻松地在 yaml 文件中编辑或输入数据。 例如: --- sample yaml file ---Name : Addr :City :State:Zi
新手Java问题,我确定已经解决了,但是在任何地方都找不到解决方案:( 我想使用这里包含的java程序http://sourceforge.net/projects/ant-tibco/files/
在我的网页中,我使用了 gridview。在这个 GridView 中,它显示了一组用户信息。我刚刚从智能标签菜单中添加了一个按钮。我的要求是当我点击每个用户对应的按钮时,它会重定向到另一个页面并显示
我想在没有任何框架的情况下直接在 JS 中编辑一个 SVG 文件。 基本上我有一个 SVG 主文件,其中应该包含一些子 SVG。 我已经在 Ajax 中检索了这些子项的内容,但我想将它们插入到 SVG
我有我的 ViewModel,我有我的 Controller 可以从 ViewModel 正确显示,但是我不确定如何使 ViewModel 可编辑,以便将编辑后的数据发送回模型。我只想编辑 Order
我不确定我的做法是否正确。 IplImage *dog_1 = cvCreateImage(cvGetSize(oriImg), oriImg->depth, oriImg->nChannels);
我有一个创建二维码的网络服务器。在此过程中,我得到一个 BarcodeQRCode 对象,我可以从中获取图像 (.getImage())。 我不确定如何将这张图片发回给客户。我不想将它保存在文件中,而
已编辑:我的第一个问题解决了,但又出现了另一个问题,只提供了一个用户 ID。这是修改后的代码的屏幕截图。 回到表格,用户将按下编辑按钮,这样他就可以编辑问题并给出适当的操作.. 我的上表代码是这样的:
据我了解,我无法通过重新启动服务器来清除 MySQL 查询缓存。 每次运行 sql 时,我都试图获得与第一个代码块类似的结果 1-这是在重新启动 Apache 和 MySQL 之前(第一次使用这些查询
我正在创建一个页面来搜索项目,然后能够编辑/更新它。当它只返回一个结果时我能够做到这一点,但当它给我多个结果时我只能编辑最后一项。下面是我的代码: ....... $dj =$_POST[djnum]
我是一名优秀的程序员,十分优秀!