Re: Linking notes?

> No ideas on linking to the Windows login name?

> > Not a CHANCE > This I took care of using API also. > > Corey

Are you using VB macro? If so, how did you "get" the login name?

/Anders

Reply to
bagarnx
Loading thread data ...

Yes here it is I can't remember who gave me this example but it has worked quite well here.

' Declare for call to mpr.dll. Declare Function WNetGetUser Lib "mpr.dll" _ Alias "WNetGetUserA" (ByVal lpName As String, _ ByVal lpUserName As String, lpnLength As Long) As Long

Const NoError = 0 'The Function call was successful Public UserInitials As String

Sub GetUserName()

' Buffer size for the return string. Const lpnLength As Integer = 255

' Get return buffer space. Dim status As Integer

' For getting user information. Dim lpName, lpUserName As String

' Assign the buffer size constant to lpUserName. lpUserName = Space$(lpnLength + 1)

' Get the log-on name of the person using product. status = WNetGetUser(lpName, lpUserName, lpnLength)

' See whether error occurred. If status = NoError Then ' This line removes the null character. Strings in C are null- ' terminated. Strings in Visual Basic are not null-terminated. ' The null character must be removed from the C strings to be used ' cleanly in Visual Basic. lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1) Else

' An error occurred. 'MsgBox "Unable to get the name." End End If

' Display the name of the person logged on to the machine. MsgBox "The person logged on this machine is: " & lpUserName End Sub

Regards

Corey Scheich

Reply to
Corey Scheich

That worked perfectly! Thank you!

/Anders

Reply to
bagarnx

I tried the macro listed. Cut and paste it into a new macro. When I run the macro, I get "Compile error: Only comments may appear after End Sub, End Function, or End Propert". It highlights the initial Declare Function call (lines 2, 3, & 4 of the posted macro). I have not created anything in VB for some time. Anyone got a couple minutes to help me trouble shoot?

Reply to
pmwh

Is there a SUB or Function above the declare the declare needs to be up at the top with your variable declarations, try putting it in a new module with nothing in it.

I assume you were referring to the code I listed yesterday since your post is a reply to the origional post.

Also make sure that you didn't have any text at the bottom below the sub.

Corey

Reply to
Corey Scheich

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.