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
|
Public Class Form1
'API
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As String) As Long
'CONSTANTE
Private Const WM_SETTINGCHANGE = &H1A
Private Const HWND_BROADCAST = &HFFFF&
Private Sub changement()
'Modifie la base de registre de windows
Dim cle, cletemp, msg As String
Dim i As Integer
cle = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet00"
For i = 1 To 9 Step 1
cletemp = cle + i.ToString + "\Control\Session Manager\Environment"
If My.Computer.Registry.GetValue(cletemp, _
"TrCatiaPath", Nothing) Is Nothing Then
msg = cletemp + " non trouver !!"
MsgBox(msg)
Else
msg = cletemp + " OK !!"
MsgBox(msg)
My.Computer.Registry.SetValue(cletemp, "TrCatiaPath", "c:\test")
End If
Next
'Message en Broadcoast pour l'envoie du changement à tous les processus de windows concernant cette modification
cle = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
My.Computer.Registry.SetValue(cle, "TrCatiaPath", "c:\test2")
Call SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, "Environment")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
changement()
End Sub
End Class |
Partager