1# @ohos.enterprise.deviceControl (Device Control)
2
3The **deviceControl** module provides APIs for device control.
4
5> **NOTE**
6>
7> 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.
8>
9> The APIs of this module can be used only in the stage model.
10>
11> The APIs of this module can be called only by a [device administrator application](../../mdm/mdm-kit-guide.md#introduction) that is enabled.
12
13## Modules to Import
14
15```ts
16import { deviceControl } from '@kit.MDMKit';
17```
18
19## deviceControl.operateDevice
20
21operateDevice(admin: Want, operate: string, addition?: string): void
22
23Allows the specified device administrator application to operate devices.
24
25**Required permissions**: ohos.permission.ENTERPRISE_OPERATE_DEVICE
26
27**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
28
29
30**Parameters**
31
32| Name  | Type                                                   | Mandatory| Description                                                        |
33| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
34| admin    | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes  | Device administrator application.                                              |
35| operate  | string                                                  | Yes  | Operation to be performed, which can be any of the following:<br>- **resetFactory**: restore device factory settings.<br>- **reboot**: restart devices.<br>- **shutDown**: shut down devices.<br>- **lockScreen**: lock device screens.<!--RP1--><!--RP1End-->|
36| addition | string                                                  | No  | <!--RP2-->Additional parameter for the operation. Currently, this parameter does not need to be passed in.<!--RP2End-->       |
37
38**Error codes**
39
40For details about the error codes, see [Enterprise Device Management Error Codes](errorcode-enterpriseDeviceManager.md) and [Universal Error Codes](../errorcode-universal.md).
41
42| ID| Error Message                                                    |
43| -------- | ------------------------------------------------------------ |
44| 9200001  | The application is not an administrator application of the device. |
45| 9200002  | The administrator application does not have permission to manage the device. |
46| 201      | Permission verification failed. The application does not have the permission required to call the API. |
47| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
48
49**Example**
50
51```ts
52import { deviceControl } from '@kit.MDMKit';
53import { Want } from '@kit.AbilityKit';
54
55let wantTemp: Want = {
56  bundleName: 'com.example.myapplication',
57  abilityName: 'EntryAbility',
58};
59
60try {
61  deviceControl.operateDevice(wantTemp, 'resetFactory');
62} catch (err) {
63  console.error(`Failed to reset factory. Code is ${err.code}, message is ${err.message}`);
64}
65```
66