Get unique identifier of a mouse - mouse

When I check the hardware ID of my mouse in the device manager, it outputs HID\VID_15D9&PID_0A4C&REV_0100. The same ID is given for a different mouse of the same brand on another PC.
However, I want to have a unique identifier for each mouse, because I'm doing an inventory of laboratory equipment, and I have to audit hardware components of the lab.
I've used VBS and made use of WMIC commands. So far, I've tried this code to get the device ID of the mouse:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PointingDevice")
Wscript.Echo "Device ID: " & objItem.DeviceID
How can I get a unique ID for each device?

Related

Different Script (SAP GUI) Codes for the same process in two different computers

I want to automate some operations for my works so I record a Script on SAP GUI(SAP LOGON PAD 720), then use it to create a excel macro and it works perfectly on my computer, but when I try to run it in other computers, it doesn't work at all and when I record the same process in other PC's the Script's code is different than that one which appeared in my PC. I want to know how this can be possible, how can I change the "code form" or "code language" on my PC so when I record a script it can be used on every computer.
This is the Script from my PC
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "vl03n"
session.findById("wnd[0]").sendVKey 0
'This is the script I recorded from my computer,in other pc this "LIKP-VBELN" doesnt appear
session.findById("wnd[0]/usr/ctxtLIKP-VBELN").text = "8105148724"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[7]").press
And this is if I record the same process from others PC's
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "vl03n"
session.findById("wnd[0]").sendVKey 0
'here is when the error begin "LIKP-VBELN" doesnt appear anymore so that is why the macro doesnt work
session.findById("wnd[0]/usr/ctxt").text = "8105148724"
session.findById("wnd[0]/usr/ctxt").caretPosition = 10
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[7]").press
Check the LAN connection for the client and ensure its set to High Speed.
Regards,
ScriptMan

Applescript to rule "sent mailbox zero"?

According to GTD and "inbox zero" I also wanted a corresponding "sent mailbox zero" by applying a rule in Apple Mail. (Why? Please, see the end of this question.)
Now, here is a simple Applescript solution: sortOut. How could it be more efficient?
The workflow is simply this
Loop through all sent messages that was a reply to some other message.
Get the message id of the message the sent message was a reply to.
Locate the mailbox for this (prior) message.
Any suggestions how to solve step 3 more efficiently will be appreciated, e.g. locating a mailbox directly based on message id, without having to use the message: protocol and then open the message and preferably not to code something like ... (in every mailbox) whose message id is mID which turns out to be rather slow.
tell application "Mail"
set i to 0
set mb1 to sent mailbox
repeat with m in ((messages of mb1) whose all headers contains "In-Reply-To")
set mID to content of header "In-Reply-To" of m
set cmd to "open 'message:" & mID & "'"
try
do shell script cmd
delay 1
set s to the selection
set m2 to item 1 of s
set mb2 to mailbox of m2
set mailbox of m to mb2
close front window
set i to i + 1
end try
end repeat
if i ≠ 1 then
set s to "s"
else
set s to ""
end if
set myMsg to (i & " message" & s & " moved successfully") as rich text
display notification myMsg with title "SortOut" subtitle "Sorting complete"
end tell
Some earlier discussions elsewhere indicate that some people may even wonder why I want this. My reason is simply that I like to have have all threads and conversations, concerning every project and deadline, collected together based on context.
When a project is finished I archive it as a completed entity for easy reference if I need to go back or follow up some things (e.g. when planning a yearly event, “Remember what I replied to this question last year?” That also means that all those conversations will have the same label in gmail.
So, instead of having almost 15000 sent emails in one mailbox, I now have them sorted into context based mailboxes—and the mailbox for sent messages is empty!
BTW, the Alfred workflow Mail Actions by Pedro Lobo is simply amazing for filing mail. My script sortOut does the rest ;-)
Sorry, Pedro, I didn't have enough reputation to post a link to your brilliant work.
I just updated the code but still could not locate the mailbox corresponding to a message id from the In-Reply-To header using Applescript (without the message:protocol).
tell application "Mail"
set i to 0
set mb1 to sent mailbox
repeat with m in ((messages of mb1) whose all headers contains "In-Reply-To")
set mID to content of header "In-Reply-To" of m
set cmd to "open 'message:" & mID & "'"
try
do shell script cmd
delay 1
set s to the selection
set m2 to last item of s
set mb2 to mailbox of m2
if name of mb2 does not contain "INBOX" then
set mailbox of m to mb2
close front window
set i to i + 1
end if
end try
end repeat
if i ≠ 1 then
set s to "s"
else
set s to ""
end if
set myMsg to (i & " message" & s & " moved successfully") as rich text
display notification myMsg with title "SortOut" subtitle "Sorting complete"
mb2
end tell

How to retrieve 'bus reported device description' for Universal Serial Bus Controllers in MATLAB?

I am trying to extract 'Bus reported device description' and 'Bus Relations' informations for Universal Serial Bus Controllers in Matlab.
I can't find it in the registry and I don't know exactly how to use setupapi.dll function in Matlab to get the informations.
I want to do this because I have a plurality of Arduino Nano devices and all of them have different COMs.
I also use other USB Serial Devices under Matlab and for all of them I must create different serial objects, with different COM port names.
I want to create a Matlab function which will return what devices are connected on USB ports and what COM port they use .
I hope someone can help me with some ideas or code examples.
Thanks in advance!
This is a very late answer, but I also run into this problem and I have found a solution to find the "Bus reported device description" after searching on the Internet. I do not need "Bus Relations" in my case but I guess it may be retrieved in a similar way. I am using Windows 10 21H1 and MATLAB R2021a.
In short, my solution has 4 steps:
Find all the active COM port devices.
Find the friendly names of all devices.
Based on 1 and 2, get the friendly names of all active COM port devices.
Based on 3, get the "Bus reported device description" of all active COM port devices.
Code:
% To improve speed (x10) add jsystem to the path from here:
% https://github.com/avivrosenberg/matlab-jsystem/blob/master/src/jsystem.m
if exist('jsystem','file')
fsystem = #jsystem;
else
fsystem = #system;
end
% Find all the active COM ports
com = 'REG QUERY HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM';
[err,str] = fsystem(com);
if err
error('Error when executing the system command "%s"',com);
end
% Find the friendly names of all devices
ports = regexp(str,'\\Device\\(?<type>[^ ]*) *REG_SZ *(?<port>COM\d+)','names','dotexceptnewline');
cmd = 'REG QUERY HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\ /s /f "FriendlyName" /t "REG_SZ"';
[~,str] = fsystem(cmd); % 'noshell'
% Get the friendly names of all active COM port devices
names = regexp(str,'FriendlyName *REG_SZ *(?<name>.*?) \((?<port>COM\d+)\)','names','dotexceptnewline');
[i,j] = ismember({ports.port},{names.port});
[ports(i).name] = names(j(i)).name;
% Get the "Bus reported device description" of all active COM port devices
for i = 1:length(ports)
cmd = sprintf('powershell -command "(Get-WMIObject Win32_PnPEntity | where {$_.name -match ''(%s)''}).GetDeviceProperties(''DEVPKEY_Device_BusReportedDeviceDesc'').DeviceProperties.Data"',ports(i).port);
[~,ports(i).USBDescriptorName] = fsystem(cmd);
end
This solution works but may not be clean. I am not a Windows expert anyway. Suggestions are highly appreciated.

applescript to save email-attachments in a folder doesn't work in Yosemite

I've installed OS x 10.10.1
Now this script doesn't work:
tell application "Mail"
set theSelectedMessages to selection
set this_message to item 1 of the theSelectedMessages
tell this_message
set these_attachments to every mail attachment
repeat with z from 1 to the count of these_attachments
set this_attachment to item z of these_attachments
set this_name to the name of this_attachment as text
.........and so on
I get the message : error in the apple event Routine. The error comes in this line: "set these_attachments to every mail attachment"
In 10.9 the script worked.
WoWo
woide#wwp-service.de
G'day from the land of Oz
Your code, slightly modified, works. I think your use of 'selection' might be faulty, but haven't test it. Try 'selected mailbox'.
Regards
Brian Christmas
tell application "Mail"
set theSelectedMessages to messages of mailbox "* items to shift"
set this_message to item 1 of the theSelectedMessages
tell this_message
set these_attachments to every mail attachment
set AttachmentNames to {}
repeat with z from 1 to the count of these_attachments
set this_attachment to item z of these_attachments
set this_name to the name of this_attachment as rich text
set end of AttachmentNames to this_name as rich text
end repeat
end tell
end tell
AttachmentNames & return & z
--> {"2014-11-10 233839Z.zip", "2014-11-10 233839Z.zip", "(20141110233839Z 2).pdf", "2014-11-10 233839Z", "
", 4}

Mail "Can't continue" for a AppleScript function

I'm trying to write an AppleScript for use with Mail (on Snow Leopard) to save image attachments of messages to a folder. The main part of the AppleScript is:
property ImageExtensionList : {"jpg", "jpeg"}
property PicturesFolder : path to pictures folder as text
property SaveFolderName : "Fetched"
property SaveFolder : PicturesFolder & SaveFolderName
tell application "Mail"
set theMessages to the selection
repeat with theMessage in theMessages
repeat with theAttachment in every mail attachment of theMessage
set attachmentFileName to theAttachment's name
if isImageFileName(attachmentFileName) then
set attachmentPathName to SaveFolder & attachmentFileName
save theAttachment in getNonexistantFile(attachmentPathName)
end if
end repeat
end repeat
end tell
on isImageFileName(theFileName)
set dot to offset of "." in theFileName
if dot > 0 then
set theExtension to text (dot + 1) thru -1 of theFileName
return theExtension is in ImageExtensionList
end if
return false
end isImageFileName
When run, I get the error:
error "Mail got an error: Can’t continue isImageFileName." number -1708
where error -1708 is:
Event wasnt handled by an Apple event handler.
However, if I copy/paste the isImageFileName() into another script like:
property ImageExtensionList : {"jpg", "jpeg"}
on isImageFileName(theFileName)
set dot to offset of "." in theFileName
if dot > 0 then
set theExtension to text (dot + 1) thru -1 of theFileName
return theExtension is in ImageExtensionList
end if
return false
end isImageFileName
if isImageFileName("foo.jpg") then
return true
else
return false
end if
it works fine. Why does Mail complain about this?
It may be a quirk, but it has an explanation. If you're in a tell application "whatever" block, all calls are made in the namespace of that application's dictionary, not your script's dictionary. Because of that, you have to explicity tell AppleScript to look back into your script for the name. Saying my is like saying tell me, instructing the script where to look for the function.
Try "my isImageFileName". It's not Mail, just a quirk of AppleScript.