Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 460873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:55:03+00:00 2026-05-12T22:55:03+00:00

EDIT: followup at NetUserModalsGet() returns strings incorrectly for C#.NET I’m struggling with the DLL

  • 0

EDIT: followup at NetUserModalsGet() returns strings incorrectly for C#.NET

I’m struggling with the DLL declarations for this function:

NET_API_STATUS NetUserModalsGet(
  __in   LPCWSTR servername,
  __in   DWORD level,
  __out  LPBYTE *bufptr
);

(Reference: http://msdn.microsoft.com/en-us/library/aa370656%28VS.85%29.aspx)

I tried this:

private string BArrayToString(byte[] myArray)
{
    string retVal = "";
    if (myArray == null)
        retVal = "Null";
    else
    {
        foreach (byte myByte in myArray)
        {
            retVal += myByte.ToString("X2");
        }
    }
    return retVal;
}

...

[DllImport("netapi32.dll")]
public static extern int NetUserModalsGet(
  string servername,
  int level,
  out byte[] bufptr
);

[DllImport("netapi32.dll")]
public static extern int NetApiBufferFree(
  byte[] bufptr
);

...

int retVal;
byte[] myBuf;

retVal = NetUserModalsGet("\\\\" + tbHost.Text, 0, out myBuf);
myResults.Text += String.Format("retVal={0}\nBuffer={1}\n", retVal, BArrayToString(myBuf));
retVal = NetApiBufferFree(myBuf);

I get a return value of 1231 (Network Location cannot be reached) no matter if I use an IP address or a NetBIOS name of a machine that’s undoubtedly online, or even my own. On edit: this happens even if I don’t put a “\\” in front of the hostname.

I’m doing things wrong, I know, and let’s not even get started on how to declare that blasted return buffer (which can have a number of different lengths, ewww).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:55:03+00:00Added an answer on May 12, 2026 at 10:55 pm

    From pinvoke.net (they also have some sample code on how to use it):

       [DllImport("netapi32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
        static extern uint NetUserModalsGet(
            string server,
            int level,
            out IntPtr BufPtr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: Yet another followup at https://stackoverflow.com/questions/1799742/shouldnt-netusermodalsget-tell-me-what-domain-a-machine-is-part-of-and-where Thanks to Gonzalo's help, I'm able to use
EDIT: This is a followup to SSE2 Compiler Error This is the real bug
This is a followup question to my question , that was left unanswered EDIT
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
EDIT : It turned out that this can only be done through an external
this is followup to this question : Assigning 1 line of a txt file
This is a followup to: MySQL - Is it possible to get all sub-items
This is a followup to my question here . I would like to understand
This is a followup of this question in the following code, why does line
This is a followup question to PHP: if more than ..px resize to As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.