• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

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?
0
blackc
Asked:
blackc
  • 5
  • 3
  • 3
  • +2
1 Solution
 
AzraSoundCommented:
http://www.codearchive.com/vbasic/sysinfo.html


theres an example there that does such...its not the cleanest however
0
 
skip99Commented:
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
0
 
blackcAuthor Commented:
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!
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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



0
 
AxterCommented:
blackc,
If you're using Windows NT, the code that skip99 listed will not stop a user from backing out.
0
 
skip99Commented:
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
0
 
blackcAuthor Commented:
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
0
 
AzraSoundCommented:
thanks for the compliments and generosity chris.  if you wish to split up points you can do so by asking them to do so for you in the community support area.  
http://www1.experts-exchange.com/Customer_Service/Experts_Exchange/
just tell them what you want to do and how you want to do it and they will take care of it for you.  also be sure to include the url for this question so they know which question it is you are referring to.
0
 
skip99Commented:
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
0
 
blackcAuthor Commented:
Adjusted points from 100 to 150
0
 
blackcAuthor Commented:
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.
0
 
ianBCommented:
Community Support has reduced points from 150 to 100
0
 
ianBCommented:
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 :

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

Ian
Community Support @ Experts Exchange
0
 
blackcAuthor Commented:
here ya go
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 5
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now