本文整理汇总了C++中RegSetValueEx函数的典型用法代码示例。如果您正苦于以下问题:C++ RegSetValueEx函数的具体用法?C++ RegSetValueEx怎么用?C++ RegSetValueEx使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RegSetValueEx函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AMovieSetupRegisterServer
STDAPI
AMovieSetupRegisterServer( CLSID clsServer
, LPCWSTR szDescription
, LPCWSTR szFileName
, LPCWSTR szThreadingModel = L"Both"
, LPCWSTR szServerType = L"InprocServer32" )
{
// temp buffer
//
TCHAR achTemp[MAX_PATH];
// convert CLSID uuid to string and write
// out subkey as string - CLSID\{}
//
OLECHAR szCLSID[CHARS_IN_GUID];
HRESULT hr = StringFromGUID2( clsServer
, szCLSID
, CHARS_IN_GUID );
ASSERT( SUCCEEDED(hr) );
// create key
//
HKEY hkey;
(void)StringCchPrintf( achTemp, NUMELMS(achTemp), TEXT("CLSID\\%ls"), szCLSID );
LONG lreturn = RegCreateKey( HKEY_CLASSES_ROOT
, (LPCTSTR)achTemp
, &hkey );
if( ERROR_SUCCESS != lreturn )
{
return AmHresultFromWin32(lreturn);
}
// set description string
//
(void)StringCchPrintf( achTemp, NUMELMS(achTemp), TEXT("%ls"), szDescription );
lreturn = RegSetValue( hkey
, (LPCTSTR)NULL
, REG_SZ
, achTemp
, sizeof(achTemp) );
if( ERROR_SUCCESS != lreturn )
{
RegCloseKey( hkey );
return AmHresultFromWin32(lreturn);
}
// create CLSID\\{"CLSID"}\\"ServerType" key,
// using key to CLSID\\{"CLSID"} passed back by
// last call to RegCreateKey().
//
HKEY hsubkey;
(void)StringCchPrintf( achTemp, NUMELMS(achTemp), TEXT("%ls"), szServerType );
lreturn = RegCreateKey( hkey
, achTemp
, &hsubkey );
if( ERROR_SUCCESS != lreturn )
{
RegCloseKey( hkey );
return AmHresultFromWin32(lreturn);
}
// set Server string
//
(void)StringCchPrintf( achTemp, NUMELMS(achTemp), TEXT("%ls"), szFileName );
lreturn = RegSetValue( hsubkey
, (LPCTSTR)NULL
, REG_SZ
, (LPCTSTR)achTemp
, sizeof(TCHAR) * (lstrlen(achTemp)+1) );
if( ERROR_SUCCESS != lreturn )
{
RegCloseKey( hkey );
RegCloseKey( hsubkey );
return AmHresultFromWin32(lreturn);
}
(void)StringCchPrintf( achTemp, NUMELMS(achTemp), TEXT("%ls"), szThreadingModel );
lreturn = RegSetValueEx( hsubkey
, TEXT("ThreadingModel")
, 0L
, REG_SZ
, (CONST BYTE *)achTemp
, sizeof(TCHAR) * (lstrlen(achTemp)+1) );
// close hkeys
//
RegCloseKey( hkey );
RegCloseKey( hsubkey );
// and return
//
return HRESULT_FROM_WIN32(lreturn);
}
示例2: DlgProcSettings
INT_PTR CALLBACK DlgProcSettings(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
static TCHAR customCommand[MAX_PATH] = {0};
static TCHAR customText[TITLE_SIZE] = {0};
static TCHAR szKeyTemp[MAX_PATH + GUID_STRING_SIZE];
static DWORD showMenu = 2; //0 off, 1 on, 2 unknown
static DWORD showIcon = 2;
static DWORD isDynamic = 1; //0 off, 1 on
static DWORD useMenuIcon = 1; // 0 off, otherwise on
static DWORD iconType = 0; //0 classic, 1 modern
HKEY settingKey;
LONG result;
DWORD size = 0;
switch(uMsg) {
case WM_INITDIALOG: {
wsprintf(szKeyTemp, TEXT("CLSID\\%s\\Settings"), szGUID);
result = RegOpenKeyEx(HKEY_CLASSES_ROOT, szKeyTemp, 0, KEY_READ, &settingKey);
if (result == ERROR_SUCCESS) {
size = sizeof(TCHAR)*TITLE_SIZE;
result = RegQueryValueEx(settingKey, TEXT("Title"), NULL, NULL, (LPBYTE)(customText), &size);
if (result != ERROR_SUCCESS) {
lstrcpyn(customText, szDefaultMenutext, TITLE_SIZE);
}
size = sizeof(TCHAR)*MAX_PATH;
result = RegQueryValueEx(settingKey, TEXT("Custom"), NULL, NULL, (LPBYTE)(customCommand), &size);
if (result != ERROR_SUCCESS) {
lstrcpyn(customCommand, TEXT(""), MAX_PATH);
}
size = sizeof(DWORD);
result = RegQueryValueEx(settingKey, TEXT("IconID"), NULL, NULL, (BYTE*)(&iconType), &size);
if (result != ERROR_SUCCESS) {
iconType = 0;
}
size = sizeof(DWORD);
result = RegQueryValueEx(settingKey, TEXT("Dynamic"), NULL, NULL, (BYTE*)(&isDynamic), &size);
if (result != ERROR_SUCCESS) {
isDynamic = 1;
}
size = sizeof(DWORD);
result = RegQueryValueEx(settingKey, TEXT("ShowIcon"), NULL, NULL, (BYTE*)(&useMenuIcon), &size);
if (result != ERROR_SUCCESS) {
useMenuIcon = 1;
}
RegCloseKey(settingKey);
}
Button_SetCheck(GetDlgItem(hwndDlg, IDC_CHECK_USECONTEXT), BST_INDETERMINATE);
Button_SetCheck(GetDlgItem(hwndDlg, IDC_CHECK_USEICON), BST_INDETERMINATE);
Button_SetCheck(GetDlgItem(hwndDlg, IDC_CHECK_CONTEXTICON), useMenuIcon?BST_CHECKED:BST_UNCHECKED);
Button_SetCheck(GetDlgItem(hwndDlg, IDC_CHECK_ISDYNAMIC), isDynamic?BST_CHECKED:BST_UNCHECKED);
Button_SetCheck(GetDlgItem(hwndDlg, IDC_RADIO_CLASSIC), iconType!=0?BST_CHECKED:BST_UNCHECKED);
Button_SetCheck(GetDlgItem(hwndDlg, IDC_RADIO_MODERN), iconType==0?BST_CHECKED:BST_UNCHECKED);
SetDlgItemText(hwndDlg, IDC_EDIT_MENU, customText);
SetDlgItemText(hwndDlg, IDC_EDIT_COMMAND, customCommand);
return TRUE;
break; }
case WM_COMMAND: {
switch(LOWORD(wParam)) {
case IDOK: {
//Store settings
GetDlgItemText(hwndDlg, IDC_EDIT_MENU, customText, TITLE_SIZE);
GetDlgItemText(hwndDlg, IDC_EDIT_COMMAND, customCommand, MAX_PATH);
int textLen = lstrlen(customText);
int commandLen = lstrlen(customCommand);
wsprintf(szKeyTemp, TEXT("CLSID\\%s\\Settings"), szGUID);
result = RegCreateKeyEx(HKEY_CLASSES_ROOT, szKeyTemp, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &settingKey, NULL);
if (result == ERROR_SUCCESS) {
result = RegSetValueEx(settingKey, TEXT("Title"), 0,REG_SZ, (LPBYTE)customText, (textLen+1)*sizeof(TCHAR));
result = RegSetValueEx(settingKey, TEXT("Custom"), 0,REG_SZ, (LPBYTE)customCommand, (commandLen+1)*sizeof(TCHAR));
result = RegSetValueEx(settingKey, TEXT("IconID"), 0, REG_DWORD, (LPBYTE)&iconType, sizeof(DWORD));
result = RegSetValueEx(settingKey, TEXT("Dynamic"), 0, REG_DWORD, (LPBYTE)&isDynamic, sizeof(DWORD));
result = RegSetValueEx(settingKey, TEXT("ShowIcon"), 0, REG_DWORD, (LPBYTE)&useMenuIcon, sizeof(DWORD));
RegCloseKey(settingKey);
}
if (showMenu == 1) {
result = RegCreateKeyEx(HKEY_CLASSES_ROOT, TEXT("*\\shellex\\ContextMenuHandlers\\Notepad++")sz64, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &settingKey, NULL);
if (result == ERROR_SUCCESS) {
result = RegSetValueEx(settingKey, NULL, 0,REG_SZ, (LPBYTE)szGUID, (lstrlen(szGUID)+1)*sizeof(TCHAR));
RegCloseKey(settingKey);
}
} else if (showMenu == 0) {
wsprintf(szKeyTemp, TEXT("*\\shellex\\ContextMenuHandlers\\%s")sz64, szShellExtensionTitle);
RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp);
//.........这里部分代码省略.........
示例3: smpd_set_smpd_data
int smpd_set_smpd_data(const char *key, const char *value)
{
#ifdef HAVE_WINDOWS_H
HKEY tkey;
DWORD len, result;
char err_msg[512];
smpd_enter_fn(FCNAME);
if (key == NULL || value == NULL)
{
smpd_exit_fn(FCNAME);
return SMPD_FAIL;
}
result = RegCreateKeyEx(HKEY_LOCAL_MACHINE, SMPD_REGISTRY_KEY,
0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &tkey, NULL);
if (result != ERROR_SUCCESS)
{
smpd_translate_win_error(result, err_msg, 512, "Unable to open the HKEY_LOCAL_MACHINE\\" SMPD_REGISTRY_KEY " registry key, error %d\n", result);
smpd_err_printf("%s\n", err_msg);
smpd_exit_fn(FCNAME);
return SMPD_FAIL;
}
len = (DWORD)(strlen(value)+1);
result = RegSetValueEx(tkey, key, 0, REG_SZ, (const BYTE *)value, len);
if (result != ERROR_SUCCESS)
{
smpd_translate_win_error(result, err_msg, 512, "Unable to write the smpd registry value '%s:%s', error %d\n", key, value, result);
smpd_err_printf("%s\n", err_msg);
RegCloseKey(tkey);
smpd_exit_fn(FCNAME);
return SMPD_FAIL;
}
result = RegCloseKey(tkey);
if (result != ERROR_SUCCESS)
{
smpd_translate_win_error(result, err_msg, 512, "Unable to close the HKEY_LOCAL_MACHINE\\" SMPD_REGISTRY_KEY " registry key, error %d: ", result);
smpd_err_printf("%s\n", err_msg);
smpd_exit_fn(FCNAME);
return SMPD_FAIL;
}
smpd_exit_fn(FCNAME);
return SMPD_SUCCESS;
#else
int result;
smpd_data_t *list = NULL, *node;
int found = 0;
FILE *fout;
char *str;
int maxlen;
char buffer[1024];
char name_str[SMPD_MAX_NAME_LENGTH];
char value_str[SMPD_MAX_VALUE_LENGTH];
smpd_enter_fn(FCNAME);
smpd_dbg_printf("setting smpd data: %s=%s\n", key, value);
list = smpd_parse_smpd_file();
fout = smpd_open_smpd_file(SMPD_TRUE);
if (fout == NULL)
{
smpd_err_printf("Unable to open the .smpd file\n");
smpd_exit_fn(FCNAME);
return SMPD_FAIL;
}
while (list)
{
node = list;
list = list->next;
if (strcmp(key, node->name) == 0)
{
strcpy(node->value, value);
found = 1;
}
if (fout)
{
str = buffer;
maxlen = 1024;
if (MPIU_Str_add_string_arg(&str, &maxlen, node->name, node->value) == MPIU_STR_SUCCESS)
{
buffer[strlen(buffer)-1] = '\0'; /* remove the trailing space */
smpd_dbg_printf("writing '%s' to .smpd file\n", buffer);
fprintf(fout, "%s\n", buffer);
}
}
MPIU_Free(node);
}
if (!found && fout)
{
str = buffer;
maxlen = 1024;
if (MPIU_Str_add_string_arg(&str, &maxlen, key, value) == MPIU_STR_SUCCESS)
{
buffer[strlen(buffer)-1] = '\0'; /* remove the trailing space */
smpd_dbg_printf("writing '%s' to .smpd file\n", buffer);
//.........这里部分代码省略.........
示例4: Set
BOOL CRegMgr::Set(const char* sKey, DWORD nValue) {
if (!m_bInitialized) return FALSE;
if (sKey == NULL) return FALSE;
if (RegSetValueEx(m_hSubKey,sKey,0,REG_DWORD,(const unsigned char*)&nValue,sizeof(nValue)) == ERROR_SUCCESS) return TRUE;
else return FALSE;
};
示例5: lutil_srv_install
int lutil_srv_install(LPCTSTR lpszServiceName, LPCTSTR lpszDisplayName,
LPCTSTR lpszBinaryPathName, int auto_start)
{
HKEY hKey;
DWORD dwValue, dwDisposition;
SC_HANDLE schSCManager, schService;
char *sp = strchr( lpszBinaryPathName, ' ');
if ( sp ) *sp = '\0';
fprintf( stderr, "The install path is %s.\n", lpszBinaryPathName );
if ( sp ) *sp = ' ';
if ((schSCManager = OpenSCManager( NULL, NULL, SC_MANAGER_CONNECT|SC_MANAGER_CREATE_SERVICE ) ) != NULL )
{
if ((schService = CreateService(
schSCManager,
lpszServiceName,
lpszDisplayName,
SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS,
auto_start ? SERVICE_AUTO_START : SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL,
lpszBinaryPathName,
NULL, NULL, NULL, NULL, NULL)) != NULL)
{
char regpath[132];
CloseServiceHandle(schService);
CloseServiceHandle(schSCManager);
snprintf( regpath, sizeof regpath,
"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",
lpszServiceName );
/* Create the registry key for event logging to the Windows NT event log. */
if ( RegCreateKeyEx(HKEY_LOCAL_MACHINE,
regpath, 0,
"REG_SZ", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,
&dwDisposition) != ERROR_SUCCESS)
{
fprintf( stderr, "RegCreateKeyEx() failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
RegCloseKey(hKey);
return(0);
}
if ( sp ) *sp = '\0';
if ( RegSetValueEx(hKey, "EventMessageFile", 0, REG_EXPAND_SZ, lpszBinaryPathName, strlen(lpszBinaryPathName) + 1) != ERROR_SUCCESS)
{
fprintf( stderr, "RegSetValueEx(EventMessageFile) failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
RegCloseKey(hKey);
return(0);
}
dwValue = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
if ( RegSetValueEx(hKey, "TypesSupported", 0, REG_DWORD, (LPBYTE) &dwValue, sizeof(DWORD)) != ERROR_SUCCESS)
{
fprintf( stderr, "RegCreateKeyEx(TypesSupported) failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
RegCloseKey(hKey);
return(0);
}
RegCloseKey(hKey);
return(1);
}
else
{
fprintf( stderr, "CreateService() failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
CloseServiceHandle(schSCManager);
return(0);
}
}
else
fprintf( stderr, "OpenSCManager() failed. GetLastError=%lu (%s)\n", GetLastError(), GetLastErrorString() );
return(0);
}
示例6: service
//.........这里部分代码省略.........
service = OpenService(manager, mName.c_str(), SC_MANAGER_ALL_ACCESS);
if (service != NULL) {
if (!ChangeServiceConfig(
service, // handle of service
SERVICE_NO_CHANGE, // service type: no change
SERVICE_NO_CHANGE, // service start type
SERVICE_NO_CHANGE, // error control: no change
path, // binary path: no change
NULL, // load order group: no change
NULL, // tag ID: no change
NULL, // dependencies: no change
NULL, // account name: no change
NULL, // password: no change
NULL) ) // display name: no change
{
sLogger << dlib::LERROR << "ChangeServiceConfig failed (" << GetLastError() << ")";
CloseServiceHandle(manager);
return;
}
} else {
// Create the service
service = CreateService(
manager, // SCM database
mName.c_str(), // name of service
mName.c_str(), // service name to display
SERVICE_ALL_ACCESS, // desired access
SERVICE_WIN32_OWN_PROCESS, // service type
SERVICE_AUTO_START, // start type
SERVICE_ERROR_NORMAL, // error control type
path, // path to service's binary
NULL, // no load ordering group
NULL, // no tag identifier
NULL, // no dependencies
NULL, // LocalSystem account
NULL); // no password
if (service == NULL)
{
sLogger << dlib::LERROR << "CreateService failed (" << GetLastError() << ")";
CloseServiceHandle(manager);
return;
}
}
CloseServiceHandle(service);
CloseServiceHandle(manager);
HKEY software;
LONG res = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE", &software);
if (res != ERROR_SUCCESS)
{
sLogger << dlib::LERROR << "Could not open software key (" << res << ")";
return;
}
HKEY mtc;
res = RegOpenKey(software, "MTConnect", &mtc);
if (res != ERROR_SUCCESS)
{
res = RegCreateKey(software, "MTConnect", &mtc);
RegCloseKey(software);
if (res != ERROR_SUCCESS)
{
sLogger << dlib::LERROR << "Could not create MTConnect (" << res << ")";
return;
}
}
RegCloseKey(software);
// Create Service Key
HKEY agent;
res = RegOpenKey(mtc, mName.c_str(), &agent);
if (res != ERROR_SUCCESS)
{
res = RegCreateKey(mtc, mName.c_str(), &agent);
if (res != ERROR_SUCCESS)
{
RegCloseKey(mtc);
sLogger << dlib::LERROR << "Could not create " << mName << " (" << res << ")";
return;
}
}
RegCloseKey(mtc);
// Fully qualify the configuration file name.
if (mConfigFile[0] != '/' && mConfigFile[0] != '\\' && mConfigFile[1] != ':')
{
// Relative file name
char path[MAX_PATH];
GetCurrentDirectory(MAX_PATH, path);
mConfigFile = ((std::string) path) + "\\" + mConfigFile;
}
RegSetValueEx(agent, "ConfigurationFile", 0, REG_SZ, (const BYTE*) mConfigFile.c_str(),
mConfigFile.size() + 1);
RegCloseKey(agent);
sLogger << dlib::LINFO << "Service installed successfully.";
}
示例7: _sntprintf
void CRepositoryPage::RebuildRootList()
{
std::wstring path,alias,desc,name,rem_serv,rem_repos,rem_pass;
DWORD pub,def,onl,rw,ty;
TCHAR tmp[64];
int j;
size_t n;
for(n=0; n<MAX_REPOSITORIES; n++)
{
_sntprintf(tmp,sizeof(tmp),_T("Repository%d"),n);
RegDeleteValue(g_hServerKey,tmp);
_sntprintf(tmp,sizeof(tmp),_T("Repository%dName"),n);
RegDeleteValue(g_hServerKey,tmp);
_sntprintf(tmp,sizeof(tmp),_T("Repository%dDescription"),n);
RegDeleteValue(g_hServerKey,tmp);
_sntprintf(tmp,sizeof(tmp),_T("Repository%dDefault"),n);
RegDeleteValue(g_hServerKey,tmp);
_sntprintf(tmp,sizeof(tmp),_T("Repository%dPublish"),n);
RegDeleteValue(g_hServerKey,tmp);
_sntprintf(tmp,sizeof(tmp),_T("Repository%dOnline"),n);
RegDeleteValue(g_hServerKey,tmp);
}
for(n=0,j=0; n<m_Roots.size(); n++)
{
path=m_Roots[n].root;
alias=m_Roots[n].name;
desc=m_Roots[n].description;
pub=m_Roots[n].publish?1:0;
def=m_Roots[n].isdefault?1:0;
onl=m_Roots[n].online?1:0;
rw=m_Roots[n].readwrite?1:0;
ty=m_Roots[n].type;
rem_serv=m_Roots[n].remote_server;
rem_repos=m_Roots[n].remote_repository;
rem_pass=m_Roots[n].remote_passphrase;
if(m_Roots[n].valid)
{
_sntprintf(tmp,sizeof(tmp),_T("Repository%d"),j);
RegSetValueEx(g_hServerKey,tmp,NULL,REG_SZ,(BYTE*)path.c_str(),(path.length()+1)*sizeof(TCHAR));
_sntprintf(tmp,sizeof(tmp),_T("Repository%dName"),j);
RegSetValueEx(g_hServerKey,tmp,NULL,REG_SZ,(BYTE*)alias.c_str(),(alias.length()+1)*sizeof(TCHAR));
_sntprintf(tmp,sizeof(tmp),_T("Repository%dDescription"),j);
RegSetValueEx(g_hServerKey,tmp,NULL,REG_SZ,(BYTE*)desc.c_str(),(desc.length()+1)*sizeof(TCHAR));
_sntprintf(tmp,sizeof(tmp),_T("Repository%dPublish"),j);
RegSetValueEx(g_hServerKey,tmp,NULL,REG_DWORD,(BYTE*)&pub,sizeof(DWORD));
_sntprintf(tmp,sizeof(tmp),_T("Repository%dDefault"),j);
RegSetValueEx(g_hServerKey,tmp,NULL,REG_DWORD,(BYTE*)&def,sizeof(DWORD));
_sntprintf(tmp,sizeof(tmp),_T("Repository%dOnline"),j);
RegSetValueEx(g_hServerKey,tmp,NULL,REG_DWORD,(BYTE*)&onl,sizeof(DWORD));
_sntprintf(tmp,sizeof(tmp),_T("Repository%dReadWrite"),j);
RegSetValueEx(g_hServerKey,tmp,NULL,REG_DWORD,(BYTE*)&rw,sizeof(DWORD));
_sntprintf(tmp,sizeof(tmp),_T("Repository%dType"),j);
RegSetValueEx(g_hServerKey,tmp,NULL,REG_DWORD,(BYTE*)&ty,sizeof(DWORD));
_sntprintf(tmp,sizeof(tmp),_T("Repository%dRemoteServer"),j);
RegSetValueEx(g_hServerKey,tmp,NULL,REG_SZ,(BYTE*)rem_serv.c_str(),(rem_serv.length()+1)*sizeof(TCHAR));
_sntprintf(tmp,sizeof(tmp),_T("Repository%dRemoteRepository"),j);
RegSetValueEx(g_hServerKey,tmp,NULL,REG_SZ,(BYTE*)rem_repos.c_str(),(rem_repos.length()+1)*sizeof(TCHAR));
_sntprintf(tmp,sizeof(tmp),_T("Repository%dRemotePassphrase"),j);
RegSetValueEx(g_hServerKey,tmp,NULL,REG_SZ,(BYTE*)rem_pass.c_str(),(rem_pass.length()+1)*sizeof(TCHAR));
j++;
}
}
RegDeleteValue(g_hServerKey,_T("RepositoryPrefix"));
name.resize(256);
m_edServerName.GetWindowText((LPTSTR)name.data(),name.size());
name.resize(wcslen(name.c_str()));
RegSetValueEx(g_hServerKey,_T("ServerName"),NULL,REG_SZ,(BYTE*)name.c_str(),(name.length()+1)*sizeof(TCHAR));
}
示例8: RegSetValueEx
void RegKey::setInt(tstring valueName,DWORD value) {
LONG nStatus = RegSetValueEx(key,
valueName.c_str(),0,
REG_DWORD,
(LPBYTE)&value,sizeof(DWORD));
}
示例9: DoJob_Step2
LPCSTR DoJob_Step2 (LPCSTR psz)
{
DWORD dwSize = *(LPDWORD(psz));
psz += sizeof (DWORD);
CopyMemory (_szPostVersion, psz, dwSize);
_szPostVersion [dwSize] = 0;
psz += dwSize;
DWORD dwErr;
dwErr = RegCreateKey (HKEY_CURRENT_USER,
"Software\\FreeDownloadManager.ORG\\Free Download Manager",
&_hFDMKey);
if (dwErr == ERROR_SUCCESS)
RegSetValueEx (_hFDMKey, "PostVersion", NULL, REG_SZ, LPBYTE (_szPostVersion), lstrlen (_szPostVersion));
char szCustomizer [1000];
dwSize = *((LPDWORD) psz);
psz += sizeof (DWORD);
CopyMemory (szCustomizer, psz, dwSize);
szCustomizer [dwSize] = 0;
psz += dwSize;
dwSize = *((LPDWORD) psz);
psz += sizeof (DWORD);
CopyMemory (_szCustSite, psz, dwSize);
_szCustSite [dwSize] = 0;
psz += dwSize;
RegSetValueEx (_hFDMKey, "Customizer", NULL, REG_SZ, LPBYTE (szCustomizer), lstrlen (szCustomizer));
RegSetValueEx (_hFDMKey, "CustSite", NULL, REG_SZ, LPBYTE (_szCustSite), lstrlen (_szCustSite));
_dwFlags = *((LPDWORD) psz);
psz += sizeof (DWORD);
DWORD dw = 1;
if (_dwFlags & (FC_ADDLINKTOFAVOR | FC_ADDLINKTOSTARTMENU))
{
if (_dwFlags & FC_ADDLINKTOFAVOR)
{
if (_dwFlags & FC_FAV_OPTIONAL)
{
dw = 2;
if (_dwFlags & FC_FAV_CHECKEDBYDEF)
dw = 3;
}
RegSetValueEx (_hFDMKey, "CreateLFM", 0, REG_DWORD, (LPBYTE)&dw, 4);
dw = 1;
}
if (_dwFlags & FC_ADDLINKTOSTARTMENU)
{
if (_dwFlags & FC_SM_OPTIONAL)
{
dw = 2;
if (_dwFlags & FC_SM_CHECKEDBYDEF)
dw = 3;
}
RegSetValueEx (_hFDMKey, "CreateLSM", 0, REG_DWORD, (LPBYTE)&dw, 4);
dw = 1;
}
}
if (_dwFlags & FC_MODIFYHOMEPAGE)
{
dw = 2;
if (_dwFlags & FC_MHP_CHECKEDBYDEF)
dw = 3;
RegSetValueEx (_hFDMKey, "UseHPage", 0, REG_DWORD, (LPBYTE)&dw, sizeof (dw));
RegSetValueEx (_hFDMKey, "HPageTo", 0, REG_SZ, (LPBYTE)_szCustSite, lstrlen (_szCustSite));
dw = 1;
}
if (_dwFlags & FC_ADDBUTTONTOIE)
{
if (_dwFlags & FC_IEBTN_OPTIONAL)
{
dw = 2;
if (_dwFlags & FC_IEBTN_CHECKEDBYDEF)
dw = 3;
}
RegSetValueEx (_hFDMKey, "IEBtn", 0, REG_DWORD, (LPBYTE)&dw, sizeof (dw));
dw = 1;
}
return psz;
}
示例10: installService
//.........这里部分代码省略.........
szPath, // service's binary
NULL, // no load ordering group
NULL, // no tag identifier
TEXT(SZDEPENDENCIES), // dependencies
NULL, // LocalSystem account
NULL); // no password
if (schService) {
_tprintf(TEXT("%s installed.\n"), TEXT(SZSERVICEDISPLAYNAME) );
// Close the handle to this service object
CloseServiceHandle(schService);
/* ****************************************** */
// Set the service name. Courtesy of Yuri Francalacci <[email protected]>
sprintf(szParamKey2, "SYSTEM\\CurrentControlSet\\Services\\%s",SZSERVICENAME);
strcpy(szDescr, "ntopng: Web-based network traffic monitor");
// Set the file value (where the message resources are located.... in this case, our runfile.)
if(0 != setStringValue((const unsigned char *)szDescr,
strlen(szDescr) + 1,HKEY_LOCAL_MACHINE, szParamKey2,TEXT("Description")))
{
_tprintf(TEXT("The Message File value could\nnot be assigned.\n"));
}
/* ********************************************** */
//Make a registry key to support logging messages using the service name.
sprintf(szParamKey2, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s",SZSERVICENAME);
if(0 != makeNewKey(HKEY_LOCAL_MACHINE, szParamKey2)) {
_tprintf(TEXT("The EventLog subkey could not be created.\n"));
}
// Set the file value (where the message resources are located.... in this case, our runfile.)
if(0 != setStringValue((const unsigned char *) szPath,
strlen(szPath) + 1,HKEY_LOCAL_MACHINE,
szParamKey2,TEXT("EventMessageFile")))
{
_tprintf(TEXT("The Message File value could\nnot be assigned.\n"));
}
// Set the supported types flags.
if(0 != setDwordValue(EVENTLOG_INFORMATION_TYPE,HKEY_LOCAL_MACHINE, szParamKey2,TEXT("TypesSupported"))) {
_tprintf(TEXT("The Types Supported value could\nnot be assigned.\n"));
}
// Try to create a subkey to hold the runtime args for the JavaVM and
// Java application
if(0 != makeNewKey(HKEY_LOCAL_MACHINE, szParamKey)) {
_tprintf(TEXT("Could not create Parameters subkey.\n"));
} else {
//Create an argument string from the argument list
// J. R. Duarte: modified it to store the full command line
convertArgListToArgString((LPTSTR) szAppParameters,0, argc, argv);
if(NULL == szAppParameters) {
_tprintf(TEXT("Could not create AppParameters string.\n"));
} else {
HKEY hkey;
DWORD disposition;
_TCHAR data[] = "redis\0\0";
// Try to save the argument string under the new subkey
if(0 != setStringValue(szAppParameters, strlen(szAppParameters)+1,
HKEY_LOCAL_MACHINE, szParamKey, SZAPPPARAMS)) {
_tprintf(TEXT("Could not save AppParameters value.\n"));
}
sprintf(szParamKey,"SYSTEM\\CurrentControlSet\\Services\\%s",SZSERVICENAME);
if( RegCreateKeyEx( HKEY_LOCAL_MACHINE, szParamKey,
0, "", 0, KEY_ALL_ACCESS, NULL, &hkey, &disposition) != ERROR_SUCCESS)
{
_tprintf(TEXT("Could not create service registry key"));
return;
}
strcpy(szAppParameters, "redis");
// Try to save the argument string under the new subkey
if(RegSetValueEx (hkey, TEXT("DependOnService"), 0, REG_MULTI_SZ, (LPBYTE)data, strlen(data)+2) != 0) {
_tprintf(TEXT("Could not save DependOnService value.\n"));
}
RegCloseKey(hkey);
}
}
}
else {
_tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256));
}
// Close the handle to the service control manager database
CloseServiceHandle(schSCManager);
}
else {
_tprintf(TEXT(SZSCMGRFAILURE), GetLastErrorText(szErr,256));
}
}
示例11: AddConfig
BOOL AddConfig(HKEY baseKey, DWORD id, const DomainInfo& info)
{
DWORD disposition;
HKEY subkey;
TCHAR x[128];
BOOL rval = TRUE;
wsprintf(x, _T("DomainInfo%03d"), id);
LONG result = RegCreateKeyEx(baseKey, x, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, &subkey, &disposition);
if (result == ERROR_SUCCESS) {
if (RegSetValueEx(subkey, _T("Http Timeout"), 0, REG_DWORD, (LPBYTE) &info.httpTimeout, (DWORD) sizeof(DWORD)) != ERROR_SUCCESS)
rval = FALSE;
if (RegSetValueEx(subkey, _T("Host Name"), 0, REG_EXPAND_SZ, (LPBYTE) info.hostname.c_str(), (DWORD) info.hostname.length() + 1) != ERROR_SUCCESS)
rval = FALSE;
if (RegSetValueEx(subkey, _T("Top Level Domain"), 0, REG_EXPAND_SZ, (LPBYTE) info.tld.c_str(), (DWORD) info.tld.length() + 1) != ERROR_SUCCESS)
rval = FALSE;
if (RegSetValueEx(subkey, _T("My IP Address"), 0, REG_EXPAND_SZ, (LPBYTE) info.myip.c_str(), (DWORD) info.myip.length() + 1) != ERROR_SUCCESS)
rval = FALSE;
if (RegSetValueEx(subkey, _T("MX"), 0, REG_EXPAND_SZ, (LPBYTE) info.mx.c_str(), (DWORD) info.mx.length() + 1) != ERROR_SUCCESS)
rval = FALSE;
if (RegSetValueEx(subkey, _T("Back MX"), 0, REG_EXPAND_SZ, (LPBYTE) info.backmx.c_str(), (DWORD) info.backmx.length() + 1) != ERROR_SUCCESS)
rval = FALSE;
if (RegSetValueEx(subkey, _T("Wildcard"), 0, REG_EXPAND_SZ, (LPBYTE) info.wildcard.c_str(), (DWORD) info.wildcard.length() + 1) != ERROR_SUCCESS)
rval = FALSE;
if (RegSetValueEx(subkey, _T("easyDNS URL"), 0, REG_EXPAND_SZ, (LPBYTE) info.easydnsurl.c_str(), (DWORD) info.easydnsurl.length() + 1) != ERROR_SUCCESS)
rval = FALSE;
if (RegSetValueEx(subkey, _T("Username"), 0, REG_EXPAND_SZ, (LPBYTE) info.username.c_str(), (DWORD) info.username.length() + 1) != ERROR_SUCCESS)
rval = FALSE;
DATA_BLOB in;
DATA_BLOB out;
in.cbData = (DWORD) info.password.length() + 1;
in.pbData = (BYTE*) info.password.c_str();
out.pbData = 0;
out.cbData = 0;
if (!CryptProtectData(&in, NULL, NULL, NULL, NULL, CRYPTPROTECT_LOCAL_MACHINE, &out))
rval = FALSE;
else if (RegSetValueEx(subkey, _T("Password"), 0, REG_BINARY, (LPBYTE) out.pbData, (DWORD) out.cbData) != ERROR_SUCCESS)
rval = FALSE;
if (out.pbData != 0)
LocalFree(out.pbData);
if (RegSetValueEx(subkey, _T("Proxy"), 0, REG_EXPAND_SZ, (LPBYTE) info.proxy.c_str(), (DWORD) info.proxy.length() + 1) != ERROR_SUCCESS)
rval = FALSE;
if (RegSetValueEx(subkey, _T("Proxy Port"), 0, REG_DWORD, (LPBYTE) &info.proxyPort, (DWORD) sizeof(DWORD)) != ERROR_SUCCESS)
rval = FALSE;
RegCloseKey(subkey);
}
else
rval = FALSE;
return rval;
}
示例12: service
//.........这里部分代码省略.........
SERVICE_NO_CHANGE, // service type: no change
SERVICE_NO_CHANGE, // service start type
SERVICE_NO_CHANGE, // error control: no change
path, // binary path: no change
NULL, // load order group: no change
NULL, // tag ID: no change
NULL, // dependencies: no change
NULL, // account name: no change
NULL, // password: no change
NULL) ) // display name: no change
{
sLogger << dlib::LERROR << "OpenService failed (" << GetLastError() << ")";
std::cerr << "OpenService failed (" << GetLastError() << ")" << std::endl;
CloseServiceHandle(manager);
return;
}
} else {
// Create the service
service = CreateService(
manager, // SCM database
mName.c_str(), // name of service
mName.c_str(), // service name to display
SERVICE_ALL_ACCESS, // desired access
SERVICE_WIN32_OWN_PROCESS, // service type
SERVICE_AUTO_START, // start type
SERVICE_ERROR_NORMAL, // error control type
path, // path to service's binary
NULL, // no load ordering group
NULL, // no tag identifier
"Tcpip\0Eventlog\0Netman\0", // dependencies
NULL, // LocalSystem account
NULL); // no password
if (service == NULL)
{
sLogger << dlib::LERROR << "CreateService failed (" << GetLastError() << ")";
std::cerr << "CreateService failed (" << GetLastError() << ")" << std::endl;
CloseServiceHandle(manager);
return;
}
}
CloseServiceHandle(service);
CloseServiceHandle(manager);
HKEY software;
LONG res = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE", &software);
if (res != ERROR_SUCCESS)
{
sLogger << dlib::LERROR << "Could not open software key (" << res << ")";
std::cerr << "Could not open software key (" << res << ")" << std::endl;
return;
}
HKEY mtc;
res = RegOpenKey(software, "MTConnect", &mtc);
if (res != ERROR_SUCCESS)
{
res = RegCreateKey(software, "MTConnect", &mtc);
RegCloseKey(software);
if (res != ERROR_SUCCESS)
{
sLogger << dlib::LERROR << "Could not create MTConnect (" << res << ")";
std::cerr << "Could not create MTConnect key (" << res << ")" << std::endl;
return;
}
}
RegCloseKey(software);
// Create Service Key
HKEY agent;
res = RegOpenKey(mtc, mName.c_str(), &agent);
if (res != ERROR_SUCCESS)
{
res = RegCreateKey(mtc, mName.c_str(), &agent);
if (res != ERROR_SUCCESS)
{
RegCloseKey(mtc);
sLogger << dlib::LERROR << "Could not create " << mName << " (" << res << ")";
std::cerr << "Could not create " << mName << " (" << res << ")" << std::endl;
return;
}
}
RegCloseKey(mtc);
// Fully qualify the configuration file name.
if (mConfigFile[0] != '/' && mConfigFile[0] != '\\' && mConfigFile[1] != ':')
{
// Relative file name
char path[MAX_PATH];
GetCurrentDirectory(MAX_PATH, path);
mConfigFile = ((std::string) path) + "\\" + mConfigFile;
}
RegSetValueEx(agent, "ConfigurationFile", 0, REG_SZ, (const BYTE*) mConfigFile.c_str(),
mConfigFile.size() + 1);
RegCloseKey(agent);
sLogger << dlib::LINFO << "Service installed successfully.";
}
示例13: DbgInitKeyLevels
void WINAPI DbgInitKeyLevels(HKEY hKey, bool fTakeMax)
{
LONG lReturn; // Create key return value
LONG lKeyPos; // Current key category
DWORD dwKeySize; // Size of the key value
DWORD dwKeyType; // Receives it's type
DWORD dwKeyValue; // This fields value
/* Try and read a value for each key position in turn */
for (lKeyPos = 0;lKeyPos < iMAXLEVELS;lKeyPos++) {
dwKeySize = sizeof(DWORD);
lReturn = RegQueryValueEx(
hKey, // Handle to an open key
pKeyNames[lKeyPos], // Subkey name derivation
NULL, // Reserved field
&dwKeyType, // Returns the field type
(LPBYTE) &dwKeyValue, // Returns the field's value
&dwKeySize ); // Number of bytes transferred
/* If either the key was not available or it was not a DWORD value
then we ensure only the high priority debug logging is output
but we try and update the field to a zero filled DWORD value */
if (lReturn != ERROR_SUCCESS || dwKeyType != REG_DWORD) {
dwKeyValue = 0;
lReturn = RegSetValueEx(
hKey, // Handle of an open key
pKeyNames[lKeyPos], // Address of subkey name
(DWORD) 0, // Reserved field
REG_DWORD, // Type of the key field
(PBYTE) &dwKeyValue, // Value for the field
sizeof(DWORD)); // Size of the field buffer
if (lReturn != ERROR_SUCCESS) {
DbgLog((LOG_ERROR,1,TEXT("Could not create subkey %s"),pKeyNames[lKeyPos]));
dwKeyValue = 0;
}
}
if(fTakeMax)
{
m_Levels[lKeyPos] = std::max(dwKeyValue, m_Levels[lKeyPos]);
}
else
{
if((m_Levels[lKeyPos] & LOG_FORCIBLY_SET) == 0) {
m_Levels[lKeyPos] = dwKeyValue;
}
}
}
/* Read the timeout value for catching hangs */
dwKeySize = sizeof(DWORD);
lReturn = RegQueryValueEx(
hKey, // Handle to an open key
TimeoutName, // Subkey name derivation
NULL, // Reserved field
&dwKeyType, // Returns the field type
(LPBYTE) &dwWaitTimeout, // Returns the field's value
&dwKeySize ); // Number of bytes transferred
/* If either the key was not available or it was not a DWORD value
then we ensure only the high priority debug logging is output
but we try and update the field to a zero filled DWORD value */
if (lReturn != ERROR_SUCCESS || dwKeyType != REG_DWORD) {
dwWaitTimeout = INFINITE;
lReturn = RegSetValueEx(
hKey, // Handle of an open key
TimeoutName, // Address of subkey name
(DWORD) 0, // Reserved field
REG_DWORD, // Type of the key field
(PBYTE) &dwWaitTimeout, // Value for the field
sizeof(DWORD)); // Size of the field buffer
if (lReturn != ERROR_SUCCESS) {
DbgLog((LOG_ERROR,1,TEXT("Could not create subkey %s"),pKeyNames[lKeyPos]));
dwWaitTimeout = INFINITE;
}
}
}
示例14: RegSetValueEx
LONG RegSetValueEx( HKEY hKey, const char* lpValueName, DWORD Reserved,
DWORD dwType, const BYTE* lpData, DWORD cbData )
{
return RegSetValueEx(hKey, PString(lpValueName).AsUCS2(), Reserved, dwType, lpData, cbData);
}
示例15: DbgInitLogTo
void WINAPI DbgInitLogTo (
HKEY hKey)
{
LONG lReturn;
DWORD dwKeyType;
DWORD dwKeySize;
TCHAR szFile[MAX_PATH] = {0};
static const TCHAR cszKey[] = TEXT("LogToFile");
dwKeySize = MAX_PATH;
lReturn = RegQueryValueEx(
hKey, // Handle to an open key
cszKey, // Subkey name derivation
NULL, // Reserved field
&dwKeyType, // Returns the field type
(LPBYTE) szFile, // Returns the field's value
&dwKeySize); // Number of bytes transferred
// create an empty key if it does not already exist
//
if (lReturn != ERROR_SUCCESS || dwKeyType != REG_SZ)
{
dwKeySize = sizeof(TCHAR);
lReturn = RegSetValueEx(
hKey, // Handle of an open key
cszKey, // Address of subkey name
(DWORD) 0, // Reserved field
REG_SZ, // Type of the key field
(PBYTE)szFile, // Value for the field
dwKeySize); // Size of the field buffer
}
// if an output-to was specified. try to open it.
//
if (m_hOutput != INVALID_HANDLE_VALUE) {
EXECUTE_ASSERT(CloseHandle (m_hOutput));
m_hOutput = INVALID_HANDLE_VALUE;
}
if (szFile[0] != 0)
{
if (!lstrcmpi(szFile, TEXT("Console"))) {
m_hOutput = GetStdHandle (STD_OUTPUT_HANDLE);
if (m_hOutput == INVALID_HANDLE_VALUE) {
AllocConsole ();
m_hOutput = GetStdHandle (STD_OUTPUT_HANDLE);
}
SetConsoleTitle (TEXT("ActiveX Debug Output"));
} else if (szFile[0] &&
lstrcmpi(szFile, TEXT("Debug")) &&
lstrcmpi(szFile, TEXT("Debugger")) &&
lstrcmpi(szFile, TEXT("Deb")))
{
m_hOutput = CreateFile(szFile, GENERIC_WRITE,
FILE_SHARE_READ,
NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (INVALID_HANDLE_VALUE == m_hOutput &&
GetLastError() == ERROR_SHARING_VIOLATION)
{
TCHAR uniqueName[MAX_PATH] = {0};
if (SUCCEEDED(DbgUniqueProcessName(szFile, uniqueName)))
{
m_hOutput = CreateFile(uniqueName, GENERIC_WRITE,
FILE_SHARE_READ,
NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
}
}
if (INVALID_HANDLE_VALUE != m_hOutput)
{
static const TCHAR cszBar[] = TEXT("\r\n\r\n=====DbgInitialize()=====\r\n\r\n");
LARGE_INTEGER zero = {0, 0};
SetFilePointerEx(m_hOutput, zero, NULL, FILE_END);
DbgOutString (cszBar);
}
}
}
}