Tout d'abord, situons le contexte : je cherche à désactiver (et réactiver) la webcam sur mon PC. Mes nièces m'énervent à lancer skype et la webcam
Mais ça, c'est déjà fait. ^^
Le souci n'est pas un problème, mais une gêne...
En effet : obligation de redémarrer le PC pour que cette modification soit prise en compte...
Existe-t-il un moyen d'actualiser le PC sans avoir besoin de redémarrer le tout ?
PS : voici le code :
#include <Process.au3>
#include <Webcam.au3>
#include <File.au3>
Global $Form1 = GUICreate("Form1", 640, 525, 320, 10, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$wkdir = @TempDir & "\MaCamera"
DirRemove($wkdir, 1)
DirCreate($wkdir)
$webcam_io = $wkdir & "\WebCam_IO.exe"
FileInstall("WebCam_IO.exe", $webcam_io)
$devcon_x86 = $wkdir & "\devcon_x86.exe"
$devcon_x64 = $wkdir & "\devcon_x64.exe"
$devcon_ia64 = $wkdir & "\devcon_ia64.exe"
FileInstall("devcon_x86.exe", $devcon_x86)
FileInstall("devcon_x64.exe", $devcon_x64)
FileInstall("devcon_ia64.exe", $devcon_ia64)
Global $camera = _WebcamOpen($Form1, 0, 0, 640, 480)
$SnapBtn = GUICtrlCreateButton("Capture Image", 10, 490, 110, 25)
$VidBtn = GUICtrlCreateButton("Capture Vidéo", 130, 490, 110, 25)
$OffCam = GUICtrlCreateButton("Désactiver Caméra", 290, 490, 110, 25)
$OnCam = GUICtrlCreateButton("Activer Caméra", 410, 490, 110, 25)
$Red = GUICtrlCreateButton("-", 560, 490, 30, 25)
$Quit = GUICtrlCreateButton("X", 600, 490, 30, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_WebcamClose($camera)
Exit
Case $SnapBtn
; je préfère ne pas mettre ce bout de code, pour éviter que certains s'en servent pour espionner...
Case $OffCam
ProcessClose("devcon.exe")
ProcessClose("devcon_x86.exe")
ProcessClose("devcon_x64.exe")
ProcessClose("devcon_ia64.exe")
If @OSArch = "X86" Then $devcon = $devcon_x86
If @OSArch = "X64" Then $devcon = $devcon_x64
If @OSArch = "IA64" Then $devcon = $devcon_ia64
$Bat = $wkdir & "\batch.bat"
$ListePeriph = @HomeDrive & "\ListePeriph.txt"
FileDelete($Bat)
FileDelete($ListePeriph)
$tmpBAT = FileOpen($Bat, 2)
$command = $devcon & ' find * > ' & $ListePeriph
FileWriteLine($tmpBAT, $command)
FileClose($tmpBAT)
RunWait($Bat, "", @SW_HIDE)
For $a = _FileCountLines($ListePeriph) To 1 Step -1
If Not StringInStr(FileReadLine($ListePeriph, $a), "webcam") Then _FileWriteToLine($ListePeriph, $a, "", 1)
Next
$webcam_ligne = StringSplit(StringStripWS(FileReadLine($ListePeriph, 1), 8), ":")[1]
$webcam_id = "*" & StringReplace(StringSplit($webcam_ligne, "\")[1] & "\" & StringSplit($webcam_ligne, "\")[2], "&", "*") & "*"
$command = $devcon & ' disable ' & $webcam_id
RunWait(@ComSpec & " /c " & $command, "", @SW_HIDE)
MsgBox(0, "", "La désactivation de la Webcam sera effective au prochain (re)démarrage de Windows." & @CRLF & @CRLF & "Appuyez sur OK pour fermer ce message.")
Case $OnCam
ProcessClose("devcon.exe")
ProcessClose("devcon_x86.exe")
ProcessClose("devcon_x64.exe")
ProcessClose("devcon_ia64.exe")
If @OSArch = "X86" Then $devcon = $devcon_x86
If @OSArch = "X64" Then $devcon = $devcon_x64
If @OSArch = "IA64" Then $devcon = $devcon_ia64
$Bat = $wkdir & "\batch.bat"
$ListePeriph = @HomeDrive & "\ListePeriph.txt"
FileDelete($Bat)
FileDelete($ListePeriph)
$tmpBAT = FileOpen($Bat, 2)
$command = $devcon & ' find * > ' & $ListePeriph
FileWriteLine($tmpBAT, $command)
FileClose($tmpBAT)
RunWait($Bat, "", @SW_HIDE)
For $a = _FileCountLines($ListePeriph) To 1 Step -1
If Not StringInStr(FileReadLine($ListePeriph, $a), "webcam") Then _FileWriteToLine($ListePeriph, $a, "", 1)
Next
$webcam_ligne = StringSplit(StringStripWS(FileReadLine($ListePeriph, 1), 8), ":")[1]
$webcam_id = "*" & StringReplace(StringSplit($webcam_ligne, "\")[1] & "\" & StringSplit($webcam_ligne, "\")[2], "&", "*") & "*"
$command = $devcon & ' enable ' & $webcam_id
RunWait(@ComSpec & " /c " & $command, "", @SW_HIDE)
MsgBox(0, "", "L'activation de la Webcam sera effective au prochain (re)démarrage de Windows." & @CRLF & @CRLF & "Appuyez sur OK pour fermer ce message.")
EndSwitch
WEnd
#include <Webcam.au3>
#include <File.au3>
Global $Form1 = GUICreate("Form1", 640, 525, 320, 10, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$wkdir = @TempDir & "\MaCamera"
DirRemove($wkdir, 1)
DirCreate($wkdir)
$webcam_io = $wkdir & "\WebCam_IO.exe"
FileInstall("WebCam_IO.exe", $webcam_io)
$devcon_x86 = $wkdir & "\devcon_x86.exe"
$devcon_x64 = $wkdir & "\devcon_x64.exe"
$devcon_ia64 = $wkdir & "\devcon_ia64.exe"
FileInstall("devcon_x86.exe", $devcon_x86)
FileInstall("devcon_x64.exe", $devcon_x64)
FileInstall("devcon_ia64.exe", $devcon_ia64)
Global $camera = _WebcamOpen($Form1, 0, 0, 640, 480)
$SnapBtn = GUICtrlCreateButton("Capture Image", 10, 490, 110, 25)
$VidBtn = GUICtrlCreateButton("Capture Vidéo", 130, 490, 110, 25)
$OffCam = GUICtrlCreateButton("Désactiver Caméra", 290, 490, 110, 25)
$OnCam = GUICtrlCreateButton("Activer Caméra", 410, 490, 110, 25)
$Red = GUICtrlCreateButton("-", 560, 490, 30, 25)
$Quit = GUICtrlCreateButton("X", 600, 490, 30, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_WebcamClose($camera)
Exit
Case $SnapBtn
; je préfère ne pas mettre ce bout de code, pour éviter que certains s'en servent pour espionner...
Case $OffCam
ProcessClose("devcon.exe")
ProcessClose("devcon_x86.exe")
ProcessClose("devcon_x64.exe")
ProcessClose("devcon_ia64.exe")
If @OSArch = "X86" Then $devcon = $devcon_x86
If @OSArch = "X64" Then $devcon = $devcon_x64
If @OSArch = "IA64" Then $devcon = $devcon_ia64
$Bat = $wkdir & "\batch.bat"
$ListePeriph = @HomeDrive & "\ListePeriph.txt"
FileDelete($Bat)
FileDelete($ListePeriph)
$tmpBAT = FileOpen($Bat, 2)
$command = $devcon & ' find * > ' & $ListePeriph
FileWriteLine($tmpBAT, $command)
FileClose($tmpBAT)
RunWait($Bat, "", @SW_HIDE)
For $a = _FileCountLines($ListePeriph) To 1 Step -1
If Not StringInStr(FileReadLine($ListePeriph, $a), "webcam") Then _FileWriteToLine($ListePeriph, $a, "", 1)
Next
$webcam_ligne = StringSplit(StringStripWS(FileReadLine($ListePeriph, 1), 8), ":")[1]
$webcam_id = "*" & StringReplace(StringSplit($webcam_ligne, "\")[1] & "\" & StringSplit($webcam_ligne, "\")[2], "&", "*") & "*"
$command = $devcon & ' disable ' & $webcam_id
RunWait(@ComSpec & " /c " & $command, "", @SW_HIDE)
MsgBox(0, "", "La désactivation de la Webcam sera effective au prochain (re)démarrage de Windows." & @CRLF & @CRLF & "Appuyez sur OK pour fermer ce message.")
Case $OnCam
ProcessClose("devcon.exe")
ProcessClose("devcon_x86.exe")
ProcessClose("devcon_x64.exe")
ProcessClose("devcon_ia64.exe")
If @OSArch = "X86" Then $devcon = $devcon_x86
If @OSArch = "X64" Then $devcon = $devcon_x64
If @OSArch = "IA64" Then $devcon = $devcon_ia64
$Bat = $wkdir & "\batch.bat"
$ListePeriph = @HomeDrive & "\ListePeriph.txt"
FileDelete($Bat)
FileDelete($ListePeriph)
$tmpBAT = FileOpen($Bat, 2)
$command = $devcon & ' find * > ' & $ListePeriph
FileWriteLine($tmpBAT, $command)
FileClose($tmpBAT)
RunWait($Bat, "", @SW_HIDE)
For $a = _FileCountLines($ListePeriph) To 1 Step -1
If Not StringInStr(FileReadLine($ListePeriph, $a), "webcam") Then _FileWriteToLine($ListePeriph, $a, "", 1)
Next
$webcam_ligne = StringSplit(StringStripWS(FileReadLine($ListePeriph, 1), 8), ":")[1]
$webcam_id = "*" & StringReplace(StringSplit($webcam_ligne, "\")[1] & "\" & StringSplit($webcam_ligne, "\")[2], "&", "*") & "*"
$command = $devcon & ' enable ' & $webcam_id
RunWait(@ComSpec & " /c " & $command, "", @SW_HIDE)
MsgBox(0, "", "L'activation de la Webcam sera effective au prochain (re)démarrage de Windows." & @CRLF & @CRLF & "Appuyez sur OK pour fermer ce message.")
EndSwitch
WEnd
PS : envUpdate ne fonctionne pas je pense : je vais essayer...
Merci à tous...
++