[m][VB6][SNIPPET] DisableMsConfig - Desactiva Msconfig.exe

Iniciado por Karcrack, 12 Agosto 2010, 23:55 PM

0 Miembros y 1 Visitante están viendo este tema.

Karcrack

Código (vb) [Seleccionar]
'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

Mi4night

Hey great stuff karcrack like usually!

One question what does CreateSemaphoreW  ectually do?

aaronduran2

Testeado en W7 Ultimate, funciona perfectamente ;-)

Como siempre códigos geniales ;)

Karcrack

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...

Miseryk

Cita de: Karcrack en 12 Agosto 2010, 23:55 PM
Código (vb) [Seleccionar]
'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.
Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It's never too late to change our luck
So, don't let them steal your light
Don't let them break your stride
There is light on the other side
And you'll see all the raindrops falling behind
Make it out tonight
it's a revolution

CL!!!

Karcrack

Tienes que almacenar el valor que devuelve CreateSemaphore() y mas tarde pasarselo a ReleaseMutex()

Miseryk

Código (vb) [Seleccionar]

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? :(
Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It's never too late to change our luck
So, don't let them steal your light
Don't let them break your stride
There is light on the other side
And you'll see all the raindrops falling behind
Make it out tonight
it's a revolution

CL!!!

wh0!


Karcrack

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:
Código (vb) [Seleccionar]
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

Miseryk

Wow, genial, muchas gracias, ah, también lo había probado con ReleaseSemaphore(), :D  ;-) ;-)
Can you see it?
The worst is over
The monsters in my head are scared of love
Fallen people listen up! It's never too late to change our luck
So, don't let them steal your light
Don't let them break your stride
There is light on the other side
And you'll see all the raindrops falling behind
Make it out tonight
it's a revolution

CL!!!