# @ohos.enterprise.applicationManager (Application Management) The **applicationManager** module provides application management capabilities, including adding, removing, and obtaining the applications that are forbidden to run. > **NOTE** > > - The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. > > - The APIs of this module can be used only in the stage model. > > - The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is enabled. > ## Modules to Import ```ts import { applicationManager } from '@kit.MDMKit'; ``` ## applicationManager.addDisallowedRunningBundlesSync addDisallowedRunningBundlesSync(admin: Want, appIds: Array\, accountId?: number): void Adds the applications that are not allowed to run by the current or specified user through the specified device administrator application. **Required permissions**: ohos.permission.ENTERPRISE_MANAGE_APPLICATION **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | | appIds | Array<string> | Yes | IDs of the applications to add. | | accountId | number | No | User ID, which must be greater than or equal to 0.
- If **accountId** is passed in, this API applies to the specified user.
- If **accountId** is not passed in, this API applies to the current user.| **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device. | | 201 | Permission verification failed. The application does not have the permission required to call the API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts import { Want } from '@kit.AbilityKit'; let wantTemp: Want = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; let appIds: Array = ['com.example.myapplication']; try { applicationManager.addDisallowedRunningBundlesSync(wantTemp, appIds); console.info('Succeeded in adding disallowed running bundles.'); } catch (err) { console.error(`Failed to add disallowed running bundles. Code is ${err.code}, message is ${err.message}`); } ``` ## applicationManager.removeDisallowedRunningBundlesSync removeDisallowedRunningBundlesSync(admin: Want, appIds: Array\, accountId?: number): void Removes the applications that cannot be run by the current or specified user through the specified device administrator application. **Required permissions**: ohos.permission.ENTERPRISE_MANAGE_APPLICATION **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | | appIds | Array<string> | Yes | IDs of the applications to remove. | | accountId | number | No | User ID, which must be greater than or equal to 0.
- If **accountId** is passed in, this API applies to the specified user.
- If **accountId** is not passed in, this API applies to the current user.| **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device. | | 201 | Permission verification failed. The application does not have the permission required to call the API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts import { Want } from '@kit.AbilityKit'; let wantTemp: Want = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; let appIds: Array = ['com.example.myapplication']; try { applicationManager.removeDisallowedRunningBundlesSync(wantTemp, appIds); console.info('Succeeded in removing disallowed running bundles.'); } catch (err) { console.error(`Failed to remove disallowed running bundles. Code is ${err.code}, message is ${err.message}`); } ``` ## applicationManager.getDisallowedRunningBundlesSync getDisallowedRunningBundlesSync(admin: Want, accountId?: number): Array<string> Obtains the applications that are not allowed to run by the current user through the specified device administrator application. **Required permissions**: ohos.permission.ENTERPRISE_MANAGE_APPLICATION **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **Parameters** | Name | Type | Mandatory| Description | | --------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | | accountId | number | No | User ID, which must be greater than or equal to 0.
- If **accountId** is passed in, this API applies to the specified user.
- If **accountId** is not passed in, this API applies to the current user.| **Return value** | Type | Description | | ------------------- | -------------------------------- | | Array<string> | Applications that are not allowed to run by the current user.| **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device. | | 201 | Permission verification failed. The application does not have the permission required to call the API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts import { Want } from '@kit.AbilityKit'; let wantTemp: Want = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; try { let result: Array = applicationManager.getDisallowedRunningBundlesSync(wantTemp) console.info(`Succeeded in getting disallowed running bundles, result : ${JSON.stringify(result)}`); } catch (err) { console.error(`Failed to get disallowed running bundles. Code is ${err.code}, message is ${err.message}`); } ``` ## applicationManager.addAutoStartApps addAutoStartApps(admin: Want, autoStartApps: Array\): void Adds the auto-start applications (applications that automatically run at system startup) through the specified device administrator application. This API returns the result synchronously. Currently, this capability supports only 2-in-1 devices. **Required permissions**: ohos.permission.ENTERPRISE_MANAGE_APPLICATION **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **Parameters** | Name | Type | Mandatory| Description | | ------------- | ------------------------------------------------------------ | ---- | -------------------------------------- | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | | autoStartApps | Array\<[Want](../apis-ability-kit/js-apis-app-ability-want.md)> | Yes | Auto-start applications to add. A maximum of 10 applications can be added at a time.| **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device. | | 201 | Permission verification failed. The application does not have the permission required to call the API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts import { Want } from '@kit.AbilityKit'; let wantTemp: Want = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; let autoStartApps: Array = [ { bundleName: 'com.example.autoStartApplication', abilityName: 'EntryAbility', } ]; try { applicationManager.addAutoStartApps(wantTemp, autoStartApps); console.info(`Succeeded in adding auto start applications.`); } catch(err) { console.error(`Failed to add auto start applications. Code: ${err.code}, message: ${err.message}`); } ``` ## applicationManager.removeAutoStartApps removeAutoStartApps(admin: Want, autoStartApps: Array\): void Removes the auto-start applications through the specified device administrator application. This API returns the result synchronously. Currently, this capability supports only 2-in-1 devices. **Required permissions**: ohos.permission.ENTERPRISE_MANAGE_APPLICATION **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **Parameters** | Name | Type | Mandatory| Description | | ------------- | ------------------------------------------------------------ | ---- | ---------------- | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application. | | autoStartApps | Array\<[Want](../apis-ability-kit/js-apis-app-ability-want.md)> | Yes | Auto-start applications to remove.| **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device. | | 201 | Permission verification failed. The application does not have the permission required to call the API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts import { Want } from '@kit.AbilityKit'; let wantTemp: Want = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; let autoStartApps: Array = [ { bundleName: 'com.example.autoStartApplication', abilityName: 'EntryAbility', } ]; try { applicationManager.removeAutoStartApps(wantTemp, autoStartApps); console.info(`Succeeded in removing auto start applications.`); } catch(err) { console.error(`Failed to remove auto start applications. Code: ${err.code}, message: ${err.message}`); } ``` ## applicationManager.getAutoStartApps getAutoStartApps(admin: Want): Array\ Obtains the auto-start applications through the specified device administrator application. This API returns the result synchronously. Currently, this capability supports only 2-in-1 devices. **Required permissions**: ohos.permission.ENTERPRISE_MANAGE_APPLICATION **System capability**: SystemCapability.Customization.EnterpriseDeviceManager **Parameters** | Name| Type | Mandatory| Description | | ------ | ------------------------------------------------------- | ---- | -------------- | | admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes | Device administrator application.| **Return value** | Type | Description | | ------------------------------------------------------------ | -------------------- | | Array\<[Want](../apis-ability-kit/js-apis-app-ability-want.md)> | List of the auto-start applications obtained.| **Error codes** For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md). | ID| Error Message | | -------- | ------------------------------------------------------------ | | 9200001 | The application is not an administrator application of the device. | | 9200002 | The administrator application does not have permission to manage the device. | | 201 | Permission verification failed. The application does not have the permission required to call the API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **Example** ```ts import { Want } from '@kit.AbilityKit'; let wantTemp: Want = { bundleName: 'com.example.myapplication', abilityName: 'EntryAbility', }; try { let res: Array = applicationManager.getAutoStartApps(wantTemp); console.info(`Succeeded in adding auto start apps: ${JSON.stringify(res)}`); } catch(err) { console.error(`Failed to auto start apps. Code: ${err.code}, message: ${err.message}`); } ```