Solved

simple vb security

Posted on 2000-04-08
14
163 Views
Last Modified: 2010-05-02
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
Comment
Question by:blackc
  • 5
  • 3
  • 3
  • +2
14 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2696505
http://www.codearchive.com/vbasic/sysinfo.html


theres an example there that does such...its not the cleanest however
0
 
LVL 1

Expert Comment

by:skip99
ID: 2697122
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
 

Author Comment

by:blackc
ID: 2697228
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 2697302
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
 
LVL 30

Expert Comment

by:Axter
ID: 2697308
blackc,
If you're using Windows NT, the code that skip99 listed will not stop a user from backing out.
0
 
LVL 1

Expert Comment

by:skip99
ID: 2697744
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
 

Author Comment

by:blackc
ID: 2698916
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 28

Accepted Solution

by:
AzraSound earned 100 total points
ID: 2698982
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
 
LVL 1

Expert Comment

by:skip99
ID: 2701705
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
 

Author Comment

by:blackc
ID: 2703875
Adjusted points from 100 to 150
0
 

Author Comment

by:blackc
ID: 2703876
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
 
LVL 5

Expert Comment

by:ianB
ID: 2707094
Community Support has reduced points from 150 to 100
0
 
LVL 5

Expert Comment

by:ianB
ID: 2707095
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
 

Author Comment

by:blackc
ID: 2710375
here ya go
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now