Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

NetValidateName (netapi32)
 
.
Summary
Validate if a name is in a valid format and if its in use.

C# Signature:

[DllImport("netapi32.dll", SetLastError=true,CharSet=CharSet.Unicode)]
static extern UInt32 NetValidateName(string lpServer,string lpName, string lpAccount,string lpPassword, int NameType);

static extern UInt32 NetValidateName(string lpServer,string lpName, string lpAccount,string lpPassword, NET_SETUP_NAMETYPE NameType);

VB Signature:

Powershell:

Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;

public class NetworkUtil
{
    [DllImport("Netapi32.dll",CharSet=CharSet.Unicode)]
    public static extern UInt32 NetValidateName(string lpServer,string lpName,string lpAccount,string lpPassword,
    int NameType);
}

User-Defined Types:

ENUM NET_SETUP_NAMETYPE{
NetSetupUnknown,
NetSetupMachine,
NetSetupWorkgroup,
NetSetupDomain,
NetSetupNonExistentDomain,
NetSetupDnsMachine}

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

Most useful NameType's are 1 and 3 which will allow you to see if the name is in use.

Tips & Tricks:

Please add some!

Sample Code:

using System;

using System.Runtime.InteropServices;



public class NetworkUtil

{

    [DllImport("Netapi32.dll",SetLastError=true,CharSet=CharSet.Unicode)]

    public static extern UInt32 NetValidateName(string lpServer,string lpName, string lpAccount,string lpPassword, int NameType);




    static void Main()

    {

    UInt32 rtn = NetValidateName(null, "jrich523.wordpress.com", null, null, 3);

    Console.WriteLine(rtn);

    Console.ReadKey();

    }

}

POWERSHELL Code Example:

Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;

public class NetworkUtil
{
    [DllImport("Netapi32.dll",CharSet=CharSet.Unicode)]
    public static extern UInt32 NetValidateName(string lpServer,string lpName,string lpAccount,string lpPassword,
    int NameType);
}
"@

Function Test-NetBIOSName{

param([string] $Name, [int] $NameType)
[NetworkUtil]::NetValidateName($null,$name,$null,$null,$NameType)
}


#TEST

Test-NetBIOSName “myserver” 1

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions