Registry Programming in Windows Service

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

in my service i added my Registry Programming code,am facing with a problem
which am not able to rectify it..the problem is , in the service, the program
gets hanged and doesnt move after Registry is accessed..that is before
registry code,everything works and once u access regitry it doesnt!......even
Messagebox isnot working!..

the code is as follows,

/**************************Code starts here*******************/
RegistryKey
pRegKey=Registry.LocalMachine.OpenSubKey("Software\\Software\\MyKey");
pRegKey->SetValue("VAL","1");
pRegKey.Close();

pRegKey=Registry.LocalMachine.OpenSubKey("Software\\Software\\MyKey");
object result=pRegKey->GetValue("VAL");
MessageBox.Show(result.ToString());
pRegKey.Close();
/**************************Code starts here*******************/

i would be happy if someone could help me out..

thanks in advance...

with regards,
C.C.Chakkaradeep
 
Chakkaradeep,

What is the account that the service is running under? Is it possible
that the account doesn't have rights to the registry? If you set the
service up to run under an admin account, does it work?
 
A MessageBox typically won't show from a Service - it's running with a
different account and probably wasn't installed to Interact with Desktop.
Your Service thread might just be crashing too if those keys/data items are
missing - I think the process still stays running so it looks like a hang.
 
Your service runs in a secured non interactive non visible
desktop/winstation. Whenever you execute MessageBox.Show the MessageBox is
not visible and no-one can press the OK button and your service appears to
hang.
Remove the MessageBox.Show and try again.

Willy.
 
Hi all,

i haev enabled Interaction with Desktop option in the Program Code
itself......Registry code is working in other functions but only in this code
which is in another function is not working.........so am confused...becoz if
it working in one part o my code,it should work at another part also provided
all my syntax and usage are correct.....as said in MSDN i have closed the
RegistryKey so that my work is accomplished..then also in this particular
code part whihc i have written above does not work!!!..

thanks in advance..

with regards,
C.C.Chakkaradeep
 
Chakkaradeep said:
Hi all,

i haev enabled Interaction with Desktop option in the Program Code
itself......Registry code is working in other functions but only in this
code
which is in another function is not working.........so am confused...becoz
if
it working in one part o my code,it should work at another part also
provided
all my syntax and usage are correct.....as said in MSDN i have closed the
RegistryKey so that my work is accomplished..then also in this particular
code part whihc i have written above does not work!!!..

What exactly is not working, any error code exceptions? ( you don't seem to
need try/catch blocks)
Is the registry path correct?

Time to attach a debugger and step through your code I'm affraid, if you
can't supply us more info.

Willy.
 
Back
Top