Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where can I store values for a WinService?

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
0
0
US
I am developing a Windows Service that monitors a directory, but I would like a few parameters stored, such as the folder to monitor, a destination folder, and some other options. I don't want to have a database for it, I think that is overkill, and these are set once parameters. Should I do an .ini file or set things in the registry? I have done neither so any help or links are appreciated. Thank you.
 
Stay away from using the registry if you can. You should use an xml file so can say that you use xml in your application. Managers and clients seem to love to hear the word xml even if it is being used for something as trivial as storing a few config settings.
 
kcj402003, Any advice on using an ini file? I have never done it. I have used XML, but don't know if I need that here.
 
Here's an example. Let me know if you have any questions. KJ

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim strDir As String
Dim strFile As String

strDir = "C:\Temp"
strFile = "C:\Temp\Config.ini"

Dim di As DirectoryInfo = New DirectoryInfo(strDir)
Dim fin As FileInfo = New FileInfo(strFile)
Dim fs As FileStream
Dim sw As StreamWriter
Dim sr As StreamReader
Dim str1 As String
Dim str2 As String

'Create folder if it does not exist
If di.Exists = False Then
di.Create()
End If

'Create file if it does not exist
If fin.Exists = False Then
fs = New FileStream(strFile, FileMode.Create, FileAccess.Write)
sw = New StreamWriter(fs)
sw.WriteLine("1")
sw.WriteLine("2")
sw.Flush()
fs.Flush()
sw.Close()
fs.Close()
End If


fs = New FileStream(strFile, FileMode.Open, FileAccess.Read)
sr = New StreamReader(fs)
str1 = sr.ReadLine
str2 = sr.ReadLine
fs.Flush()
fs.Close()
sr.Close()

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top