• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.enterprise.accountManager (Account Management)
2
3The **accountManager** module provides APIs for account management of enterprise devices.
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> - The APIs of this module can be used only in the stage model.
10>
11> - The APIs provided by this module can be called only by a [device administrator application](enterpriseDeviceManagement-overview.md#basic-concepts) that is [enabled](js-apis-enterprise-adminManager.md#adminmanagerenableadmin).
12
13## Modules to Import
14
15```ts
16import accountManager from '@ohos.enterprise.accountManager';
17```
18
19## accountManager.disallowAddLocalAccount
20
21disallowAddLocalAccount(admin: Want, disallow: boolean, callback: AsyncCallback<void>): void
22
23Disallows a device administrator application to create local user accounts. This API uses an asynchronous callback to return the result.
24
25**Required permissions**: ohos.permission.ENTERPRISE_SET_ACCOUNT_POLICY
26
27**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
28
29**System API**: This is a system API.
30
31**Parameters**
32
33| Name     | Type                                      | Mandatory  | Description                      |
34| -------- | ---------------------------------------- | ---- | ------------------------------- |
35| admin    | [Want](js-apis-app-ability-want.md)     | Yes   | Device administrator application.                 |
36| disallow    | boolean     | Yes   | Whether to forbid the creation of local user accounts. The value **true** means to disallow the creation of local user accounts, and the value **false** means the opposite.                 |
37| callback | AsyncCallback<void>            | Yes   | Callback invoked to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.      |
38
39**Error codes**
40
41For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
42
43| ID| Error Message                                                                      |
44| ------- | ---------------------------------------------------------------------------- |
45| 9200001 | The application is not an administrator application of the device.                       |
46| 9200002 | The administrator application does not have permission to manage the device.|
47
48**Example**
49
50```ts
51import Want from '@ohos.app.ability.Want';
52let wantTemp: Want = {
53  bundleName: 'com.example.myapplication',
54  abilityName: 'EntryAbility',
55};
56
57accountManager.disallowAddLocalAccount(wantTemp, true, (err) => {
58  if (err) {
59    console.error(`Failed to disallow add local account. Code: ${err.code}, message: ${err.message}`);
60    return;
61  }
62  console.info('Succeeded in disallowing add local account');
63});
64```
65
66## accountManager.disallowAddLocalAccount
67
68disallowAddLocalAccount(admin: Want, disallow: boolean): Promise<void>
69
70Disallows a device administrator application to create local user accounts. This API uses a promise to return the result.
71
72**Required permissions**: ohos.permission.ENTERPRISE_SET_ACCOUNT_POLICY
73
74**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
75
76**System API**: This is a system API.
77
78**Parameters**
79
80| Name  | Type                                 | Mandatory  | Description     |
81| ----- | ----------------------------------- | ---- | ------- |
82| admin | [Want](js-apis-app-ability-want.md) | Yes   | Device administrator application.|
83| disallow    | boolean     | Yes   | Whether to forbid the creation of local user accounts. The value **true** means to disallow the creation of local user accounts, and the value **false** means the opposite.                 |
84
85**Return value**
86
87| Type                  | Description                     |
88| --------------------- | ------------------------- |
89| Promise<void> | Promise that returns no value. If the operation fails, an error object will be thrown.|
90
91**Error codes**
92
93For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
94
95| ID| Error Message                                                                    |
96| ------- | ---------------------------------------------------------------------------- |
97| 9200001 | The application is not an administrator application of the device.                       |
98| 9200002 | The administrator application does not have permission to manage the device.|
99
100**Example**
101
102```ts
103import Want from '@ohos.app.ability.Want';
104import { BusinessError } from '@ohos.base';
105let wantTemp: Want = {
106  bundleName: 'com.example.myapplication',
107  abilityName: 'EntryAbility',
108};
109
110accountManager.disallowAddLocalAccount(wantTemp, true).then(() => {
111  console.info('Succeeded in disallowing add local account');
112}).catch((err: BusinessError) => {
113  console.error(`Failed to disallow add local account. Code: ${err.code}, message: ${err.message}`);
114});
115```
116