# WinUser

Import: `import com.install4j.api.windows.WinUser;`

```java
public class WinUser
```

Collection of static methods to create or delete users and local groups on Windows.

If a helper process with elevated privileges has been created by the "Request privileges" action, the methods of
this class are pushed to the helper process. Please see the help topic on "Elevation Of Privileges" for more information.

| Type | Kind | Description |
|---|---|---|
## Nested types

| [WinUser.AddUserResult](WinUser.AddUserResult.md) | class | The class of the objects returned by [`WinUser.addUser`](WinUser.md#adduser-string-string-string-groupcreationmode-string-string). |
| [WinUser.AddUserResultType](WinUser.AddUserResultType.md) | enum | The type of result returned by [`WinUser.addUser`](WinUser.md#adduser-string-string-string-groupcreationmode-string-string) |
| [WinUser.GroupCreationMode](WinUser.GroupCreationMode.md) | enum | The group creation mode. |

## Methods

| Signature | Returns | Description |
|---|---|---|
| [`deleteUser(String)`](#deleteuser-string) | `boolean` | Delete a user. |
| [`deleteLocalGroup(String)`](#deletelocalgroup-string) | `boolean` | Delete a local group. |
| [`addUser(String, String, String, GroupCreationMode, String, String)`](#adduser-string-string-string-groupcreationmode-string-string) | `AddUserResult` | Add a user and optionally a local group. |
| [`getAccountName(String)`](#getaccountname-string) | `String` | Try to get an account name for a SID (Security Identifier). |
| [`getUserName(String)`](#getusername-string) | `String` | Try to get the user name (an unqualified account name) for a SID (Security Identifier). |
| [`getUserSid()`](#getusersid) | `String` | Get the user's SID (Security Identifier) of the current process. |

### deleteUser(String)

```java
public static boolean deleteUser(String nameOrSid)
```

Delete a user.


**Parameters:**

- `nameOrSid` — an account name or a SID in String form

**Returns:** `true` if successful or if the user doesn't exist

### deleteLocalGroup(String)

```java
public static boolean deleteLocalGroup(String nameOrSid)
```

Delete a local group.


**Parameters:**

- `nameOrSid` — an account name or a SID in String form

**Returns:** `true` if successful or if the local group doesn't exist

### addUser(String, String, String, GroupCreationMode, String, String)

```java
public static AddUserResult addUser(String name, String password, String comment, GroupCreationMode groupCreationMode, String localGroupNameOrSid, String localGroupComment)
```

Add a user and optionally a local group.


**Parameters:**

- `name` — the user name
- `password` — the password for the account
- `comment` — an optional comment. Can be `null`
- `groupCreationMode` — how the group should be created
- `localGroupNameOrSid` — a group name or optionally a SID if the group already exists. Can be `null` for `WinUser.GroupCreationMode#NONE`.
- `localGroupComment` — an optional comment for the local group. Can be `null`

**Returns:** the result of the operation

### getAccountName(String)

```java
public static String getAccountName(String sid)
```

Try to get an account name for a SID (Security Identifier).


**Parameters:**

- `sid` — the SID in String form

**Returns:** A qualified account name or `null` if the account could not be found.

### getUserName(String)

```java
public static String getUserName(String sid)
```

Try to get the user name (an unqualified account name) for a SID (Security Identifier).


**Parameters:**

- `sid` — the SID in String form

**Returns:** An unqualified account name or `null` if the account could not be found.

### getUserSid()

```java
public static String getUserSid()
```

Get the user's SID (Security Identifier) of the current process.


**Returns:** A SID in String form or `null` if the method fails.

## Constructors

| Signature | Description |
|---|---|
| [`WinUser()`](#winuser) |  |

### WinUser()

```java
public WinUser()
```

