If you want to make a program that's only for one person, then you can use this code in a MODULE:
VB6:
VB 2005+:Option Explicit
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Sub Get_User_Name()
Dim lpBuff As String * 25
Dim ret As Long, UserName As String
ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
If UserName = "Ebonesser" Then
Form2.Show
Else
MsgBox "This program does not belong to you", vbOKOnly + vbCritical, "ERROR!"
End If
End Sub
Call on these modules with something like this:Option Explicit On
Module Module1
Sub Get_User_Name()
Dim fName As String = Environment.UserName
If fName = "Ebonesser" Then
Form2.Show()
Else
MsgBox("This program does not belong to you", vbOKOnly + vbCritical, "ERROR!")
End If
End Sub
End Module
VB6:
VB 2005+:Private Sub Command1_Click()
Module1.Get_User_Name
End Sub
I used "Ebonesser" as user example.Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Module1.Get_User_Name()
End Sub
If you want to make it for more people, just do ""Ebonesser" or "Daniel" or "Martin"" and so many people you want, just use "or" in between. This is very useful for school/work networks where you can't change usernames, but also for homes because the person that is using your program doesn't know that you're using his/her username as a "key" to open the program. If the user changes the username and tells you that the program doesn't work, do a new program with his/her new name.
But these codes are mostly for school/work networks, where you can't change your name
I hope you like it and use it
//Ebonesser![]()