[St-m-svn] SF.net SVN: st-m:[1367] branches/core_v3/Startup/Winini/Section.cpp
Brought to you by:
cnx_glenn
From: <cnx...@us...> - 2008-08-21 13:24:31
|
Revision: 1367 http://st-m.svn.sourceforge.net/st-m/?rev=1367&view=rev Author: cnx_glenn Date: 2008-08-21 13:24:27 +0000 (Thu, 21 Aug 2008) Log Message: ----------- Win.ini section: Implemented disable Modified Paths: -------------- branches/core_v3/Startup/Winini/Section.cpp Modified: branches/core_v3/Startup/Winini/Section.cpp =================================================================== --- branches/core_v3/Startup/Winini/Section.cpp 2008-08-21 13:08:54 UTC (rev 1366) +++ branches/core_v3/Startup/Winini/Section.cpp 2008-08-21 13:24:27 UTC (rev 1367) @@ -313,6 +313,45 @@ try { + if (item->getAttributes() & Item::Attribute::corrupt) + throw Exception(_T("Item is corrupted")); + + //try to disable item + CRegKey hKey; + hKey.open(HKLM, mDisabledkey.c_str(), KEY_ALL_ACCESS | (isWindows64() ? KEY_WOW64_64KEY : 0)); + if (hKey.isOpen()) + { + DWORD dwDisposition = 0; + CRegKey hKeyNew; + hKeyNew.create(hKey, item->getName().c_str(), REG_NONE, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS | (isWindows64() ? KEY_WOW64_64KEY : 0)); + if (hKeyNew.isOpen()) + { + if (dwDisposition == REG_OPENED_EXISTING_KEY) + throw Exception(_T("An item with this name already exists")); + + try + { + if (hKeyNew.setValue(item->getPath().c_str(), _T("command")) != ERROR_SUCCESS) + throw Exception(_T("Unable to disable item (Unable to set command value)")); + if (hKeyNew.setValue(mPart.c_str(), _T("part")) != ERROR_SUCCESS) + throw Exception(_T("Unable to disable item (Unable to set hkey value)")); + } + + catch (...) + { + hKeyNew.close(); + hKey.deleteSubKey(item->getName().c_str()); + throw; + } + } + else + throw Exception(_T("Unable to disable item (couldn't create disabled item key)")); + } + else + throw Exception(_T("Unable to disable item (access to registry denied)")); + + //we successfully disabled our item, we can now safely delete the enabled one + remove(item); } catch (Exception const&) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |