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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help calling "advapi32.dll" from ASP

Status
Not open for further replies.

AlexTekTip

Programmer
Aug 30, 2004
17
US
Hello,

I have the following snippet of code, which in VB gives me the current network login. I am trying to migrate the code to asp so I can use it from a web page. When I call my asp page the web server returns an error:
Technical Information (for support personnel)

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/SLApprover/MyVersion.asp, line 3, column 8


***Code Snippet Begins Here****
<%@ Language=VBScript %>
<%
Declare function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Dim NTUserName

function OSUserName()
Dim cn as String
Dim ls as Long
Dim res as Long
cn = String(1024, 0)
ls = 1024
res = GetUserName(cn, ls)
If res <> 0 Then
OSusername = mid(cn, 1, InStr(cn, Chr(0)) - 1)
Else
OSusername = ""
End if
end function

NTUserName = OSUserName()
Response.Write("The NT User Name is: " & NTUserName)

%>
***Code Snippet End Here****



Any obvious problems? Can I not call the windows API libraries from ASP?

Thanks.
 
Not sure about calling DLLs, I'll leave that to someone else.

You can get the user's WinNT logon, though, much more easily, via
Code:
Request.Servervariables("LOGON_USER")
I don't know how spoofable it is or anything, but it's worked fine under intranet scenarios I've been involved in.
 
You can't make API calls from ASP.
Wrap it up in a VB/C++ COM component.

- J
 
Have an example? Or a website that discusses it?

Anyway,

I was able to get what I needed by using the servervariables("LOGON_USER") but it would be nice to know several methods.


Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top