Using VBScript
Using VBScript
The following VBScript code illustrates how to enumerate the PosDevice class instances, add a device, and add a name to that device.
'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='Msr Simulator'")
objSO.AddDevice "COM1"
Set objDevice = objServices.Get("PosDevice.SoName='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(25-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
The following output results from running the VBScript shown above:
Enumerating PosDevice...
CashDrawer CashDrawer Simulator ENABLED
CheckScanner CheckScanner Simulator ENABLED
LineDisplay LineDisplay Simulator ENABLED
Msr Msr Simulator ENABLED
PinPad PinPad Simulator ENABLED
PosKeyboard PosKeyboard Simulator ENABLED
PosPrinter PosPrinter Simulator ENABLED
Scanner Scanner Simulator ENABLED
Msr ExampleMsr ENABLED
Scanner Example Scanner ENABLED
Add Device on COM1 and add name 'MSRSim' for MsrSimulator ...
Added 'MSRSim' to: Msr Msr Simulator COM1