void ScanExistingRegistryEntry(XPIDSTRUCT *scanstruct) { CString xpidkey=regkey+"\\"+scanstruct->xpidname; if(regMyReg.KeyExists(xpidkey, HKEY_LOCAL_MACHINE)) { //SCN5 was here before, load last settings regMyReg.Open( xpidkey, HKEY_LOCAL_MACHINE ); scanstruct->xpidsetting1.renameport=regMyReg["renameXPID1"]; scanstruct->xpidsetting1.renamename=regMyReg["renamename1"]; scanstruct->xpidsetting2.renameport=regMyReg["renameXPID2"]; scanstruct->xpidsetting2.renamename=regMyReg["renamename2"]; regMyReg.Close(); } else { regMyReg.Open( xpidkey, HKEY_LOCAL_MACHINE ); //Standard settings scanstruct->xpidsetting1.renameport=false; scanstruct->xpidsetting1.renamename=""; scanstruct->xpidsetting2.renameport=false; scanstruct->xpidsetting2.renamename=""; regMyReg.Open( xpidkey, HKEY_LOCAL_MACHINE ); regMyReg["renameXPID1"]=scanstruct->xpidsetting1.renameport; regMyReg["renamename1"]=scanstruct->xpidsetting1.renamename; regMyReg["renameXPID2"]=scanstruct->xpidsetting2.renameport; regMyReg["renamename2"]=scanstruct->xpidsetting2.renamename; CString regvalue; regMyReg.Close(); } }
BOOL CInterfacePluginV2App::InitInstance() { CWinApp::InitInstance(); shutdowndialog=false; //Get global timeout settings out of registry if(regMyReg.KeyExists(regkey,HKEY_LOCAL_MACHINE)) { regMyReg.Open( regkey, HKEY_LOCAL_MACHINE ); if(regMyReg["enableTimeout"].Exists()) { enabletimeout=regMyReg["enabletimeout"]; timeoutdelay=regMyReg["timeoutdelay"]; } else { enabletimeout=TRUE; timeoutdelay=30; regMyReg["enabletimeout"]=enabletimeout; regMyReg["timeoutdelay"]=timeoutdelay; } regMyReg.Close(); } else { regMyReg.Open( regkey, HKEY_LOCAL_MACHINE ); enabletimeout=TRUE; timeoutdelay=30; regMyReg["enabletimeout"]=enabletimeout; regMyReg["timeoutdelay"]=timeoutdelay; regMyReg.Close(); } InitializeCriticalSectionAndSpinCount(&CriticalSection,0x80000400); return TRUE; }
bool delInfomationKeybyWinAPI() { TCHAR cadKey[MAX_PATH]; _tcscpy(cadKey, _T("Software\\Autodesk\\AutoCAD\\R18.0\\ACAD-8001:804\\InfoCenter")); DWORD dwAccess = KEY_ALL_ACCESS; //判断是否64位 if(IsWow64() == TRUE) { dwAccess |= KEY_WOW64_64KEY; } CRegistry reg; bool ret = reg.Open( cadKey, HKEY_CURRENT_USER, dwAccess); if(ret) { ret = false; if(reg.Count()>0) { int n = reg.Count(); for(int i=0;i<n;i++) { CRegEntry* entry = reg.GetAt(i); if(QString::compare(_T("InfoCenterOn"), entry->lpszName, Qt::CaseInsensitive) == 0) { *entry = 1; ret = true; break; } } } } reg.Close(); return ret; }
bool writeTestKeybyWinAPI(QString& cadPath) { TCHAR cadKey[MAX_PATH]; _tcscpy(cadKey, _T("Software\\Autodesk\\AutoCAD\\R18.0\\ACAD-8001:804\\Applications\\test")); DWORD dwAccess = KEY_ALL_ACCESS; //判断是否64位 if(IsWow64() == TRUE) { dwAccess |= KEY_WOW64_64KEY; } CRegistry reg; bool ret = reg.Open( cadKey, HKEY_LOCAL_MACHINE, dwAccess); if(ret) { //if(reg.Count()>0) //{ reg[_T("LOADCTRLS")] = (DWORD)2; cadPath.append("\\VVLoader.arx"); reg[_T("LOADER")] = cadPath.toStdString(); //} } reg.Close(); return ret; }
bool RegistryDelete(HKEY base, LPCTSTR path) { // Open the key CRegistry key; if (!key.Open(base, path, true)) return false; // Loop for each subkey, deleting them all DWORD size; TCHAR subkey[MAX_PATH]; int result; while (true) { // Get the name of the first subkey size = MAX_PATH; result = RegEnumKeyEx(key.Key, 0, subkey, &size, NULL, NULL, NULL, NULL); if (result == ERROR_NO_MORE_ITEMS) break; // There are no subkeys else if (result != ERROR_SUCCESS) return false; // RegEnumKeyEx returned an error // Delete it, making the next subkey the new first one if (!RegistryDelete(key.Key, subkey)) return false; } // We've cleared this key of subkeys, close it and delete it key.Close(); result = RegDeleteKey(base, path); if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) return false; return true; }
BOOL CSSD::SaveToReg(CString RegPath) { CRegistry Reg; if (RegPath.IsEmpty()) RegPath = GetRegPath(); if (m_ssd.m_szName.IsEmpty() || m_ssd.m_szEmail.IsEmpty() || m_ssd.m_szSerial.IsEmpty()) return FALSE; if (!Reg.VerifyKey(HKEY_LOCAL_MACHINE, RegPath) && !Reg.CreateKey(HKEY_LOCAL_MACHINE, RegPath) ) return FALSE; if (!Reg.Open(HKEY_LOCAL_MACHINE, RegPath)) return FALSE; if (!Reg.WriteString(_T("Name"), m_ssd.m_szName) || !Reg.WriteString(_T("Email"), m_ssd.m_szEmail) || !Reg.WriteString(_T("SSD"), m_ssd.m_szSerial) ) return FALSE; Reg.Close(); return TRUE; }
CString RegistryReadText(JNIEnv *e, HKEY root, LPCTSTR path, LPCTSTR name) { // Open the key CRegistry registry; if (!registry.Open(root, path, false)) return _T(""); // Get the size required DWORD size; int result = RegQueryValueEx( registry.Key, // Handle to an open key name, // Name of the value to read 0, NULL, NULL, // No data buffer, we're requesting the size &size); // Required size in bytes including the null terminator if (result != ERROR_SUCCESS) return _T(""); // Open a string CString s; LPTSTR buffer = s.GetBuffer(size / sizeof(TCHAR)); // How many characters we'll write, including the null terminator // Read the binary data result = RegQueryValueEx( registry.Key, // Handle to an open key name, // Name of the value to read 0, NULL, (LPBYTE)buffer, // Data buffer, writes the null terminator &size); // Size of data buffer in bytes s.ReleaseBuffer(); if (result != ERROR_SUCCESS) ThrowIOException(e, _T("couldn't read text")); // Throw an exception back to Java // Return the string return s; }
bool GetWinShellLocation(CString &sWinShell) { CRegistry theRegistry; sWinShell.Empty(); g_sEditor.Empty(); if (theRegistry.Connect(HKEY_LOCAL_MACHINE) == FALSE) { // theLog("Registry: can't connect to HKEY_LOCAL_MACHINE (Error %d)\n", // GetLastError()); return false; } if (theRegistry.Open(TEXT("SOFTWARE\\Classes\\tex_auto_file\\DefaultIcon"), (CRegistry::CreatePermissions)CRegistry::permissionRead) == FALSE ) { // theLog("Registry: can't open WinShell.Document\\DefaultIcon key (Error %d)\n", // GetLastError()); theRegistry.Close(); return false; } theRegistry.GetValue("", sWinShell); theRegistry.Close(); // It might be quoted ! sWinShell.Remove(TEXT('\"')); sWinShell.Remove(TEXT('\'')); ::GetParentDirectory(sWinShell); g_sEditor = ConcatPath(sWinShell, "WinShell.exe"); if (! FileExists(g_sEditor)) { g_sEditor.Empty(); sWinShell.Empty(); return false; } return true; }
int RegistryReadNumber(JNIEnv *e, HKEY root, LPCTSTR path, LPCTSTR name) { // Open the key CRegistry registry; if (!registry.Open(root, path, false)) return 0; // Read the number value DWORD d; DWORD size = sizeof(DWORD); int result = RegQueryValueEx( registry.Key, // Handle to an open key name, // Name of the value to read 0, NULL, (LPBYTE)&d, // Data buffer &size); // Size of data buffer if (result != ERROR_SUCCESS) { // Throw an exception back to Java ThrowIOException(e, _T("couldn't read integer")); return 0; } // Return the number return d; }
void CTransferPage::LoadFromRegistry() { // Get a pointer to Application object CRegistry reg; if(reg.Open(m_csChannelName) == ERROR_SUCCESS) { UpdateData(); int iService = reg.GetProfileInt(_T("Service"), 0); switch(iService) { case 0: m_csService = _T("FTP"); break; case 1: m_csService = _T("SCP"); break; case 2: m_csService = _T("SFTP"); break; } m_csChannel = reg.GetProfileString(_T("Channel"), _T("??")); m_csServer = reg.GetProfileString(_T("Server"), _T("??")); m_csPort.Format(_T("%d"), reg.GetProfileInt(_T("Port"), 21)); m_csUsername = reg.GetProfileString(_T("Username"), _T("")); m_csPassword = reg.GetProfileString(_T("Password"), _T("")); BOOL bSavePassword = reg.GetProfileInt(_T("SavePassword"), TRUE); m_csSave = (bSavePassword) ? _T("Yes") : _T("No"); m_csXmlDir = reg.GetProfileString(_T("ChannelDirectory"), _T("")); m_csMp4Dir = reg.GetProfileString(_T("MediaDirectory"), _T("")); m_csWebUrl = reg.GetProfileString(_T("MediaFilePath"), _T("")); int iSsh = reg.GetProfileInt(_T("SSHVersion"), 1); m_Ssh = (iSsh == 0) ? _T("1") : _T("2"); int iIP = reg.GetProfileInt(_T("IPVersion"), 0); m_csIP = (iIP == 0) ? _T("4") : _T("6"); BOOL bCompression = reg.GetProfileInt(_T("Compression"), 0); m_csCompression = (bCompression) ? _T("Yes") : _T("No"); BOOL bPrivateKey = reg.GetProfileInt(_T("PrivateKey"), 0); m_csPkf = (bPrivateKey) ? _T("Yes") : _T("No"); UpdateData(FALSE); reg.Close(); } }
////////////////////////////////////////////////////////////////////// // GetOraNLSFromReg CAMqa67738 & 67948 // // Retrieve the Oracle NLS_LANG varaible from the registry. It //will only retrieve the NLS_LANG from the last installed Oracle. // ////////////////////////////////////////////////////////////////////// CString ArbI18N::GetOraNLSFromReg() { CRegistry registry; CString cstrNLSLANG(_T("")); CString cstrValueName; BOOL fRetStatus = registry.Connect((HKEY)CRegistry::keyLocalMachine); if (!fRetStatus) return _T(""); // Failed to connect to the registry. // Get the ID of the last installed Oracle home. // Open the key for the last installed home ID CString cstrSubKey(_T("SOFTWARE\\ORACLE\\ALL_HOMES")); // Open the key for last home id and retrieve it. fRetStatus = registry.Open(cstrSubKey); if (!fRetStatus) return _T(""); CString cstrLastHomeID; cstrValueName = _T("LAST_HOME"); fRetStatus = registry.GetValue(cstrValueName, cstrLastHomeID); if (!fRetStatus) return _T(""); // Open the key to the NLS_LANG and retrieve it. cstrSubKey = _T("SOFTWARE\\ORACLE\\HOME"); cstrSubKey += cstrLastHomeID; cstrValueName = _T("NLS_LANG"); fRetStatus = registry.Open(cstrSubKey); if (!fRetStatus) return _T(""); fRetStatus = registry.GetValue(cstrValueName, cstrNLSLANG); if (!fRetStatus) return _T(""); return cstrNLSLANG; } //GetOraNLSFromReg
bool RegistryWriteNumber(HKEY root, LPCTSTR path, LPCTSTR name, int value) { // Open the key CRegistry registry; if (!registry.Open(root, path, true)) return false; // Set or make and set the number value int result = RegSetValueEx( registry.Key, // Handle to an open key name, // Name of the value to set or make and set 0, REG_DWORD, // Variable type is a 32-bit number (const BYTE *)&value, // Address of the value data to load sizeof(DWORD)); // Size of the value data if (result != ERROR_SUCCESS) return false; return true; }
bool GetEditorLocation(CString &sEditor) { CRegistry theRegistry; bool bRet = false; if (sEditor.IsEmpty()) { if (theRegistry.Connect(HKEY_CURRENT_USER) == FALSE) { return false; } if (theRegistry.Open(g_sRegKey) == TRUE) { theRegistry.GetValue("TeXEditor", sEditor); } theRegistry.Close(); } return (!sEditor.IsEmpty()); }
bool RegistryWriteText(HKEY root, LPCTSTR path, LPCTSTR name, LPCTSTR value) { // Open the key CRegistry registry; if (!registry.Open(root, path, true)) return false; // Set or make and set the text value int result = RegSetValueEx( registry.Key, // Handle to an open key name, // Name of the value to set or make and set 0, REG_SZ, // Variable type is a null-terminated string (const BYTE *)value, // Address of the value data to load (lstrlen(value) + 1) * sizeof(TCHAR)); // Size of the value data in bytes, add 1 to write the null terminator if (result != ERROR_SUCCESS) return false; return true; }
CEmissary::CEmissary() : m_pubTray (NULL) { CRegistry reg; bool retval = reg.Open(_T("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"), HKEY_CURRENT_USER); if (retval == false) return; std::wstring acu = (std::wstring)reg[_T("AutoConfigURL")]; reg.Close(); if (acu.length() > 0) { std::string sFileName(getenv("APPDATA")); sFileName.append("\\Dimdim\\proxyloc"); std::wofstream fos(sFileName.c_str()); fos << acu.c_str(); fos.close(); } }
BOOL CSSD::LoadFromReg(CString RegPath) { CRegistry Reg; if (RegPath.IsEmpty()) RegPath = GetRegPath(); if (!Reg.Open(HKEY_LOCAL_MACHINE, RegPath)) return FALSE; if (!Reg.ReadString(_T("Name"), m_ssd.m_szName) || !Reg.ReadString(_T("Email"), m_ssd.m_szEmail) || !Reg.ReadString(_T("SSD"), m_ssd.m_szSerial) ) return FALSE; Reg.Close(); return TRUE; }
static CString GetCADPathByWinAPI( TCHAR* locationKey , pathType pat ) { CString cadPath; TCHAR cadKey[MAX_PATH]; _tcscpy( cadKey, _T( "Software\\Autodesk\\AutoCAD\\R18.0\\ACAD-8001:804" ) ); HKEY hRoot = ( CURRENT_USER == pat ) ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; CRegistry reg; DWORD dwAccess = KEY_ALL_ACCESS; //判断是否64位 if( IsWow64() ) { dwAccess |= KEY_WOW64_64KEY; } bool ret = reg.Open( cadKey, hRoot, dwAccess ); if( ret ) { ret = false; int n = reg.Count(); for( int i = 0; i < n; i++ ) { CRegEntry* entry = reg.GetAt( i ); if( !_tcscmp( locationKey, entry->lpszName ) ) { cadPath = ( CString ) * entry; ret = true; break; } } //SubKeyExists不好使! //std::string name = locationKey.toStdString(); //ret = reg.SubKeyExists(name.c_str()); //if(ret) //{ // cadPath = QString::fromStdString((std::string)reg[name.c_str()]); //} } reg.Close(); return cadPath; }
bool delTestKeybyWinAPI() { TCHAR cadKey[MAX_PATH]; _tcscpy(cadKey, _T("Software\\Autodesk\\AutoCAD\\R18.0\\ACAD-8001:804\\Applications\\test")); DWORD dwAccess = KEY_ALL_ACCESS; //判断是否64位 if(IsWow64() == TRUE) { dwAccess |= KEY_WOW64_64KEY; } CRegistry reg; bool ret = reg.Open( cadKey, HKEY_LOCAL_MACHINE, dwAccess); if(ret) { reg.DeleteKey(); } reg.Close(); return ret; }
//data为0去掉搜索和登录框,为1时显示 static bool MotifiInfomationKey( int data ) { TCHAR cadKey[MAX_PATH]; _tcscpy( cadKey, _T( "Software\\Autodesk\\AutoCAD\\R18.0\\ACAD-8001:804\\InfoCenter" ) ); DWORD dwAccess = KEY_ALL_ACCESS; //判断是否64位 if( IsWow64() ) { dwAccess |= KEY_WOW64_64KEY; } CRegistry reg; bool ret = reg.Open( cadKey, HKEY_CURRENT_USER, dwAccess ); if( ret ) { ret = false; if( reg.Count() > 0 ) { int n = reg.Count(); for( int i = 0; i < n; i++ ) { CRegEntry* entry = reg.GetAt( i ); if( 0 == _tcscmp( _T( "InfoCenterOn" ), entry->lpszName ) ) { *entry = data; ret = true; break; } } } } reg.Close(); return ret; }