473,385 Members | 1,218 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Accessing registry values from a windows service

Stu
Hi,

I am storing various settings for a windows service in the registry - but
for some reason the windows service will not read them.

Namespaces:
Imports System.ServiceProcess
Imports System.IO
Imports System.Diagnostics

The class inherits:
Inherits System.ServiceProcess.ServiceBase

My code is:
GetSetting("MyProject", "Settings", "LogfilePath")

The function I am using works fine from within a window forms app.
Anyine any ideas?

Thanks in advance,

Stu
Nov 21 '05 #1
2 1224
I use the following in my services:
Imports Microsoft.Win32
------
Dim regKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\myprodu ct\options", False)

If regKey Is Nothing Then
'not setup yet
Else
'retrieve value as follows - regKey.GetValue("UserName")
End If

User submitted from AEWNET (http://www.aewnet.com/)
Nov 21 '05 #2
But you will also need to define registry permissions for read/writing the
registry to be on the safe side

The other user's example is what I would do too, except that I would use the
following method:

Imports Microsoft.Win32
------
Dim regKey As RegistryKey =
Registry.LocalMachine.OpenSubKey("SOFTWARE\myprodu ct\options", False)

If Not (regKey Is Nothing) Then

Dim strSetting As String = CType(regKey.GetValue("UserName"), String)

End If

regKey.Close ' <--- Don't forget to close the registry key

Then you can use 'strSetting', which will make your life easier

----------------------------------------------------------------------

Don't forget to use the Try Catch End Try block

You get the idea I thingk.
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: caldera | last post by:
Hi, I write a windows service. In that service I create a new subkey for registry. But service install is call CreateSubKey() the program throw an exception to the event log said that Cannot write...
1
by: Yoshitha | last post by:
Hi I am developing web application through which i've to write and read the values from the registry. When i set impersonate property to "false" it is displaying exception " Requested Registry...
2
by: Mostafa Salama | last post by:
i have a problem in accessing registry from web service i made a web service that call a function to access registry The web service contain the following code Dim RegKey As...
3
by: mark.jerrom | last post by:
I'm fairly new to this Web Service game so please feel free to suggest something different if it looks like i'm completely off track! I'm trying to write an application that runs on a Pocket PC...
3
by: Ahmad Jalil Qarshi | last post by:
Hi! I am developing an application in C# as a windows NT Service. This application needs to check for eventlog using EventLog.Exists("System") But unfortunately it generates exception...
11
by: vovan | last post by:
I'm using this approach to read from registry. Dim f As New RegistryPermission(RegistryPermissionAccess.AllAccess, _ "HKEY_LOCAL_MACHINE\SOFTWARE\SRS Enterprises\Coordinator\Settings") 'Vlad...
6
by: vovan | last post by:
I'm asking for help one more time. Below are 2 procedures. The first one is used in VB 2005 Windows Form project. It works fine on XP, Vista. Private Sub RegistryReadingTest() Try Dim f As New...
0
by: dipalichavan82 | last post by:
i created windows service with timer in which i m deleting files of specific extensions on client m/c n putting on server .i m taking values for 1.list of file extensions dat should be considerd...
3
by: thephatp | last post by:
BLUF: I need to build up the actual %TEMP% path for all users methodically using values in the registry, and I need to do this both by the current user AND as a service will do this running as...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.