이 섹션에 설명된 WMI API를 사용하여 관리 코드 또는 스크립팅을 사용하여 디바이스를 관리할 수 있습니다. POSDM.EXE는 이 API에 대한 명령줄 인터페이스입니다. 이 VBScript 샘플은 다음을 수행합니다.
WMI 메서드 ExecQuery를 사용하여 설치된 PosDevice 개체 목록을 검색합니다. 이 스크립트는 서비스 개체 목록을 사용하여 해당 형식, 이름, 해당 경로와 사용 또는 사용 안 함 상태를 표시합니다. 이것은 다음 명령을 실행하는 것과 유사합니다.
PosDM.exe LISTDEVICES그런 다음, AddDevice 메서드를 사용하여 COM1 경로를 설치된 서비스 개체 Microsoft Msr 시뮬레이터에 할당하려고 합니다. 이것은 다음을 실행하는 것과 같습니다.
PosDM.exe ADDDEVICE COM1 /SONAME:Microsoft Msr SimulatorAddDevice 메서드가 실패하면 이 스크립트는 오류를 catch하고 COM1이 디바이스에 이미 추가되었을 수 있으므로 DeleteDevice를 호출하여 삭제를 시도한다고 가정합니다. 이것은 다음을 실행하는 것과 같습니다.
PosDM.exe DELETEDEVICE COM1AddDevice 메서드가 이전에 실패한 경우 이 스크립트는 AddDevice를 다시 호출하려고 시도합니다. 이 메서드가 실패하면 프로그램이 종료됩니다.
마지막으로, 샘플은 AddName을 호출하여 논리 이름 MSRSim을 이 서비스 개체에 추가하려고 시도합니다. 이것은 다음을 실행하는 것과 같습니다.
PosDM.exe ADDNAME MSRSim /SONAME:"Microsoft Msr Simulator"
다음을 실행하여 이 샘플의 결과를 볼 수 있습니다.
PosDM.exe LISTDEVICES
And
PosDM.exe LISTNAMES
이 샘플을 실행하려면
서비스 개체 Microsoft Msr 시뮬레이터는 SDK와 함께 설치되었습니다. 샘플을 실행하는 데 사용할 컴퓨터에 설치되어 있는지 확인합니다.
이 스크립트를 PosDMSample.vbs 파일에 복사합니다.
다음 명령줄로 스크립트를 실행합니다.
CScript //U PosDMSample.vbs
예
'Get a handle to the POS namespace service into 'objServices'.
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objServices = objLocator.ConnectServer(, "/root/MicrosoftPointOfService")
'List the POS devices.
EnumeratePosDevice
'Add a name: MSRSim for Msr Simulator by retrieving the SO and invoking AddDevice() then AddName()
WScript.Echo "Add Device on COM1 and add name 'MSRSim' for MsrSimulator ..."
Set objSO = objServices.Get("ServiceObject.Type='Msr',Name='Microsoft Msr Simulator'")
On Error Resume Next
objSO.AddDevice "COM1"
if Err.number <> 0 Then
WScript.Echo "AddDevice failed - it already is in use."
WScript.Echo "Try to delete the device..."
On Error Resume Next
objSO.DeleteDevice "COM1"
if Err.number <> 0 Then
WScript.Echo "DeleteDevice failed"
WScript.Quit 1
end if
WScript.Echo "DeleteDevice succeeded! Attempting AddDevice again..."
On Error Resume Next
objSO.AddDevice "COM1"
if Err.number <> 0 Then
WScript.Echo "AddDevice failed a second time - exiting"
WScript.Quit 2
end if
end if
Set objDevice = objServices.Get("PosDevice.SoName='Microsoft Msr Simulator',Type='Msr',Path='COM1'")
objDevice.AddName "MSRSim"
Set objDevice = GetDevice("Msr", "MSRSim")
WScript.Echo "Added 'MSRSim' to: " & objDevice.Type & vbTab & objDevice.SoName & vbTab & objDevice.Path
'Enumerate the sClass by name
Sub EnumeratePosDevice( )
sClass = "PosDevice"
WScript.Echo "Enumerating " & sClass & "..." & vbCrLf
Set collection = objServices.ExecQuery("SELECT * From " & sClass)
For Each obj In collection
Enabled = "DISABLED"
if obj.Enabled = true Then
Enabled = "ENABLED"
end If
WScript.Echo obj.Type & Space(15-len(obj.type)) & obj.SoName & Space(35-len(obj.SoName)) & Enabled & vbTab & obj.Path
Next
WScript.Echo vbCrLf
End Sub
'Return a PosDevice matching DeviceType and Name.
Function GetDevice( DeviceType, Name )
Set Logical = GetLogicalDevice( DeviceType, Name )
objectPath = "PosDevice.SoName='" & Logical.SoName & "',Type='" & DeviceType & "',Path='" & Logical.Path & "'"
Set GetDevice = objServices.Get(objectPath)
End Function
'Return a LogicalDevice matching DeviceType and Name.
Function GetLogicalDevice( DeviceType, Name )
Query = "SELECT * From LogicalDevice WHERE Type = '" & DeviceType & "' AND Name='" & Name & "'"
Set collection = objServices.ExecQuery( Query )
For Each obj In collection
Set GetLogicalDevice = obj
exit For
Next
End Function
COM1 경로가 디바이스에 할당되지 않은 경우 샘플은 이 코드와 유사한 출력을 생성합니다.
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
Enumerating PosDevice...
Msr Microsoft Msr Simulator ENABLED
Msr Microsoft Msr Simulator ENABLED COM1
Keylock Microsoft Keylock Simulator ENABLED
Scanner Microsoft Scanner Simulator ENABLED
CashDrawer Microsoft CashDrawer Simulator ENABLED
CheckScanner Microsoft CheckScanner Simulator ENABLED
LineDisplay Microsoft LineDisplay Simulator ENABLED
PinPad Microsoft PinPad Simulator ENABLED
PosPrinter Microsoft PosPrinter Simulator ENABLED
PosKeyboard Microsoft PosKeyboard Simulator ENABLED
Add Device on COM1 and add name 'MSRSim' for MsrSimulator ...
AddDevice failed - it already be in use.
Try to delete the device...
DeleteDevice succeeded! Attempting AddDevice again...
Added 'MSRSim' to: Msr Microsoft Msr Simulator
경로 COM1이 이미 사용 중이고 다른 오류가 발생하지 않은 경우 스크립트는 이 코드와 같은 출력을 생성합니다.
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
Enumerating PosDevice...
Msr Microsoft Msr Simulator ENABLED
Msr Microsoft Msr Simulator ENABLED COM1
Keylock Microsoft Keylock Simulator ENABLED
Scanner Microsoft Scanner Simulator ENABLED
CashDrawer Microsoft CashDrawer Simulator ENABLED
CheckScanner Microsoft CheckScanner Simulator ENABLED
LineDisplay Microsoft LineDisplay Simulator ENABLED
PinPad Microsoft PinPad Simulator ENABLED
PosPrinter Microsoft PosPrinter Simulator ENABLED
PosKeyboard Microsoft PosKeyboard Simulator ENABLED
Add Device on COM1 and add name 'MSRSim' for MsrSimulator ...
AddDevice failed - it already be in use.
Try to delete the device...
DeleteDevice succeeded! Attempting AddDevice again...
Added 'MSRSim' to: Msr Microsoft Msr Simulator
참고 항목
기타 리소스
.NET