Bonsoir,

J'ai créé un service Windows. Je tiens à ce que celui-ci puisse lire / écrire dans un fichier.

Lorsque je debugg le code dans une application avec une interface graphique, les méthodes et fonctions fonctionnent parfaitement. Mais mises dans mon service, elles ne fonctionnent plus.

En réalité, le fichier ne semble pas du tout être ni lut, ni écrit.

Voici quelques fragments de code pour comprendre:

Mon installer:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
         installer = New ServiceInstaller
        processInstaller = New ServiceProcessInstaller
 
        With installer
            .DisplayName = "CreaProtect"
            .Description = "Gestion du temps d'utilisation de l'ordinateur par session"
            .ServiceName = "CreaProtect"
            .StartType = ServiceStartMode.Automatic
 
        End With
 
        With processInstaller
            .Account = ServiceAccount.LocalSystem
        End With
 
        Me.Installers.Add(installer)
        Me.Installers.Add(processInstaller)
Mon service
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
Registre.Charger("C:\CreaProtectData.xml")
 
...
 
If Not Registre.IsCurrentAdmin Then
            Windows.Forms.MessageBox.Show("Attention, le fichier de configuration a été modifié", "Attention", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Stop, Windows.Forms.MessageBoxDefaultButton.Button1, Windows.Forms.MessageBoxOptions.DefaultDesktopOnly)
        End If
Le code du fichier de registre (faisant partie d'une DLL):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
If Not File.Exists("C:\CreaProtectData.xml") Then Exit Function
 
            Dim contenu As String = File.ReadAllText("C:\CreaProtectData.xml")
            Dim decoder As XmlSerializer = New XmlSerializer(GetType(Utilisateurs))
 
            Utilisateurs = decoder.Deserialize(New StringReader(contenu))
 
            Dim md5 As Byte() = Security.Cryptography.MD5CryptoServiceProvider.Create.ComputeHash(Encoding.ASCII.GetBytes(contenu.ToCharArray))
 
            Dim key As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\CreaProtect\Config")
 
            Dim b As Byte
            Dim r As Boolean = True
 
            For b = 0 To md5.Length - 1
                If Not md5(b) = key.GetValue("MD5")(b) Then r = False
            Next
 
            Return r
Je n'ai à aucun moment un code erreur, les journaux sont clean... Bref, je ne comprend pas ...

Quelqu'un aurait-il une idée ?