本文整理汇总了C++中RegSetValueExA函数的典型用法代码示例。如果您正苦于以下问题:C++ RegSetValueExA函数的具体用法?C++ RegSetValueExA怎么用?C++ RegSetValueExA使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RegSetValueExA函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: register_key_defvalueA
/***********************************************************************
* regsvr_key_defvalueA
*/
static LONG register_key_defvalueA(
HKEY base,
WCHAR const *name,
char const *value)
{
LONG res;
HKEY key;
res = RegCreateKeyExW(base, name, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &key, NULL);
if (res != ERROR_SUCCESS) return res;
res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
lstrlenA(value) + 1);
RegCloseKey(key);
return res;
}
示例2: myspace_links_register
static void myspace_links_register()
{
HKEY hkey;
char szBuf[MAX_PATH], szExe[MAX_PATH * 2], szShort[MAX_PATH];
GetModuleFileNameA(hInst, szBuf, sizeof(szBuf));
GetShortPathNameA(szBuf, szShort, sizeof(szShort));
//LOG(LOG_DEBUG, "Links: register");
if (RegCreateKeyA(HKEY_CLASSES_ROOT, "myim", &hkey) == ERROR_SUCCESS) {
RegSetValueA(hkey, NULL, REG_SZ, "URL:MySpace IM Protocol", strlen("URL:MySpace IM Protocol"));
RegSetValueExA(hkey, "URL Protocol", 0, REG_SZ, (PBYTE) "", 1);
RegCloseKey(hkey);
}
else {
//LOG(LOG_ERROR, "Links: register - unable to create registry key (root)");
return;
}
if (RegCreateKeyA(HKEY_CLASSES_ROOT, "myim\\DefaultIcon", &hkey) == ERROR_SUCCESS) {
char szIcon[MAX_PATH];
mir_snprintf(szIcon, sizeof(szIcon), "%s,0", szShort);
RegSetValueA(hkey, NULL, REG_SZ, szIcon, strlen(szIcon));
RegCloseKey(hkey);
}
else {
//LOG(LOG_ERROR, "Links: register - unable to create registry key (DefaultIcon)");
return;
}
if (RegCreateKeyA(HKEY_CLASSES_ROOT, "myim\\shell\\open\\command", &hkey) == ERROR_SUCCESS) {
// MSVC exports differently than gcc/mingw
#ifdef _MSC_VER
mir_snprintf(szExe, sizeof(szExe), "RUNDLL32.EXE %s,[email protected] %%1", szShort);
//LOG(LOG_INFO, "Links: registering (%s)", szExe);
#else
mir_snprintf(szExe, sizeof(szExe), "RUNDLL32.EXE %s,[email protected] %%1", szShort);
//LOG(LOG_INFO, "Links: registering (%s)", szExe);
#endif
RegSetValueA(hkey, NULL, REG_SZ, szExe, strlen(szExe));
RegCloseKey(hkey);
}
else {
//LOG(LOG_ERROR, "Links: register - unable to create registry key (command)");
return;
}
}
示例3: RegCreateKeyExA
int CGlobalSettings::SetGlobalValue(const char *product, const char *key, const char *value, int ival)
{
HKEY hKey,hSubKey;
DWORD dwLen;
cvs::string regkey;
if(!isAdmin())
return -1;
if(!product || !strcmp(product,"cvsnt"))
regkey="Software\\CVS";
else
cvs::sprintf(regkey,64,"Software\\March Hare Software Ltd\\%s",product);
if(RegOpenKeyExA(HKEY_LOCAL_MACHINE,regkey.c_str(),0,KEY_READ|KEY_WRITE,&hKey) &&
RegCreateKeyExA(HKEY_LOCAL_MACHINE,regkey.c_str(),0,NULL,0,KEY_READ|KEY_WRITE,NULL,&hKey,NULL))
{
return -1; // Couldn't open or create key
}
if(key)
{
if(RegOpenKeyExA(hKey,key,0,KEY_WRITE,&hSubKey) &&
RegCreateKeyExA(hKey,key,0,NULL,0,KEY_WRITE,NULL,&hSubKey,NULL))
{
RegCloseKey(hKey);
return -1; // Couldn't open or create key
}
RegCloseKey(hKey);
hKey=hSubKey;
}
DWORD dw = (DWORD)ival,err;
dwLen=(DWORD)sizeof(DWORD);
err = RegSetValueExA(hKey,value,0,REG_DWORD,(LPBYTE)&dw,dwLen);
if(err)
{
dw = GetLastError();
RegCloseKey(hKey);
return -1;
}
RegCloseKey(hKey);
return 0;
}
示例4: register_progid
/***********************************************************************
* regsvr_progid
*/
static LONG register_progid(
WCHAR const *clsid,
char const *progid,
char const *curver_progid,
char const *name,
char const *extra)
{
LONG res;
HKEY progid_key;
res = RegCreateKeyExA(HKEY_CLASSES_ROOT, progid, 0,
NULL, 0, KEY_READ | KEY_WRITE, NULL,
&progid_key, NULL);
if (res != ERROR_SUCCESS) return res;
if (name) {
res = RegSetValueExA(progid_key, NULL, 0, REG_SZ,
(CONST BYTE*)name, strlen(name) + 1);
if (res != ERROR_SUCCESS) goto error_close_progid_key;
}
if (clsid) {
res = register_key_defvalueW(progid_key, clsid_keyname, clsid);
if (res != ERROR_SUCCESS) goto error_close_progid_key;
}
if (curver_progid) {
res = register_key_defvalueA(progid_key, curver_keyname,
curver_progid);
if (res != ERROR_SUCCESS) goto error_close_progid_key;
}
if (extra) {
HKEY extra_key;
res = RegCreateKeyExA(progid_key, extra, 0,
NULL, 0, KEY_READ | KEY_WRITE, NULL,
&extra_key, NULL);
if (res == ERROR_SUCCESS)
RegCloseKey(extra_key);
}
error_close_progid_key:
RegCloseKey(progid_key);
return res;
}
示例5: ChangeRegKey
/***************************************************************************************************\
* Функа ChangeRegKey;
* изменение (добавление) значения параметра реестра (в данной ситуации добавляем своё значение в 'Path');
* Вход:
* hKey - дескриптор указанного ключа реестра;
* pszSubKey - адрес имени открываемого подключа (раздела реестра)
* pszValName - адрес имени параметра (значения);
* pszAddVal - адрес строкового значения, которое будет добавлено в уже существующее значение указанного параметра;
* Выход:
* 1 - если всё прошло успешно, или 0 - если хуйня
* Замметки:
* по умолчанию в этом модуле изменяется системная переменная окружения 'Path';
* в Win7/etc - это админская привилегия, так что будем аккуратней =)!
\***************************************************************************************************/
DWORD ChangeRegKey(HKEY hKey, char *pszSubKey, char *pszValName, char *pszAddVal)
{
long lRes;
HKEY hNewKey;
char *pszData;
DWORD num = MAX_LEN_BUF;
DWORD dwRes = 0;
lRes = RegOpenKeyExA(hKey, pszSubKey, 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hNewKey); //open the specified reg key;
if(lRes != ERROR_SUCCESS)
return 0;
lRes = RegQueryValueExA(hNewKey, pszValName, 0, 0, 0, &num); //get num_bytes for our buffer;
if(lRes != ERROR_SUCCESS)
return 0;
else
{
pszData = (char*)malloc(sizeof(char) * num + strlen(pszAddVal) + 1); //alloc
lRes = RegQueryValueExA(hNewKey, pszValName, 0, 0, pszData, &num); //get reg key value;
if(lRes != ERROR_SUCCESS)
{
free(pszData);
return 0;
}
}
strcat(pszData, pszAddVal); //add new value;
lRes = RegSetValueExA(hNewKey, pszValName, 0, REG_EXPAND_SZ, pszData, strlen(pszData) + 1); //update reg key value;
free(pszData);
if(lRes != ERROR_SUCCESS)
return 0;
lRes = RegCloseKey(hNewKey); //close reg key;
if(lRes != ERROR_SUCCESS)
return 0;
//tell the system (programs etc) about change (new path);
SendMessageTimeoutA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, &dwRes);
return 1;
}
示例6: add_dos_device
static void add_dos_device( const char *udi, const char *device,
const char *mount_point, const char *type )
{
struct dos_drive *drive;
/* first check if it already exists */
LIST_FOR_EACH_ENTRY( drive, &drives_list, struct dos_drive, entry )
{
if (!strcmp( udi, drive->udi )) goto found;
}
if (!(drive = HeapAlloc( GetProcessHeap(), 0, sizeof(*drive) ))) return;
if (!(drive->udi = HeapAlloc( GetProcessHeap(), 0, strlen(udi)+1 )))
{
HeapFree( GetProcessHeap(), 0, drive );
return;
}
strcpy( drive->udi, udi );
list_add_tail( &drives_list, &drive->entry );
found:
drive->drive = add_drive( device, type );
if (drive->drive != -1)
{
HKEY hkey;
set_mount_point( drive, mount_point );
WINE_TRACE( "added device %c: udi %s for %s on %s type %s\n",
'a' + drive->drive, wine_dbgstr_a(udi), wine_dbgstr_a(device),
wine_dbgstr_a(mount_point), wine_dbgstr_a(type) );
/* hack: force the drive type in the registry */
if (!RegCreateKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Drives", &hkey ))
{
char name[3] = "a:";
name[0] += drive->drive;
if (!type || strcmp( type, "cdrom" )) type = "floppy"; /* FIXME: default to floppy */
RegSetValueExA( hkey, name, 0, REG_SZ, (const BYTE *)type, strlen(type) + 1 );
RegCloseKey( hkey );
}
send_notify( drive->drive, DBT_DEVICEARRIVAL );
}
}
示例7: IStream_fnRelease
/**************************************************************************
* IStream_fnRelease
*/
static ULONG WINAPI IStream_fnRelease(IStream *iface)
{
ISHRegStream *This = impl_from_IStream(iface);
ULONG refCount = InterlockedDecrement(&This->ref);
TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
if (!refCount)
{
TRACE(" destroying SHReg IStream (%p)\n",This);
if (This->hKey)
{
/* write back data in REG_BINARY */
if (This->dwMode == STGM_READWRITE || This->dwMode == STGM_WRITE)
{
if (This->dwLength)
{
if (This->bUnicode)
RegSetValueExW(This->hKey, This->u.keyNameW, 0, REG_BINARY,
(const BYTE *) This->pbBuffer, This->dwLength);
else
RegSetValueExA(This->hKey, This->u.keyNameA, 0, REG_BINARY,
(const BYTE *) This->pbBuffer, This->dwLength);
}
else
{
if (This->bUnicode)
RegDeleteValueW(This->hKey, This->u.keyNameW);
else
RegDeleteValueA(This->hKey, This->u.keyNameA);
}
}
RegCloseKey(This->hKey);
}
HeapFree(GetProcessHeap(),0,This->u.keyNameA);
HeapFree(GetProcessHeap(),0,This->pbBuffer);
HeapFree(GetProcessHeap(),0,This);
return 0;
}
return refCount;
}
示例8: ReadWindowsRegistryInt
//----- (004649EF) --------------------------------------------------------
int __fastcall ReadWindowsRegistryInt(const char *pKey, int uDefValue)
{
DWORD cbData; // [sp+8h] [bp-20h]@1
LPCSTR lpValueName; // [sp+Ch] [bp-1Ch]@1
DWORD dwDisposition; // [sp+10h] [bp-18h]@2
BYTE Data[4]; // [sp+14h] [bp-14h]@5
HKEY hKey; // [sp+18h] [bp-10h]@1
HKEY phkResult; // [sp+1Ch] [bp-Ch]@1
HKEY v10; // [sp+20h] [bp-8h]@1
HKEY v11; // [sp+24h] [bp-4h]@1
lpValueName = pKey;
v11 = 0;
v10 = 0;
hKey = 0;
phkResult = 0;
cbData = 4;
if ( !RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE", 0, KEY_READ|KEY_WOW64_32KEY, &hKey) )// for 64 bit
{
if ( !RegCreateKeyExA(hKey, "New World Computing", 0, "", 0, 0xF003Fu, 0, &phkResult, &dwDisposition) )
{
if ( !RegCreateKeyExA(phkResult, "Might and Magic VII", 0, "", 0, 0xF003Fu, 0, &v10, &dwDisposition) )
{
if ( !RegCreateKeyExA(v10, "1.0", 0, "", 0, 0xF003Fu, 0, &v11, &dwDisposition) )
{
LSTATUS status;
if ( status = RegQueryValueExA(v11, lpValueName, 0, 0, Data, &cbData) )
{
status;
GetLastError();
*(int *)Data = uDefValue;
RegSetValueExA(v11, lpValueName, 0, 4u, Data, 4u);
}
RegCloseKey(v11);
}
RegCloseKey(v10);
}
RegCloseKey(phkResult);
}
RegCloseKey(hKey);
}
return *(int *)Data;
}
示例9: strncpy_s
bool Win32Registry::getString( const char *section,
const char *field,
const char *descriptive_field,
const char *default_val,
char *buf,
int buf_size )
{
DWORD size = buf_size;
DWORD type;
{
// read user key
if ( RegQueryValueExA(
m_user_key, field, 0, &type, (LPBYTE)buf, &size )
!= ERROR_SUCCESS || type != REG_SZ )
{
// didnt work. Try read machine key
if ( RegQueryValueExA( m_machine_key,
field,
0,
&type,
(LPBYTE)buf,
&size ) != ERROR_SUCCESS
|| type != REG_SZ )
{
// still didnt work. write default to machine key
// and return default.
strncpy_s( buf, buf_size, default_val, buf_size - 1 );
buf[buf_size - 1] = 0;
RegSetValueExA( m_machine_key,
field,
0,
REG_SZ,
(LPBYTE)buf,
strlen( buf ) + 1 );
return false;
}
}
}
return true;
}
示例10: setLucidRegValue
void setLucidRegValue(const CString csSectionPath, const CString csKey, CString csValue)
{
HKEY myKey;
DWORD varType = REG_SZ; //the value's a REG_SZ type
DWORD buffSize = 1024;
DWORD dwDisp;
char pBuf[1024] = {'\0'};
const int nLen = csValue.GetLength();
strcpy(pBuf, csValue.GetBuffer(nLen));
// if the Section Path doesn't exist then create it
if (RegOpenKeyEx(HKEY_CURRENT_USER,csSectionPath, 0, KEY_WRITE, &myKey)) {
RegCreateKeyEx(HKEY_CURRENT_USER, csSectionPath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &myKey, &dwDisp);
}
RegSetValueExA(myKey,csKey,0,varType,(const BYTE *)pBuf,sizeof(pBuf));
RegCloseKey(myKey);
csValue.ReleaseBuffer();
}
示例11: InitNodeId
void InitNodeId(Skype_Inst *pInst)
{
DWORD BufSz = sizeof(pInst->NodeID);
HKEY hKey;
if (QueryRegValue(HKEY_LOCAL_MACHINE,
"SOFTWARE\\FakeSkype\\NodeId",
(LPBYTE)&pInst->NodeID, &BufSz)) return;
*(int64_t *)&pInst->NodeID = BytesRandomI64();
if (RegCreateKeyA(HKEY_LOCAL_MACHINE, "SOFTWARE\\FakeSkype", &hKey) == ERROR_SUCCESS)
{
RegSetValueExA(hKey, "NodeId", 0, REG_BINARY, (LPBYTE)&pInst->NodeID, sizeof(pInst->NodeID));
RegCloseKey(hKey);
}
//FIXED NODEID
//memcpy_s(NodeID, NODEID_SZ, "\x49\x63\xff\xee\xe0\x5c\x9d\xf8", NODEID_SZ);
//memcpy_s(NodeID, NODEID_SZ, "\x97\xca\xb1\x72\x06\xf6\x72\xb4", NODEID_SZ);
}
示例12: strcpy
//-------------------------------------------------------------------------------
void CLogWindow::Save()
{
char szFileName[MAX_PATH];
DWORD dwTemp = MAX_PATH;
if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LogDestination",NULL,NULL,
(BYTE*)szFileName,&dwTemp))
{
// Key was not found. Use C:
strcpy(szFileName,"");
}
else
{
// need to remove the file name
char* sz = strrchr(szFileName,'\\');
if (!sz)
sz = strrchr(szFileName,'/');
if (sz)
*sz = 0;
}
OPENFILENAME sFilename1 = {
sizeof(OPENFILENAME),
g_hDlg,GetModuleHandle(NULL),
"Log files\0*.txt", NULL, 0, 1,
szFileName, MAX_PATH, NULL, 0, NULL,
"Save log to file",
OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
0, 1, ".txt", 0, NULL, NULL
};
if(GetSaveFileName(&sFilename1) == 0) return;
// Now store the file in the registry
RegSetValueExA(g_hRegistry,"LogDestination",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
FILE* pFile = fopen(szFileName,"wt");
fprintf(pFile,this->szPlainText.c_str());
fclose(pFile);
CLogDisplay::Instance().AddEntry("[INFO] The log file has been saved",
D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
}
示例13: WNetCachePassword
/**************************************************************************
* WNetCachePassword [[email protected]] Saves password in cache
*
* NOTES
* Only the parameter count is verified
*
* ---- everything below this line might be wrong (js) -----
* RETURNS
* Success: WN_SUCCESS
* Failure: WN_ACCESS_DENIED, WN_BAD_PASSWORD, WN_BADVALUE, WN_NET_ERROR,
* WN_NOT_SUPPORTED, WN_OUT_OF_MEMORY
*/
DWORD WINAPI WNetCachePassword(
LPSTR pbResource, /* [in] Name of workgroup, computer, or resource */
WORD cbResource, /* [in] Size of name */
LPSTR pbPassword, /* [in] Buffer containing password */
WORD cbPassword, /* [in] Size of password */
BYTE nType, /* [in] Type of password to cache */
WORD x)
{
HKEY hkey;
DWORD r;
LPSTR valname;
WARN( "(%p(%s), %d, %p(%s), %d, %d, 0x%08x): totally insecure\n",
pbResource, debugstr_a(pbResource), cbResource,
pbPassword, debugstr_a(pbPassword), cbPassword,
nType, x );
/* @@ Wine registry key: HKCU\Software\Wine\Wine\Mpr */
r = RegCreateKeyA( HKEY_CURRENT_USER, mpr_key, &hkey );
if( r )
return WN_ACCESS_DENIED;
valname = MPR_GetValueName( pbResource, cbResource, nType );
if( valname )
{
r = RegSetValueExA( hkey, valname, 0, REG_BINARY,
(LPBYTE)pbPassword, cbPassword );
if( r )
r = WN_CANCEL;
else
r = WN_SUCCESS;
HeapFree( GetProcessHeap(), 0, valname );
}
else
r = WN_OUT_OF_MEMORY;
RegCloseKey( hkey );
return r;
}
示例14: sizeof
long Win32Registry::getInt( const char *section,
const char *field,
const char *descriptive_field,
long default_val )
{
DWORD val = default_val;
DWORD size = sizeof( val );
DWORD type;
{
// try read user setting
if ( RegQueryValueExA(
m_user_key, field, 0, &type, (LPBYTE)&val, &size )
!= ERROR_SUCCESS || type != REG_DWORD )
{
// didnt work... try read machine key
if ( RegQueryValueExA( m_machine_key,
field,
0,
&type,
(LPBYTE)&val,
&size ) != ERROR_SUCCESS
|| type != REG_DWORD )
{
// still didnt work. Use default
// and write default to machine key
RegSetValueExA( m_machine_key,
field,
0,
REG_DWORD,
(LPBYTE)&val,
sizeof( val ) );
}
}
}
return val;
}
示例15: getExecutablePath
void WinWindow::doRunOnStart()
{
std::string runPath = "\"" + getExecutablePath() + "\" -m";
Helper::request_privileges(SE_TAKE_OWNERSHIP_NAME);
HKEY hKey;
LONG result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_WRITE, &hKey);
if (result == ERROR_SUCCESS)
{
if ((result = RegSetValueExA( hKey, "NOSA-Server", 0, REG_SZ, (BYTE*)runPath.c_str(), runPath.length())) == ERROR_SUCCESS)
MessageBox(NULL, "Now NOSA-Server service will launch of computer start.", "Done!", MB_ICONINFORMATION | MB_OK);
else
MessageBox(NULL, "You don't have sufficient rights to edit your registry. Please try run this application with admin privilege.", "Error!", MB_ICONERROR | MB_OK);
}
else
MessageBox(NULL, "Your registry has wrong format!", "Error!", MB_ICONERROR | MB_OK);
RegCloseKey(hKey);
return;
}