Link to home
Start Free TrialLog in
Avatar of blackc
blackc

asked on

simple vb security

i am trying to make a very simple security program with vb.  all i want it to do is not allow any activity untill a password has been entered.  i have disabled the close box, and gotten everything to work, except that it is perfectly happy being put in the background, either with alt+tab, ctrl-alt-del, or the windows hotkey.  how do i stop this?
Avatar of AzraSound
AzraSound
Flag of United States of America image

http://www.codearchive.com/vbasic/sysinfo.html


theres an example there that does such...its not the cleanest however
Avatar of skip99
skip99

This code will basically not allow the user to quit your application even by using CTRL+ALT+DEL It will also keep the Form You specify Absolutely on top Nothing will override it.

'Place the following into a module:

Public Declare Function RegisterServiceProcess Lib "kernel32.dll" (ByVal dwProcessId As Long, ByVal dwType As Long) As Long
Public Declare Function GetCurrentProcessId Lib "kernel32.dll" () As Long
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hwndinsertafter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
       Public Const conHwndTopmost = -1
       Public Const conSwpShowWindow = &H40
       Public Const HWND_NOTOPMOST = -2

       Public Const SWP_NOSIZE = &H1
       Public Const SWP_DRAWFRAME = &H20
       Public Const SWP_HIDEWINDOW = &H80


' In your Form Load of your startup form place this and your done.

RegisterServiceProcess GetCurrentProcessId, 1

' in the form load and unload for the form which you want to stay on top put this:

OnTop = True ' (Load) Make form on top

OnTop = False ' (Unload) Normalize form



' In the General section of the form you want to stay on top place this:

Private Property Let OnTop(Setting As Boolean)
'Set form's OnTop property
    If Setting Then
        'make this form topmost
        SetWindowPos hwnd, HWND_TOPMOST, _
        0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    Else
        'Make this form non-topmost
        SetWindowPos hwnd, HWND_NOTOPMOST, _
        0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    End If
   
    mbOnTop = Setting
End Property

Private Property Get OnTop() As Boolean
    'Return the private variable set in property Let
    OnTop = mbOnTop
End Property
Avatar of blackc

ASKER

i put everything where you said to put it, but i could still alt+tab and ctrl alt del anything.  i went to the link that azrasound gave me, and i just modified that code (quite a bit actually)  but it serves my purpose admirably well.  you put quite a bit of effort into that answer tho, and i am sorry it didn't work.  if you would give me your email address, i would be happy to send you the file so you can tell me what i did wrong.  thanx!
Well I never saw where he disabled ctrl-alt-del, but this code does so:

***********************
Module Code
***********************

Private Declare Function SystemParametersInfo Lib _
"user32" Alias "SystemParametersInfoA" (ByVal uAction _
As Long, ByVal uParam As Long, ByVal lpvParam As Any, _
ByVal fuWinIni As Long) As Long


************************
Form Code
************************

Sub DisableCtrlAltDelete(bDisabled As Boolean)
    Dim X As Long
    X = SystemParametersInfo(97, bDisabled, CStr(1), 0)
End Sub

'To disable Ctrl-Alt-Delete:
Call DisableCtrlAltDelete(True)

'To enable Ctrl-Alt-Delete:
Call DisableCtrlAltDelete(False)


As for setting the window to the top, his code looks logical.  However I assume for your purposes that once a password is entered, this form that you want on top will be unloaded no?  If that were the case you should be able to implement it like this:


*************************
Module Code
*************************

Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const HWND_TOPMOST = -1


Function StayOnTop(Form As Form)
    Dim lFlags As Long
    Dim lStay As Long

    lFlags = SWP_NOSIZE Or SWP_NOMOVE
    lStay = SetWindowPos(Form.hwnd, HWND_TOPMOST, 0, 0, 0, 0, lFlags)
End Function



*******************
Form Code
*******************

'Call function on the form load event

Call StayOnTop(Me)


I would've written this out but I wasn't on my machine when I posted and didn't have all the necessary declarations memorized.  I knew that code wasn't spectacular and I figured it would take some cleaning up to do, and it appears you did it well.  Good job!  Let me know if you have further questions pertaining to this matter.



Avatar of Axter
blackc,
If you're using Windows NT, the code that skip99 listed will not stop a user from backing out.
sorry blackc I misread your code and Axter is correct It will not work under NT, Only 95/98. I thought you wanted to make it so that the user would not be able to leave your application ie Force Quitting it. Please send me your project zipped and I'll take a look

Grant
skip99@home.com
Avatar of blackc

ASKER

i am using windows 95, and will use my program on 98, so no worries about NT.  i think i got it with that code from the other website, and by this point, it hardly resembles the program that was posted.  however i like you both, and you are both very freindly, so how about if i up the points 2 150 and give azra sound 100 for the answer, and give skip 99 50 for a great efffort? do you guys know how to split the points between 2 people?  if not i will just ask another question and let ya answer it for your points.  your all very helpful, and i like you.  

chris
ASKER CERTIFIED SOLUTION
Avatar of AzraSound
AzraSound
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Chris,

I might be able to help ya make you program more sercure and restrictive if you e-mail me your project... I can't really suggest anything else tho because I'm not exactly sure how it works...

Cheers
Grant
Avatar of blackc

ASKER

Adjusted points from 100 to 150
Avatar of blackc

ASKER

the points should be split very soon, and skip99, as soon as i get home (im at school right now)  i will email you the program, tho my encryption is still seriously under construction.
Community Support has reduced points from 150 to 100
Hi,

In order to assist the points splitting process. I have reduced the points on this question to 100. blackc, please grade one of the arasound this question, and post a 50 point question for skip99.

Please post a comment at your Community Support question when you have done so :

https://www.experts-exchange.com/jsp/qShow.jsp?ta=commspt&qid=10326385 

Ian
Community Support @ Experts Exchange
Avatar of blackc

ASKER

here ya go