Click here to Skip to main content
15,789,840 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Getting a memory corruption error on this:

Here's the documentation I'm trying to translate to C#:
NET_API_STATUS  NetEnumerateComputerNames(
  __in_opt  LPCWSTR Server,
  __in      NET_COMPUTER_NAME_TYPE NameType,
  __in      ULONG Reserved,
  __out     PDWORD EntryCount,
  __out     LPWSTR **ComputerNames

[DllImport("Netapi32.dll", SetLastError = true)]
        public static extern int NetEnumerateComputerNames(
            string server_name,
            NET_COMPUTER_NAME_TYPE name_type,
            ulong reserved,
            out int entry_count,
            out IntPtr computer_names

public static void GetRemoteSystemInformation(string host, ref string computer_name, ref string system_os)
            computer_name = "";
            system_os = "Unknown";
            int entry_count;
            IntPtr p_computer_names;
            var ret = PInvoke.NetEnumerateComputerNames(host, (int)NET_COMPUTER_NAME_TYPE.NET_PRIMARY_COMPUTER_NAME, 0, out entry_count, out p_computer_names);
            if (PInvoke.ERROR_SUCCESS == ret)

[edit]Code blocks, link linkified - OriginalGriff[/edit]
Updated 9-Jun-11 10:21am
[no name] 9-Jun-11 15:54pm    
Are you by any chance compiling on a 64bit computer for any cpu? In that case change the platform to x86.
[no name] 9-Jun-11 16:05pm    
Platform target is x86 in both debug and release.
voloda2 10-Jun-11 5:48am    
How is your NET_COMPUTER_NAME_TYPE structure defined?

1 solution

Rebuilt entire solution. Started working.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900