[AccessD] OT: Broken API Call in WinXP: GetEnvironmentVariab le?

Mitsules, Mark S. (Newport News) Mark.Mitsules at ngc.com
Fri Nov 21 12:08:38 CST 2003


If it is any "console"-ation, ;) someone else has faced your situation.
Perhaps the reply to his question will provide something useful.


Q.
http://www.vbug.co.uk/vaspfaq/tsviewq.asp?ID=7755

A.
http://www.vbug.co.uk/vaspfaq/tsviewa.asp?AID=7756&QID=7755


Mark


-----Original Message-----
From: Christopher Hawkins [mailto:clh at christopherhawkins.com] 
Sent: Friday, November 21, 2003 12:58 PM
To: accessd at databaseadvisors.com
Subject: [AccessD] OT: Broken API Call in WinXP: GetEnvironmentVariable?


I have inherited an application that uses the GetEnvironmentVariable API to
identify a machine for purposes of authenticating that a certain application
can be accessed from that machine.  For those unfamiliar, here's the code
that makes this call:

***START***
Declare Function GetEnvironmentVariable Lib "kernel32" Alias
"GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As String,
ByVal nSize As Long) As Long


Private Function GetClientName() As String

Dim strBuffer As String
Dim iLenBuffer As Integer
Dim retval As Integer

On Error GoTo Err_GetClientName

    strBuffer = Space(255)
    iLenBuffer = 255

    retval = GetEnvironmentVariable("CLIENTNAME", strBuffer,
iLenBuffer)
    If Len(Trim(strBuffer)) <> 0 Then
    	strBuffer = Left(strBuffer, Len(Trim(strBuffer)) - 1)
    Else
        ' probably no client name
        strBuffer = ""
    End If
    
Exit_GetClientName:
    Exit Function

Err_GetClientName:
        MsgBox Err.Description, , "Error in Function modUtil.GetClientName"
        Resume Exit_GetClientName
    Resume 0    ' .FOR TROUBLESHOOTING
End Function
***END***

This has been working like a charm on Windows98 machines.  We add the
following line to AutoExec.bat:

"SET CLIENTNAME=FOOBAR"

And the API call returns the string "FOOBAR", every time without fail.

Now my client is migrating all their machines to XP.  Unfortunately, this
same API call returns an empty string, or sometimes the string "Console".

"OK," I think to myself. "XP doesn't really use AutoExec.bat, it uses
AutoExec.NT.  I'll set the ClientName in that file instead!  But that does
not work either.

IThe fact that XP will return the string "Console" every so often made me
think " Aha!  On XP this API call is looking in the registry, not in a .bat
file".  So I searched the registry for every place where the string
"Console" existed, and one by one replaced them with "FOOBAR" and re-ran the
code.  I still got nothing.  If it was returning "Console" before, it
returned "Console" again.  if it returned empty string before, it returned
empty string again.

Then I wet to Control Panel > System > Advanced > Environment Variables and
added a system variable named CLIENTNAME with a value of FOOBAR.

That did not work either, and now I am out of ideas.

Is there anyone who owns the API to the degree that they can tell me where
exactly GetEnvironmentVariable is looking to get the value it returns?  I am
well and truly stumped.

-Christopher-


_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com


More information about the AccessD mailing list