# netuseadd

### C# Signature:

```cs
using BOOL = System.Boolean;
using DWORD = System.UInt32;
using LPWSTR = System.String;
using NET_API_STATUS = System.UInt32;

[DllImport("NetApi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern NET_API_STATUS NetUseAdd(
     LPWSTR UncServerName,
     DWORD Level,
     ref Structures.USE_INFO_2 Buf,
     out DWORD ParmError);
```

### User-Defined Types:

```cs
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct USE_INFO_2
{
     internal LPWSTR ui2_local;
     internal LPWSTR ui2_remote;
     internal LPWSTR ui2_password;
     internal DWORD  ui2_status;
     internal DWORD  ui2_asg_type;
     internal DWORD  ui2_refcount;
     internal DWORD  ui2_usecount;
     internal LPWSTR ui2_username;
     internal LPWSTR ui2_domainname;
}
```

### Sample Code:

```cs
USE_INFO_2 useInfo    = new USE_INFO_2();
useInfo.ui2_local     = "E:";
useInfo.ui2_remote    = @"\\machine\share";
useInfo.ui2_password  = "password";
useInfo.ui2_asg_type  = 0;    //disk drive
useInfo.ui2_usecount  = 1;
useInfo.ui2_username  = "user";
useInfo.ui2_domainname= "domain"; 

uint paramErrorIndex;
uint returnCode = NetUseAdd(null, 2, ref useInfo, out paramErrorIndex);
if (returnCode != 0)
{
      throw new Win32Exception((int)returnCode);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pinvokeisalive.gitbook.io/pinvoke/desktopfunctions/netapi32/netuseadd.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
