Re: retrieving user environment settings from system process

From: alpine (alpine_don'tsendspam_at_mvps.org)
Date: 03/25/04


Date: Thu, 25 Mar 2004 08:52:18 -0700

On Thu, 25 Mar 2004 16:28:59 +0100, "Martin Egerter"
<megerter@t-online.de> wrote:

>Hi everybody,
>
>I'm trying to write a little prog, that is going to run as a service in the
>system context. However, this service is supposed to retrieve the value of a
>certain user environment variable of all currently logged on users.
>
>In C++ this can be done by first calling LsaEnumerateLogonSessions and then
>pass the returned SessionID's to LsaGetLogonSessionData. This function
>returns a structure that holds the data I need.
>
>So far so good. The bad news is, that I didn't find any source on the web
>that would tell me how to declare these functions in VB.
>
>Any hint is appreciated.
>
>Regards,
>
>Martin

In briefly looking at the struct definitions in the MSDN topics, the
only hitch I see off the top is that all of the strings appear to be
unicode. Since all VB strings are unicode under the hood but are
automatically converted to ASCII when passed in an API call, when
passing data in a call, you can use the StrPtr function to return a
pointer to the existing VB unicode string. So, you would declare all
of the unicode string pointers in the structs As Long and then pass
the pointer returned by StrPtr. There are a couple of different
methods you can use when retrieving string data from a pointer. What
you use will depend on the specifics of what you need to accomplish.

HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'tsendspam@mvps.org Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas