Loading ...
Sorry, an error occurred while loading the content.
 

AW: How to tell the type of log-on

Expand Messages
  • pendl2megabit
    Keith, here is what I have so far. I receive the error Buffer To Small for the GetGroups call, maybe you can work it out how to get the address of the buffer
    Message 1 of 13 , Sep 1, 2004
      Keith,
      here is what I have so far.
      I receive the error Buffer To Small for the GetGroups call, maybe you can work
      it out how to get the address of the buffer to be recognised by the call.

      ---
      Stefan Pendl

      '--- code start
      ' get group information of user

      open "netapi32.dll" for dll as #netapi32
      open "advapi32" for dll as #advapi32

      struct Buffer, address as ulong

      ByteCount = 2048

      calldll #netapi32, "NetApiBufferAllocate", _
      ByteCount as ulong, _
      Buffer as struct, _
      result as ulong

      print "Allocate ", result

      struct Size, value as ulong
      Size.value.struct = 256
      Buffer$ = space$(Size.value.struct)

      calldll #advapi32, "GetUserNameA", _
      Buffer$ as ptr, _
      Size as struct, _
      result as boolean

      MultiByteStr$ = Buffer$
      CodePage = 1 ' CP_OEMCP
      chMultiByte = -1
      chWideChar = len(MultiByteStr$)
      WideCharStr$ = space$(3 * chWideChar)

      calldll #kernel32, "MultiByteToWideChar", _
      CodePage as ulong, _
      Flags as ulong, _
      MultiByteStr$ as ptr, _
      chMultiByte as ulong, _
      WideCharStr$ as ptr, _
      chWideChar as ulong, _
      result as ulong

      print "Unicode", result, WideCharStr$

      username$ = WideCharStr$
      level = 0

      struct entriesread, value as ulong
      struct totalentries, value as ulong

      calldll #netapi32, "NetUserGetGroups", _
      servername$ as ptr, _
      username$ as ptr, _
      level as ulong, _
      Buffer as struct, _
      prefmaxlen as ulong, _
      entriesread as struct, _
      totalentries as struct, _
      result as ulong

      print "GetGroups", result

      calldll #netapi32, "NetApiBufferFree", _
      Buffer as struct, _
      result as ulong

      print "Free ", result

      close #advapi32
      close #netapi32
      end
      '--- code end


      > -----Ursprüngliche Nachricht-----
      > Von: fearworks
      > Gesendet: Dienstag, 31. August 2004 23:55
      > An: libertybasic@yahoogroups.com
      > Betreff: [libertybasic] Re: How to tell the type of log-on
      >
      >
      >
      > Thanks for the info.
      >
      > Anybody any ideas how to implement this then?
      >
      > All I need is to tell what type of user someone is logged into
      > Windows as...administrator, limited, and so on.
      >
      > Thanks if you can help!
      >
      > Thanks for reading even if you can't!!
      >
      > Keith.
    • fearworks
      Thanks Stefan. I ran it a few times, but didn t get the error you described. In the ... Error log timestamp 9/1/2004 23:28:0 The registers were: EIP =
      Message 2 of 13 , Sep 1, 2004
        Thanks Stefan.

        I ran it a few times, but didn't get the error you described. In the
        error.log, this is what I sometimes get:

        ----------------------------------------
        Error log timestamp 9/1/2004 23:28:0

        The registers were:
        EIP = 0x00bfbc60
        ESP = 0x0012fc68
        EBP = 0x0012fc80
        EAX = 0x00000001
        EBX = 0xffffeba3
        ECX = 0x00bfc4f7
        EDX = 0x0000002c
        EDI = 0x00cf4f14
        ESI = 0x00cf2114
        CS = 0x0000001b
        DS = 0x00000023
        ES = 0x00000023
        SS = 0x00000023
        End Registers



        Error log timestamp 9/1/2004 23:28:00
        Message 1001:
        a non-continuable protection violation has occurred. Check ERROR.LOG
        file.
        ----------------------------------------

        Is this effectively the same as your error??

        This error only showed up some of the time, not every time...

        What do the results mean though? I am not sure how I would interpret
        the results it shows in the window - which value relates to the type
        of log-in?

        Thanks if you can help any further.

        Keith.

        --- In libertybasic@yahoogroups.com, "pendl2megabit"
        <pendl2megabit@y...> wrote:
        > Keith,
        > here is what I have so far.
        > I receive the error Buffer To Small for the GetGroups call, maybe
        you can work
        > it out how to get the address of the buffer to be recognised by
        the call.
        >
        > ---
        > Stefan Pendl
        >
        > '--- code start
        > ' get group information of user
        >
        > open "netapi32.dll" for dll as #netapi32
        > open "advapi32" for dll as #advapi32
        >
        > struct Buffer, address as ulong
        >
        > ByteCount = 2048
        >
        > calldll #netapi32, "NetApiBufferAllocate", _
        > ByteCount as ulong, _
        > Buffer as struct, _
        > result as ulong
        >
        > print "Allocate ", result
        >
        > struct Size, value as ulong
        > Size.value.struct = 256
        > Buffer$ = space$(Size.value.struct)
        >
        > calldll #advapi32, "GetUserNameA", _
        > Buffer$ as ptr, _
        > Size as struct, _
        > result as boolean
        >
        > MultiByteStr$ = Buffer$
        > CodePage = 1 ' CP_OEMCP
        > chMultiByte = -1
        > chWideChar = len(MultiByteStr$)
        > WideCharStr$ = space$(3 * chWideChar)
        >
        > calldll #kernel32, "MultiByteToWideChar", _
        > CodePage as ulong, _
        > Flags as ulong, _
        > MultiByteStr$ as ptr, _
        > chMultiByte as ulong, _
        > WideCharStr$ as ptr, _
        > chWideChar as ulong, _
        > result as ulong
        >
        > print "Unicode", result, WideCharStr$
        >
        > username$ = WideCharStr$
        > level = 0
        >
        > struct entriesread, value as ulong
        > struct totalentries, value as ulong
        >
        > calldll #netapi32, "NetUserGetGroups", _
        > servername$ as ptr, _
        > username$ as ptr, _
        > level as ulong, _
        > Buffer as struct, _
        > prefmaxlen as ulong, _
        > entriesread as struct, _
        > totalentries as struct, _
        > result as ulong
        >
        > print "GetGroups", result
        >
        > calldll #netapi32, "NetApiBufferFree", _
        > Buffer as struct, _
        > result as ulong
        >
        > print "Free ", result
        >
        > close #advapi32
        > close #netapi32
        > end
        > '--- code end
        >
        >
        > > -----Ursprüngliche Nachricht-----
        > > Von: fearworks
        > > Gesendet: Dienstag, 31. August 2004 23:55
        > > An: libertybasic@yahoogroups.com
        > > Betreff: [libertybasic] Re: How to tell the type of log-on
        > >
        > >
        > >
        > > Thanks for the info.
        > >
        > > Anybody any ideas how to implement this then?
        > >
        > > All I need is to tell what type of user someone is logged into
        > > Windows as...administrator, limited, and so on.
        > >
        > > Thanks if you can help!
        > >
        > > Thanks for reading even if you can't!!
        > >
        > > Keith.
      • Chuck Card
        PMFJI Could you have a permissions issue? What class of user is the program running as? Regards, ShakerRapid [Non-text portions of this message have been
        Message 3 of 13 , Sep 1, 2004
          PMFJI

          Could you have a permissions issue?
          What class of user is the program running as?

          Regards,

          ShakerRapid


          [Non-text portions of this message have been removed]
        • fearworks
          On my system, I am running it with full admin permissions (WinXP Prof) Keith.
          Message 4 of 13 , Sep 1, 2004
            On my system, I am running it with full admin permissions (WinXP
            Prof)

            Keith.

            --- In libertybasic@yahoogroups.com, "Chuck Card" <cardcd@e...>
            wrote:
            > PMFJI
            >
            > Could you have a permissions issue?
            > What class of user is the program running as?
            >
            > Regards,
            >
            > ShakerRapid
            >
            >
            > [Non-text portions of this message have been removed]
          • pendl2megabit
            Keith and ShakerRapid, this call will have no permission issues, because it checks the groups of the current user. It would indeed act different if you would
            Message 5 of 13 , Sep 1, 2004
              Keith and ShakerRapid,
              this call will have no permission issues, because it checks the groups of the
              current user.
              It would indeed act different if you would check a different user, where you
              need administrative rights.

              The printout of the results, is to know if a call failed or not.
              For more information you will have to read the descriptions of the calls.

              The error I get is not printed to the LB error.log, it is the returning of
              2123 for the GetGroups call.

              The main problem is how to tell the GetGroups call to use the buffer previous
              allocated by the NetAPI call ???
              How can I submit a pointer address returned from another call to the GetGroups
              call ???
              In VB the receiving buffer is translated to "As String", but this didn't work
              for me :-((
              For the NetAPI allocate and free calls the buffer is translated to "As Any",
              which is neither helpfull.
              I am stuck, can someone with C knowledge enlight this ???

              TIA,
              Stefan Pendl


              > -----Ursprüngliche Nachricht-----
              > Von: fearworks
              > Gesendet: Donnerstag, 02. September 2004 04:46
              > An: libertybasic@yahoogroups.com
              > Betreff: [libertybasic] Re: How to tell the type of log-on
              >
              >
              > On my system, I am running it with full admin permissions (WinXP
              > Prof)
              >
              > Keith.
            • Ken Lewis, Sr.
              ... From: pendl2megabit Stefan; I have worked part way thru this. ... This code indicates that the buffer is too small. here is the
              Message 6 of 13 , Sep 6, 2004
                ----- Original Message -----
                From: "pendl2megabit" <pendl2megabit@...>

                Stefan;
                I have worked part way thru this.

                > The error I get is not printed to the LB error.log, it is the returning of
                > 2123 for the GetGroups call.

                This code indicates that the buffer is too small.

                here is the current working code I think it still needs work

                '--- code start
                ' get group information of user

                open "netapi32.dll" for dll as #netapi32
                open "advapi32" for dll as #advapi32

                struct Buffer, address as ulong

                ByteCount = 2048

                calldll #netapi32, "NetApiBufferAllocate", _
                ByteCount as ulong, _
                Buffer as struct, _
                result as ulong

                theBuffer=Buffer.address.struct

                print "Allocate ", result

                struct Size, value as ulong
                Size.value.struct = 256
                Buffer$ = space$(Size.value.struct)

                calldll #advapi32, "GetUserNameA", _
                Buffer$ as ptr, _
                Size as struct, _
                result as boolean

                MultiByteStr$ = Buffer$
                CodePage = 1 ' CP_OEMCP
                chMultiByte = -1
                chWideChar = len(MultiByteStr$)
                WideCharStr$ = space$(3 * chWideChar)

                calldll #kernel32, "MultiByteToWideChar", _
                CodePage as ulong, _
                Flags as ulong, _
                MultiByteStr$ as ptr, _
                chMultiByte as ulong, _
                WideCharStr$ as ptr, _
                chWideChar as ulong, _
                result as ulong

                print "Unicode", result, WideCharStr$

                username$ = WideCharStr$
                level = 0

                struct entriesread, value as ulong
                struct totalentries, value as ulong
                prefmaxlen= 0 or (-1)

                calldll #netapi32, "NetUserGetGroups", _
                servername$ as ptr, _
                username$ as ptr, _
                level as ulong, _
                theBuffer as ulong, _
                prefmaxlen as ulong, _
                entriesread as struct, _
                totalentries as struct, _
                result as ulong

                print "GetGroups", result
                print entriesread.value.struct
                print totalentries.value.struct
                print winstring(theBuffer)

                calldll #netapi32, "NetApiBufferFree", _
                Buffer as struct, _
                result as ulong

                print "Free ", result

                close #advapi32
                close #netapi32
                end
                '--- code end

                Ken
              • pendl2megabit
                Ken, thank you verymuch, I completly forgot, that a string is just a pointer and a pointer is just a number. The netusergetgroups call seems to return another
                Message 7 of 13 , Sep 6, 2004
                  Ken,
                  thank you verymuch, I completly forgot, that a string is just a pointer and a
                  pointer is just a number.
                  The netusergetgroups call seems to return another pointer inside the buffer,
                  now I have just to figure out the format of a pointer ;-)

                  ---
                  Stefan Pendl


                  > -----Ursprüngliche Nachricht-----
                  > Von: Ken Lewis, Sr.
                  > Gesendet: Montag, 06. September 2004 19:58
                  > An: libertybasic@yahoogroups.com
                  > Betreff: Re: [libertybasic] AW: How to tell the type of log-on
                  >
                  >
                  ---snip
                  >
                  > struct entriesread, value as ulong
                  > struct totalentries, value as ulong
                  > prefmaxlen= 0 or (-1)
                  >
                  > calldll #netapi32, "NetUserGetGroups", _
                  > servername$ as ptr, _
                  > username$ as ptr, _
                  > level as ulong, _
                  > theBuffer as ulong, _
                  > prefmaxlen as ulong, _
                  > entriesread as struct, _
                  > totalentries as struct, _
                  > result as ulong
                  >
                  > print "GetGroups", result
                  > print entriesread.value.struct
                  > print totalentries.value.struct
                  > print winstring(theBuffer)
                  >
                  ---snip
                • Ken Lewis, Sr.
                  ... From: pendl2megabit To: Sent: Monday, September 06, 2004 3:49 PM Subject: [libertybasic] AW: How
                  Message 8 of 13 , Sep 6, 2004
                    ----- Original Message -----
                    From: "pendl2megabit" <pendl2megabit@...>
                    To: <libertybasic@yahoogroups.com>
                    Sent: Monday, September 06, 2004 3:49 PM
                    Subject: [libertybasic] AW: How to tell the type of log-on


                    > Ken,
                    > thank you verymuch, I completly forgot, that a string is just a pointer
                    and a
                    > pointer is just a number.
                    > The netusergetgroups call seems to return another pointer inside the
                    buffer,
                    > now I have just to figure out the format of a pointer ;-)
                    >
                    > ---
                    > Stefan Pendl

                    The buffer return is wide char so you will have to convert it to multibyte

                    Ken
                  • pendl2megabit
                    Ken, the unicode to ansi conversion is not the problem. The string returned is just 3 chars long, which fits not the expected result for the group name
                    Message 9 of 13 , Sep 6, 2004
                      Ken,
                      the unicode to ansi conversion is not the problem.
                      The string returned is just 3 chars long, which fits not the expected result
                      for the group name Administrators :-(
                      The result should be at least 28 chars long :-o

                      ---
                      Stefan Pendl


                      > -----Ursprüngliche Nachricht-----
                      > Von: Ken Lewis, Sr.
                      > Gesendet: Montag, 06. September 2004 23:08
                      > An: libertybasic@yahoogroups.com
                      > Betreff: Re: [libertybasic] AW: How to tell the type of log-on
                      >
                      >
                      > The buffer return is wide char so you will have to convert it to multibyte
                      >
                      > Ken
                    • pendl2megabit
                      Ken, I already increased the pointer by the length of the returned string till I get no string returned by WINSTRING(). The result I get is the All Users
                      Message 10 of 13 , Sep 6, 2004
                        Ken,
                        I already increased the pointer by the length of the returned string till I
                        get no string returned by WINSTRING().
                        The result I get is the "All Users" profile directory name.
                        I am using Win2k SP4.
                        Will check tomorow on WinXP Pro SP2, because its midnight now in Austria.

                        ---
                        Stefan Pendl


                        > -----Ursprüngliche Nachricht-----
                        > Von: Ken Lewis, Sr.
                        > Gesendet: Montag, 06. September 2004 23:08
                        > An: libertybasic@yahoogroups.com
                        > Betreff: Re: [libertybasic] AW: How to tell the type of log-on
                        >
                        >
                        > The buffer return is wide char so you will have to convert it to multibyte
                        >
                        > Ken
                      Your message has been successfully submitted and would be delivered to recipients shortly.