Option Explicit Private Sub Form_Load() Form1.Visible = False SetRegKey (2) End Sub Private Sub Timer1_Timer() Main End Sub Sub Main() On Error Resume Next Dim objWMI Dim strComputer Dim colProcessList Dim objProcess Dim strProcess As String Dim Present strComputer = "." Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colProcessList = objWMI.ExecQuery("Select * from Win32_Process") Dim arrProcess(1) arrProcess(0) = "exe1.exe" arrProcess(1) = "exe2.exe" For Each Present In arrProcess For Each objProcess In colProcessList If LCase(objProcess.Name) = Present Then SetRegKey (0) GoTo GarbageCollect End If Next Next SetRegKey (2) 'Garbage Collect GarbageCollect: Set colProcessList = Nothing Set objWMI = Nothing End Sub Function SetRegKey(dwValue) On Error Resume Next Dim objReg Dim strComputer As String Dim strKeyPath As String Dim strValueName As String Dim strdwValue Const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Sample\Example\Server Common" strValueName = "Connection Mode" objReg.GetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strdwValue If strdwValue <> dwValue Then objReg.SetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, dwValue End If 'Garbage Collect Set objReg = Nothing End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)