Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logged-on, user name 2

Status
Not open for further replies.

Alt255

Programmer
May 14, 1999
1,846
US
This will seem like a frivolous question to some but the completion of a project is hanging on a workable resolution and I can't see the answer (if it were a snake it probably would have chewed off my leg by now - but I still can't see it).<br>
How does one obtain the name of the current user without relying on a database connection? My background app needs to know the name of the user within seconds of a new login and it must work with 100% reliability on all Win9x machines. I'm not worried about users bypassing the Windows login by hitting ESC at the password dialog (my app gives the user only two options: either login with a valid password or turn the computer off).<br>
The API doesn't appear to provide a way to get the &quot;Windows&quot; user name (then again, the API is a snake that has already had its fill of my leg, on numerous occasions).<br>
<br>
Could somebody please pull this reptile off of my foot before it takes another gulp?<br>
<br>
Any suggestions will earn my eternal gratitude.<br>

 
<br>
If I understand you correctly, you want to retrieve the username who is logged onto the workstation. If this is the case then this code should work:<br>
<br>
Public Declare Function GetUserName Lib &quot;advapi32.dll&quot; Alias &quot;GetUserNameA&quot; (ByVal lpBuffer As String, nSize As Long) As Long<br>
<br>
Public Function UserName() As String<br>
<br>
Dim sBuffer As String<br>
Dim lSize As Long<br>
<br>
sBuffer = Space$(255)<br>
lSize = Len(sBuffer)<br>
<br>
Call GetUserName(sBuffer, lSize)<br>
<br>
If lSize &gt; 0 Then _<br>
UserName = UCase$(Left$(sBuffer, lSize))<br>
<br>
End Function<br>
<br>
I hope this helps!<br>
<br>
Tarek<br>

 
Oops... it <b>was</b> a snake! I somehow had concluded that GetUserName was only useful for retrieving the name of the current database user. I didn't bother to try it on startup.<br>
It turned out to be exactly what I was looking for all along. Thanks, VB400, for a nudge in the right direction.<br>
<br>
Sometimes the solution is so close it blocks the view of our nose.
 
Now I'm getting excited! It's all falling together in one easy piece of code. Tarek, you may never know what your push did for me today but, rest assured, my pledge is secure. If you need anything I can provide, I'll be there.<br>
<br>

 
Is there a way to say &quot;GetUserPassword&quot;? Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;The intermediate stage between socialism and capitalism is alcoholism.&quot; Norman Brenner

 
Maybe.

Use [tt]WNetVerifyPassword[/tt] to verify that a password is correct for the current user.
Use [tt]WNetEnumCachedPasswords[/tt] to try to retrieve a password for the current user. (I think the last one is somewhat &quot;undocumented&quot;.)

Geez, this thread is a blast from the past. I thought that somebody was posing as Alt255 until I opened the thread and, remembering the situation, tried to speculate on how much I had been drinking.
VCA.gif

Alt255@Vorpalcom.Intranets.com​
 
The only problem with that function, is that I can't get it to work under WinNT. I get the error &quot;Can't find DLL entry point WNetEnumCachedPasswords&quot;. Any ideas? Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;The intermediate stage between socialism and capitalism is alcoholism.&quot; Norman Brenner

 
Sorry. I have never heard of any practical way to get a password under NT. It really isn't worth the effort.

Even under Win9x, WNetEnumCachedPasswords serves little purpose. It only retrieves the cached passwords for the currently logged on user. Why not just ask him for the password? He's probably sitting at the machine.

But... if you feel like wasting a little time, you might try generating an endless list of random character combinations, testing each one with [tt]WNetVerifyPassword[/tt].

Then again, what would be the point of the exercise?
VCA.gif

Alt255@Vorpalcom.Intranets.com​
 
I tried using the WNetVerifyPassword routine, but that failed as well. It seems under the NT system access to the mpr.dll file is denied for users.

The reason for this exercise was simply to get the password for a logged on terminal, so that I can log another terminal on with the same user/password. Unfortunately the person owning that logon is no longer around, but his terminal is.... weird situation. Thanks a bunch though! :) Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;The intermediate stage between socialism and capitalism is alcoholism.&quot; Norman Brenner

 
Michael,

Notwithstanding the loopholes that are exploited on a regular basis, NT is a secure system. User passwords are only held in a one-way hashed, encrypted form.

There is no (easy) way of retrieving the original plaintext version.

If you've got access to the SAM, then it is possible to use crypto techniques (including brute force attacks) to determine a given password (and this is made easier if the NT box is still configured to support LANMAN password hashing).

However, if you have legitimate access to the SAM, then it would be much, much simpler to use User Admin to change the user's password to something new.

And if you don't have access - well, this isn't the forum for hacking NT security.
 
strongm,
I understand that :) and that wasn't the intent of my doing either. The issue is being resolved the long way now (bureaucracy and paperwork).

Thanks for your help though. :)

Best Regards and many Thanks!
Michael G. Bronner X-)

&quot;Beer makes you feel the way you ought to feel with out beer.&quot; Henry Lawson

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top