1# @ohos.enterprise.deviceControl(设备控制管理) 2 3本模块提供设备控制能力。 4 5> **说明**: 6> 7> 本模块首批接口从API version 12 开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 9> 本模块接口仅可在Stage模型下使用。 10> 11> 本模块接口仅对[设备管理应用](../../mdm/mdm-kit-guide.md#功能介绍)开放,需将设备管理应用激活后调用,实现相应功能。 12 13## 导入模块 14 15```ts 16import { deviceControl } from '@kit.MDMKit'; 17``` 18 19## deviceControl.operateDevice 20 21operateDevice(admin: Want, operate: string, addition?: string): void 22 23允许管理员操作设备。 24 25**需要权限:** ohos.permission.ENTERPRISE_OPERATE_DEVICE 26 27**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager 28 29 30**参数:** 31 32| 参数名 | 类型 | 必填 | 说明 | 33| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 34| admin | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 设备管理应用。 | 35| operate | string | 是 | 要执行的操作。<br/>- resetFactory:设备恢复出厂设置。<br/>- reboot:设备重启。<br/>- shutDown:设备关机。<br/>- lockScreen:设备屏幕锁定。 <!--RP1--><!--RP1End-->| 36| addition | string | 否 | <!--RP2-->执行时附加参数。目前无需传入。<!--RP2End--> | 37 38**错误码:** 39 40以下错误码的详细介绍请参见[企业设备管理错误码](errorcode-enterpriseDeviceManager.md)和[通用错误码](../errorcode-universal.md)。 41 42| 错误码ID | 错误信息 | 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**示例:** 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