IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Comment executer un programme à partir d'un service windows


Sujet :

VB.NET

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Août 2005
    Messages
    53
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 53
    Par défaut Comment executer un programme à partir d'un service windows
    Bonjour,
    Je suis en train de développer un service windows qui doit scruter un dossier et verifier si un fichier existe, s'il existe je doit le décompresser.
    Est ce que quelqu'un saurait faire ça?
    Ce post est en fait la suite d'un poste que j'ai délaissé car je me demmande si je ne faisais pas fausse route.
    Après avoir essayé une multitude de solutions à base de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Dim proc As New System.Diagnostics.Process()
    ...
    proc.Start()
    ou
    je devient
    ça fait 2 jour que je cherche des solutions sur des forums et les seuls posts que j'ai trouvé à ce sujet n'avait pas de réponse


    Est ce tout simplement possible?

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Août 2005
    Messages
    53
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 53
    Par défaut
    Je viens de trouver la réponse dans la doc microsoft, c'est tout simplement impossible en VB

  3. #3
    Membre éprouvé
    Inscrit en
    Avril 2007
    Messages
    124
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 124
    Par défaut
    Si c'est juste pour Zipper ou dezipper tu peux utiliser Vb pour le faire.
    Exemple d'une classe (fournis par Microsoft)
    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
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
     
      Public Class ZipUtil
            Public Function CompressFile(ByVal sourceFile As String, ByVal destinationFile As String) As String
     
                ' make sure the source file is there
                If File.Exists(sourceFile) = False Then
                    Throw New FileNotFoundException
                End If
     
                ' Create the streams and byte arrays needed
                Dim buffer As Byte() = Nothing
                Dim sourceStream As FileStream = Nothing
                Dim destinationStream As FileStream = Nothing
                Dim compressedStream As GZipStream = Nothing
                Dim ReturnValue As String = Nothing
                Try
                    ' Read the bytes from the source file into a byte array
                    sourceStream = New FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read)
     
                    ' Read the source stream values into the buffer
                    buffer = New Byte(sourceStream.Length) {}
                    Dim checkCounter As Integer = sourceStream.Read(buffer, 0, buffer.Length)
     
                    ' Open the FileStream to write to
                    destinationStream = New FileStream(destinationFile, FileMode.OpenOrCreate, FileAccess.Write)
     
                    ' Create a compression stream pointing to the destiantion stream
                    compressedStream = New GZipStream(destinationStream, CompressionMode.Compress, True)
     
                    'Now write the compressed data to the destination file
                    compressedStream.Write(buffer, 0, buffer.Length)
                    ReturnValue = "Success"
                Catch ex As ApplicationException
                    ReturnValue = ex.Message
                Finally
                    ' Make sure we allways close all streams
                    If Not (sourceStream Is Nothing) Then
                        sourceStream.Close()
                    End If
                    If Not (compressedStream Is Nothing) Then
                        compressedStream.Close()
                    End If
                    If Not (destinationStream Is Nothing) Then
                        destinationStream.Close()
                    End If
                End Try
                Return ReturnValue
            End Function
     
            Public Function DecompressFile(ByVal sourceFile As String, ByVal destinationFile As String) As String
                Dim ReturnValue As String = Nothing
                ' make sure the source file is there
                If File.Exists(sourceFile) = False Then
                    Throw New FileNotFoundException
                End If
     
                ' Create the streams and byte arrays needed
                Dim sourceStream As FileStream = Nothing
                Dim destinationStream As FileStream = Nothing
                Dim decompressedStream As GZipStream = Nothing
                Dim quartetBuffer As Byte() = Nothing
     
                Try
                    ' Read in the compressed source stream
                    sourceStream = New FileStream(sourceFile, FileMode.Open)
     
                    ' Create a compression stream pointing to the destiantion stream
                    decompressedStream = New GZipStream(sourceStream, CompressionMode.Decompress, True)
     
                    ' Read the footer to determine the length of the destiantion file
                    quartetBuffer = New Byte(4) {}
                    Dim position As Integer = CType(sourceStream.Length, Integer) - 4
                    sourceStream.Position = position
                    sourceStream.Read(quartetBuffer, 0, 4)
                    sourceStream.Position = 0
                    Dim checkLength As Integer = BitConverter.ToInt32(quartetBuffer, 0)
     
                    Dim buffer(checkLength + 100) As Byte
                    Dim offset As Integer = 0
                    Dim total As Integer = 0
     
                    ' Read the compressed data into the buffer
                    While True
                        Dim bytesRead As Integer = decompressedStream.Read(buffer, offset, 100)
                        If bytesRead = 0 Then
                            Exit While
                        End If
                        offset += bytesRead
                        total += bytesRead
                    End While
     
                    ' Now write everything to the destination file
                    destinationStream = New FileStream(destinationFile, FileMode.Create)
                    destinationStream.Write(buffer, 0, total)
     
                    ' and flush everyhting to clean out the buffer
                    destinationStream.Flush()
                    ReturnValue = "Success"
                Catch ex As ApplicationException
                    ReturnValue = ex.Message
                Finally
                    ' Make sure we allways close all streams
                    If Not (sourceStream Is Nothing) Then
                        sourceStream.Close()
                    End If
                    If Not (decompressedStream Is Nothing) Then
                        decompressedStream.Close()
                    End If
                    If Not (destinationStream Is Nothing) Then
                        destinationStream.Close()
                    End If
                End Try
                Return ReturnValue
            End Function
     
            Protected Overrides Sub Finalize()
                MyBase.Finalize()
            End Sub
        End Class

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Août 2005
    Messages
    53
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 53
    Par défaut
    merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [C#] Comment executer un programme externe ?
    Par Worldofdada dans le forum C#
    Réponses: 7
    Dernier message: 11/02/2009, 14h36
  2. Exécuter un programme à partir d'un service windows
    Par TekP@f dans le forum Windows Forms
    Réponses: 5
    Dernier message: 28/01/2009, 11h09
  3. Réponses: 1
    Dernier message: 10/12/2006, 13h38
  4. Comment executer un programme avec un bouton
    Par STEPH69000 dans le forum VB 6 et antérieur
    Réponses: 7
    Dernier message: 09/08/2006, 19h48
  5. Réponses: 12
    Dernier message: 06/06/2006, 18h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo