Re: retrieving user environment settings from system process

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

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



Relevant Pages

  • Re: with ctypes, how to parse a multi-string
    ... I am currently dealing with ctypes, ... Several APIs take a pointer to an ... unicode string as a parameter, which points at function return to a ... The last string is ...
    (comp.lang.python)
  • Re: UNICODE_STRING storage
    ... No, but it IS a Unicode string, as Alex said. ... >pointer to RtlInitUnicodeString would simply set the Length, MaximunLength, ...
    (microsoft.public.development.device.drivers)
  • Re: Efficency and the standard library
    ... loop will dereference a null pointer if argument strInstring is ... this code, out of adversarial hatred, envy and malice. ... Some C programmers in these threads would suggest const ... the output string. ...
    (comp.lang.c)
  • Re: ptrdiff_t overflow/underflow
    ... satisfy the vast majority of trim() use cases. ... It may point to a valid string, ... If any pointer can be converted to a 'void *', assuming there isn't any meta-data outside of the pointer's object representation, and assuming an implementation must not allow two 'void *' values to represent two separate objects, it seems like a fair upper bound. ... And if a pointer value includes bounds information, perhaps the implementation would be kind enough to document either the representation or how to access the information. ...
    (comp.lang.c)
  • Re: "Mastering C Pointers"....
    ... A pointer is a kind of variable that can "point to" some object. ... has a type (pointer to int), and a value of some kind. ... You may know that you can access these integers by using array notation ... The function will take one argument, a string, and will return the length ...
    (comp.lang.c)