注册表项自动更新 [英] Registry entry updated automatically

查看:75
本文介绍了注册表项自动更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我访问excel宏时,我需要将"AccessVBOM"的注册表项值更改为"1",并在工作完成后将其更新为"0".
我使用下面的代码来设置值.
我可以将值设置为1并将值重置为0,但是自动将其更新为值1.

I need to change the registry entry value of "AccessVBOM" to ''1'' when i access excel macro and later updated it to ''0'' once my job is completed.
I used the below code to set the value.
I can able to set the value to 1 and reset the value to 0 but automatically it is getting updated with the value 1.

Void AccesstoVBAProject(BOOL bAccess)
{
	HKEY hKey;
	DWORD buffer = bAccess;
	unsigned long size = sizeof(DWORD);
	CLSID clsid;	
	int i = 0;
	BOOL flag = FALSE;
	CString version;
	CString subkey = "Software\\Microsoft\\Office\\";		
	for (i = EXCEL2003; i <= EXCEL2010; i++ )  
	{  
		if (SUCCEEDED(CLSIDFromProgID(szExcelProgID[i-1], &clsid)))  
		{ 
			switch(i)
			{
			case 1:		
				version = "11.0";			
				break;
			case 2:
				version = "12.0";			
				break;
			case 3:
				version = "14.0";			
				break;
			}		
			version = version + "\\Excel\\Security";
			subkey = subkey + version;
			break;
		}  
	} 		
	if(RegOpenKeyEx(HKEY_CURRENT_USER, (LPCSTR)subkey, 0, KEY_READ|KEY_SET_VALUE|KEY_CREATE_SUB_KEY|KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
	{
		if(RegSetValueEx(hKey, TEXT("AccessVBOM"), 0, REG_DWORD, (LPBYTE)&buffer, size) == ERROR_SUCCESS)
		{
			flag = TRUE;
		}
		RegCloseKey(hKey);
	}	
	return flag;
}
void GetMacroList()
{
AccesstoVBAProject(TRUE);
----
----
AccesstoVBAProject(FALSE);
}

推荐答案

嗨.

看来Office引擎正在跟踪注册表值的最后使用值,并在退出时将其写入.

这是两篇讨论相同(或相似行为)的不同文章,我只是在谷歌上搜索了一下:
Hi.

It seems that the Office engine is keeping track of the last used value of the registry value and writing it on exit.

These are two different articles discussing the same (or similar behavior) I just found googling a bit:
MSDN Blogs > cristib > VBA - How to programmatically enable access to the VBA object model using macros
报价:

似乎Office应用程序会在首次启动时记住该键的值.如果在应用程序运行时,您尝试通过任何方法(宏,脚本,手动编辑密钥...等)修改"AccessVBOM"密钥,但进入选项"> 信任中心"> 信任中心设置"> 宏设置",您的更改将在退出时被放弃.由于您需要退出应用程序并再次加载它才能使设置生效,因此无法以编程方式启用/禁用对VB对象模型的访问.

It seems that the Office application will remember what was the value for this key when it first started. If while the application is running you attempt to modify the ''AccessVBOM'' key by any method (macro, script, manually editing the key ...etc), except for going in ''Options'' > ''Trust Center'' > ''Trust Center Setting'' > ''Macro Settings'', your change will be discarded on exit. Since you need to exit the application and load it again for the setting to become effective, you cannot programmatically enable / disable access to VB object model.



RE:启用Turst访问Visual Basic项目



RE: Enabling Turst access to Visual Basic Projects

报价:

可以从VBA代码启用对Visual Basic项目的信任.

可以通过regedit.exe对其进行修改.它称为AccessVBOM,它可以
也可以通过VBA代码进行修改.但是,关闭Excel会设置
将AccessVBOM值返回
到信任访问
Visual Basic项目"复选框

It is possible to Enable Trust to Visual Basic Project from VBA code.

It can be modifed through regedit.exe. It is called AccessVBOM, which can
also be modified through VBA code. However, closing Excel will set the
AccessVBOM value back
to the level that is indicated in the "Trust access to
Visual Basic Project" checkbox



可能的解决方法可能是延迟将其设置为零的最后一个操作,将其安排为在设置的时间后运行,或者等待Office引擎卸载.否则,您可以尝试通过Office引擎提供的对象模型(如果可用)将其重置为零,而不是直接访问注册表值.

问候,
Daniele.



A possible workaround might be delaying the last operation that sets it to zero, scheduling it to be run after a set amount of time or to wait for the Office engine to be unloaded. Otherwise, You may try to reset it to zero through the object model provided by the office engine (if available) rather than direct access to the registry value.

Regards,
Daniele.


这篇关于注册表项自动更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆