Get computer name (1 Viewer)

born2live

Registered User.
Local time
Tomorrow, 02:52
Joined
Jul 19, 2012
Messages
26
Hi guys,
I have a database which is going to be used in network of the company.
I have defined authorized Domain usernames and Computer Names in a table.
There is a Login form in which I placed a code to get the computer name and domain username to compare with the ones I have defined in the mentioned table.
The problem is that the defined phrase is text, but I don't know what kind of data the gotten computer name is!
For example I have defined a computer name like Smith in the table that has 5 characters and also there is a domain computer name with Smith name but vba doesn't detect them equal and shows Len of the gotten computer name as 255.
How can I convert that phrase to its real number of characters??? :banghead:

Any helps will be appreciated,
Thanks
 
Last edited:

namliam

The Mailman - AWF VIP
Local time
Today, 23:22
Joined
Aug 11, 2003
Messages
11,696
Have you tried using the Trim function?
 

namliam

The Mailman - AWF VIP
Local time
Today, 23:22
Joined
Aug 11, 2003
Messages
11,696
What function are you using to get the computer name?
 

born2live

Registered User.
Local time
Tomorrow, 02:52
Joined
Jul 19, 2012
Messages
26
This is the code I'm using to get the computer name:

Declare Function GetComputerName& Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long)

Function GetIdentifier()
Dim lpBuff As String * 1314
GetComputerName lpBuff, Len(lpBuff)
GetIdentifier = lpBuff
End Function
 

namliam

The Mailman - AWF VIP
Local time
Today, 23:22
Joined
Aug 11, 2003
Messages
11,696
Most likely they are some unreadable space or somesort....
Try
Code:
GetIdentifier = Replace(lpBuff, Right(lpBuff, 1), "")
 

born2live

Registered User.
Local time
Tomorrow, 02:52
Joined
Jul 19, 2012
Messages
26
Thank you namliam, It worked!
...
But I made a big mistake and now the database can't be opened!!!
I put a 3 part if in the Login form with 3 Ands. To check if Username of domain and using Computer Name are the same as what I have defined in table and also Thick of the EnableOrDisable field is "True", Form opens and if not, Application quits!
On my computer 2 parts of the if phrase is true, but the third part isn't and so application quits and I can't do anything.
Is there a way to recover the database and open it again???
I should say that System Restore didn't help me!
 

born2live

Registered User.
Local time
Tomorrow, 02:52
Joined
Jul 19, 2012
Messages
26
Thank you namliam, It worked!
...
But I made a big mistake and now the database can't be opened!!!
I put a 3 part if in the Login form with 3 Ands. To check if Username of domain and using Computer Name are the same as what I have defined in table and also Thick of the EnableOrDisable field is "True", Form opens and if not, Application quits!
On my computer 2 parts of the if phrase is true, but the third part isn't and so application quits and I can't do anything.
Is there a way to recover the database and open it again???
I should say that System Restore didn't help me!

The mistake also solved:
By holding Shift key down when the database is opening, it opens without executing scripts or forms. :D
But I think, this can be a bad point for the security of database!
 

namliam

The Mailman - AWF VIP
Local time
Today, 23:22
Joined
Aug 11, 2003
Messages
11,696
the bypasskey as this is called can be disabled as well
 

born2live

Registered User.
Local time
Tomorrow, 02:52
Joined
Jul 19, 2012
Messages
26
Could you please tell me how to disable the bypasskey?
 

namliam

The Mailman - AWF VIP
Local time
Today, 23:22
Joined
Aug 11, 2003
Messages
11,696
be carefull though, that is your "backdoor" if you dont have that and dont have your own version or ability to reallow the shift key... you may be screwed being locked out of your db
 

MarkK

bit cruncher
Local time
Today, 15:22
Joined
Mar 17, 2004
Messages
8,178
Also, try . . .
Code:
? Environ("Computername")
 

born2live

Registered User.
Local time
Tomorrow, 02:52
Joined
Jul 19, 2012
Messages
26
be carefull though, that is your "backdoor" if you dont have that and dont have your own version or ability to reallow the shift key... you may be screwed being locked out of your db

Thank you namliam, your comment is perfectly right. I just asked to know :)
 

Users who are viewing this thread

Top Bottom