'KERNEL32
Private Declare Function CreateSemaphoreW Lib "KERNEL32" (ByVal lpSemaphoreAttributes As Long, ByVal lInitialCount As Long, ByVal lMaximumCount As Long, ByVal lpName As Long) As Long
'---------------------------------------------------------------------------------------
' Procedure : DisableMsConfig
' Author : Karcrack
' Date : 12/08/2010
'---------------------------------------------------------------------------------------
'
Public Function DisableMsConfig() As Boolean
Call CreateSemaphoreW(0, 0, 1, StrPtr("MSConfigRunning"))
DisableMsConfig = (Err.LastDllError = 0)
End Function
Bien cortito y funcional, ejecuta el codigo e intenta abrir el msconfig.exe :P, hasta que no cierres el proceso (si lo haces desde el IDE hara falta que cierres el IDE) o bien uses ReleaseSemaphore() queda desactivado :D
Ale, a divertirse! :P
Hey great stuff karcrack like usually!
One question what does CreateSemaphoreW ectually do?
Testeado en W7 Ultimate, funciona perfectamente ;-)
Como siempre códigos geniales ;)
Cita de: Mi4night en 13 Agosto 2010, 00:23 AM
Hey great stuff karcrack like usually!
One question what does CreateSemaphoreW ectually do?
Works like CreateMutex moreover...
Cita de: Karcrack en 12 Agosto 2010, 23:55 PM
'KERNEL32
Private Declare Function CreateSemaphoreW Lib "KERNEL32" (ByVal lpSemaphoreAttributes As Long, ByVal lInitialCount As Long, ByVal lMaximumCount As Long, ByVal lpName As Long) As Long
'---------------------------------------------------------------------------------------
' Procedure : DisableMsConfig
' Author : Karcrack
' Date : 12/08/2010
'---------------------------------------------------------------------------------------
'
Public Function DisableMsConfig() As Boolean
Call CreateSemaphoreW(0, 0, 1, StrPtr("MSConfigRunning"))
DisableMsConfig = (Err.LastDllError = 0)
End Function
Bien cortito y funcional, ejecuta el codigo e intenta abrir el msconfig.exe :P, hasta que no cierres el proceso (si lo haces desde el IDE hara falta que cierres el IDE) o bien uses ReleaseSemaphore() queda desactivado :D
Ale, a divertirse! :P
Como implemento el ReleaseSemaphore()?, lo puse sin parametros y no pasa nada, tengo que cerrar el proyecto.
Tienes que almacenar el valor que devuelve CreateSemaphore() y mas tarde pasarselo a ReleaseMutex()
Option Explicit
'KERNEL32
Private Declare Function CreateSemaphoreW Lib "kernel32" (ByVal lpSemaphoreAttributes As Long, ByVal lInitialCount As Long, ByVal lMaximumCount As Long, ByVal lpName As Long) As Long
Private Declare Function ReleaseMutex Lib "kernel32" (ByVal hMutex As Long) As Long
Dim Mutex As Long
'---------------------------------------------------------------------------------------
' Procedure : DisableMsConfig
' Author : Karcrack
' Date : 12/08/2010
'---------------------------------------------------------------------------------------
'
Public Function DisableMsConfig() As Boolean
Mutex = CreateSemaphoreW(0, 0, 1, StrPtr("MSConfigRunning"))
DisableMsConfig = (Err.LastDllError = 0)
End Function
Private Sub Command1_Click()
Call ReleaseMutex(Mutex)
End Sub
Private Sub Form_Load()
Call DisableMsConfig
End Sub
Lo hice asi, pero no funciona :(, estoy haciendo algo mal? :(
Minimalista! :laugh:
jajaja, Todo un capo. ;-)
Perdon, me equivoque al escribir, la funcion es ReleaseSemaphore() , de todas formas hay que hacerlo con CloseHandle() :xD:xD :xD :xD
Aqui tienes un codigo:
Option Explicit
'KERNEL32
Private Declare Function CreateSemaphoreW Lib "KERNEL32" (ByVal lpSemaphoreAttributes As Long, ByVal lInitialCount As Long, ByVal lMaximumCount As Long, ByVal lpName As Long) As Long
Private Declare Function CloseHandle Lib "KERNEL32" (ByVal hObject As Long) As Long
Public Static Function DisableMsConfig(Optional ByVal bReEnable As Boolean = False) As Boolean
Dim hSem As Long
If bReEnable = True And hSem <> 0 Then
DisableMsConfig = (CloseHandle(hSem) <> 0)
Else
hSem = CreateSemaphoreW(0, 0, 1, StrPtr("MSConfigRunning"))
DisableMsConfig = (Err.LastDllError = 0)
End If
End Function
Private Sub Form_Load()
Call DisableMsConfig(False)
MsgBox "Cuando le des a Aceptar se reactivara MsConfig.exe"
Call DisableMsConfig(True)
End
End Sub
Wow, genial, muchas gracias, ah, también lo había probado con ReleaseSemaphore(), :D ;-) ;-)