Problème capture écran

pyroha - 21 déc. 2015 à 12:15
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 - 22 déc. 2015 à 18:50
Bonjour,

Je rencontre un problème, dans mon projet je souhaite pouvoir faire une capture d'écran d'un ordinateur de mon réseau.
Pour cela j'ai un programme dans l’ordinateur distant qui vérifie en permanence si un fichier est créer dans un dossier spécifié.
Si un fichier est crée, il prend une capture d'écran et l'enregistre dans un dossier
Grâce à un programme sur mon poste je charge l'image et l'affiche, seulement si je veut en prendre d'autres, une erreur se produit.

Programme sur mon poste :

Try

Dim PATHDOSSIER As String = "\\PROPRIETAIRE-PC\Users\Proprietaire\Messagerie interne\Florence sécurité\Capture ecran\depart"
For Each files As String In System.IO.Directory.GetFiles(PATHDOSSIER)
System.IO.File.Delete(files)
Next


Dim img As String = "\\PROPRIETAIRE-PC\Users\Proprietaire\Messagerie interne\Florence sécurité\Capture ecran\images"
For Each files1 As String In System.IO.Directory.GetFiles(img)
System.IO.File.Delete(files1)

Next
Catch ex As Exception
MsgBox("Une erreur c'est produite !", MsgBoxStyle.Exclamation, "Erreur")
End Try



Try
If ListView1.FocusedItem.Index = 0 Then

System.IO.File.Create("\\PROPRIETAIRE-PC\Users\Proprietaire\Messagerie interne\Pierre sécurité\Capture ecran\depart\capture.txt")



Dim msg As String
Dim titre As String
Dim style As MsgBoxStyle
Dim reponse As MsgBoxResult
msg = "Une photo a été prise de l'écran de Pierre " & vbCrLf & "Voulez - vous l'ouvrir ? "
style = MsgBoxStyle.Information Or MsgBoxStyle.OkOnly Or MsgBoxStyle.MsgBoxSetForeground Or MsgBoxStyle.SystemModal Or MsgBoxStyle.YesNo
titre = "Confirmation"
reponse = MsgBox(msg, style, titre)
If reponse = vbNo Then


ElseIf reponse = vbYes Then

Capture_ecran_affichage.Show()
Me.Hide()
Capture_ecran_affichage.PictureBox1.Image = Image.FromFile("\\PROPRIETAIRE-PC\Users\Proprietaire\Messagerie interne\Pierre sécurité\Capture ecran\images\capture.png")
End If
End If







If ListView1.FocusedItem.Index = 1 Then



System.IO.File.Create("\\PROPRIETAIRE-PC\Users\Proprietaire\Messagerie interne\Manon sécurité\Capture ecran\depart\capture.txt")





Dim msg As String
Dim titre As String
Dim style As MsgBoxStyle
Dim reponse As MsgBoxResult
msg = "Une photo a été prise de l'écran de Manon " & vbCrLf & "Voulez - vous l'ouvrir ? "
style = MsgBoxStyle.Information Or MsgBoxStyle.OkOnly Or MsgBoxStyle.MsgBoxSetForeground Or MsgBoxStyle.SystemModal Or MsgBoxStyle.YesNo
titre = "Confirmation"
reponse = MsgBox(msg, style, titre)
If reponse = vbNo Then


ElseIf reponse = vbYes Then

Capture_ecran_affichage.Show()

Capture_ecran_affichage.PictureBox1.Image = Image.FromFile("\\PROPRIETAIRE-PC\Users\Proprietaire\Messagerie interne\Manon sécurité\Capture ecran\images\capture.png")
End If
End If





If ListView1.FocusedItem.Index = 2 Then

System.IO.File.Create("\\PROPRIETAIRE-PC\Users\Proprietaire\Messagerie interne\Florence sécurité\Capture ecran\depart\capture.txt")



Dim msg As String
Dim titre As String
Dim style As MsgBoxStyle
Dim reponse As MsgBoxResult
msg = "Une photo a été prise de l'écran de Florence" & vbCrLf & "Voulez - vous l'ouvrir ? "
style = MsgBoxStyle.Information Or MsgBoxStyle.OkOnly Or MsgBoxStyle.MsgBoxSetForeground Or MsgBoxStyle.SystemModal Or MsgBoxStyle.YesNo
titre = "Confirmation"
reponse = MsgBox(msg, style, titre)
If reponse = vbNo Then


ElseIf reponse = vbYes Then

Capture_ecran_affichage.Show()

Capture_ecran_affichage.PictureBox1.Image = Image.FromFile("\\PROPRIETAIRE-PC\Users\Proprietaire\Messagerie interne\Florence sécurité\Capture ecran\images\capture.png")
End If
End If

Catch ex As Exception

End Try


Programme pc distant

Option Strict On
Public Class Form1
Dim FSW As New IO.FileSystemWatcher






Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FSW.Path = "\\PROPRIETAIRE-PC\Users\Proprietaire\Messagerie interne\Florence sécurité\Capture ecran\depart"
AddHandler FSW.Created, AddressOf FichierCree

FSW.EnableRaisingEvents = True





End Sub
Private Sub FichierCree(ByVal sender As Object, ByVal e As IO.FileSystemEventArgs)
Try
Dim largeur As Integer = Screen.PrimaryScreen.Bounds.Width
Dim hauteur As Integer = Screen.PrimaryScreen.Bounds.Height

Dim capture_ecran As New Bitmap(largeur, hauteur)
Dim graph As Graphics = Graphics.FromImage(capture_ecran)

graph.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)
PictureBox1.Image = capture_ecran

capture_ecran.Save("\\PROPRIETAIRE-PC\Users\Proprietaire\Messagerie interne\Florence sécurité\Capture ecran\images\capture.png")

Catch ex As Exception

End Try




End Sub


Merci par avance de votre aide

2 réponses

Zermelo Messages postés 378 Date d'inscription samedi 22 septembre 2012 Statut Membre Dernière intervention 13 août 2017 14
22 déc. 2015 à 08:10
Bonjour pyroha.
Pour avoir un Vb net propre (qui ne bave pas sur Vb 6), ouvrir My project, puis
– dans l'onglet Compiler,
––– mettre Option Explicit sur ON,
––– mettre Option Strict sur ON,
––– mettre Option Infer sur Off,
– dans l'onglet Références, désactiver Microsoft.
Cordialement.
0
Merci de votre réponse mais lorsque j'ai effectués les manipulations, 102 erreurs me sont signalés.
Cordialement
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
22 déc. 2015 à 12:58
Bonjour,
Et elles te le seront( (signalées) tant que tu t'obstineras à écrire du VB6 dans du VB.Net. Option Strict on t'oblige à écrire du VB.Net "pur" (ce que t'a signalé Zermelo, que je salue). Option Explicit t'oblige à déclarer et typer toutes tes variables. Si tu veux vraiment travailler proprement avec VB.Net, c'est le prix à payer.
Sinon, autant rester sous VB6 !
0
pyroha > ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018
22 déc. 2015 à 13:04
D'accord mais je me sens pas de tout refaire, j'ai passé trop de temps a écrire comme ça.
Cela est il gênant de continuer comme je le fais ?
0
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169 > pyroha
22 déc. 2015 à 14:06
Salut pyroha
La gêne n'est que pour toi
Mais si dans un "texte en français" tu y mettais de " l'anglais" est-ce que cela serait gênant pour toi ?
à traduire par : Mais si dans un "code en VB NET" tu y mettais du " VB6"

Comme dit ucfoutu ( que je salue ) autant rester sous VB 6 sinon
0
Zermelo Messages postés 378 Date d'inscription samedi 22 septembre 2012 Statut Membre Dernière intervention 13 août 2017 14
22 déc. 2015 à 15:21
Salut pyroha.
Tout le monde peut se tromper. Parmi ceux-là, ce sont les meilleurs qui se précipitent pour corriger leurs erreurs, et qui de ce fait apprennent le plus vite.
Cordialement.
Mes salutations à Ucfoutu et à vb95.
0
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169
22 déc. 2015 à 18:50
salut à toi aussi µZermelo
0
vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024 169 > vb95 Messages postés 3472 Date d'inscription samedi 11 janvier 2014 Statut Contributeur Dernière intervention 13 avril 2024
22 déc. 2015 à 18:50
faute de frappe : désolé
0
Rejoignez-nous