Article View: borland.public.cppbuilder.nativeapi
Article #3716Registry Problems
From: Chris
Date: Sat, 29 Apr 2006 09:05
Date: Sat, 29 Apr 2006 09:05
123 lines
5374 bytes
5374 bytes
Hi
On one of my customers PCs (Win XP) I have the following problem (which I
cannot reproduce).
The user starts the PC and says he does not have to log on so I guess they
don't have different users etc.
My app is started via a desktop link. It has no problems reading and
writing to the registry (it stores all registry info in the one place under
HKCU\Software\Jewesloft\Onyx). When the user wants to restore the database
(it's an invoicing system) my app starts another app that takes care of
stoping the server, replacing the files etc and then closes.
It starts this app using ShellExecute and this new app has no problems
reading and writing to the registry. Once the database has been restored
this second app now restarts the first app (again using ShellExecute) but
now the primary app doesn't see the data in the registry that it could a
moment or two before (i.e. the 'Please register now' screen is displayed
etc). The user can re-register and the setting is saved so I guess that the
app can still read and write to the registry. It's as if my registry keys
are deleted.
This second app reads from various keys that the first app sets (all in the
HKCU/software/jewelsoft/onyx location) and has code to flag errors so I am
sure that the second app can also see the current registry settings, the
last thing it does is set a key and delete another one from the HKLM area
(as shown below) and I believe this is what triggers the problem.
//set autorun last as this is the only thing that could fail if we don't
//have the correct admin privileges
if (ckAutostart->Checked)
{DeleteRegVal("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run","GenInv
Nexus Server",(int)HKEY_LOCAL_MACHINE); //This key may not exist
SetRegVal("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run","Nexus
Server",ServerWorkingDir + "nxServer.exe",true,(int)HKEY_LOCAL_MACHINE);
}
else
{DeleteRegVal("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run","GenInv
Nexus Server",(int)HKEY_LOCAL_MACHINE); //This key may not exist
DeleteRegVal("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run","Nexus
Server",(int)HKEY_LOCAL_MACHINE);
}
These are the functions
//---------------------------------------------------------------------------
String __fastcall TfrmServerAdmin::MyGetRegVal(String KeyToOpen, String
KeyToRead, String & Default, int RootKey)
{
String RetVal;
TRegistry *thisreg = new TRegistry;
thisreg->RootKey = (void*)RootKey; // Registry Section
thisreg->OpenKey(KeyToOpen,false);
RetVal = thisreg->ReadString(KeyToRead);
delete thisreg;
if (RetVal != "")
return RetVal;
else
return Default;
}
//-----------------------------------------------------------
bool __fastcall TfrmServerAdmin::SetRegVal(String KeyToOpen, String
KeyToWrite, String & StrToWrite, bool CreateKey,int RootKey)
{
bool RetVal = false;
TRegistry *thisreg = new TRegistry;
thisreg->RootKey = (void*)RootKey; // Registry Section
try
{
if (thisreg->OpenKey(KeyToOpen,CreateKey))
{thisreg->WriteString(KeyToWrite,StrToWrite);
RetVal = true;
}
else
RetVal = false;
}
__finally
{
delete thisreg;
return RetVal;
}
}
//-----------------------------------------------------
bool __fastcall TfrmServerAdmin::DeleteRegVal(String KeyToOpen, String
KeyToDelete, int RootKey)
{
bool RetVal = false;
TRegistry *thisreg = new TRegistry;
thisreg->RootKey = (void*)RootKey; // Registry Section
try
{
if (thisreg->OpenKey(KeyToOpen,false))
{thisreg->DeleteValue(KeyToDelete);
RetVal = true;
}
else
RetVal = false;
}
__finally
{
delete thisreg;
return RetVal;
}
}
//-----------------------------------------------------
I also know that this user is logged on as an administrator as he is able to
run my setup program (inno) which is set to check for admin users.
Does anyone have any idea why the app seems to lose the data stored in the
registry?
Could Windows be doing something in the background? Could it be
anti-spyware/anti-virus software? I don't think any other software is
affected (only mine) but the second app definately does not set any registry
keys other than that mentioned above.
Best regards
Chris
Technical Details
Message-ID:
<44532c52$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,b99e639ffcfc4f13,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Chris" <nospam@nospam.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Registry Problems Date: Sat, 29 Apr 2006 10:05:25 +0100 Lines: 125 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 NNTP-Posting-Host: 83.100.236.203 Message-ID: <44532c52$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1146301522 83.100.236.203 (29 Apr 2006 02:05:22 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail