Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have app / executable file paths and I want to get the friendly app name from them. Imagine a getAppName function like this:

const result = getAppName('C:\Program Files\Mozilla Firefox\firefox.exe');
console.log(result); // Firefox

For example, on Windows, if you right click the app and click "Properties", you can see this name in General > Description and Details > File Description;

The "General" tab of Google Chrome's Properties

The "Details" tab of Google Chrome's Properties

I've had no luck looking for npm packages, system commands, etc. In the end, I need a solution for Linux, Mac, and Windows. Ideally there's a way via a built-in Node.js package or something on npm, but I might have to cobble together a solution usibe three OS-specific system commands I execute from Node.js.

I found WMIC (in How to check file properties through WMI command line) for Windows but I can't quite get what I want out of it;

wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe" get Description

Description
C:Program FilesMozilla Firefoxfirefox.exe
wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe" get Name

Name
C:Program FilesMozilla Firefoxfirefox.exe
wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe" get File Description

Invalid GET Expression.
wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe" get File Name

Invalid GET Expression.
wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe" get FileName

FileName
firefox
wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe" get FileDescription

Node - XPS
ERROR:
Description = Invalid query
wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe" get ProductName

Node - XPS
ERROR:
Description = Invalid query
wmic datafile where name="C:\Program Files\Mozilla Firefox\firefox.exe"

AccessMask  Archive  Caption                                       Compressed  CompressionMethod  CreationClassName  CreationDate               CSCreationClassName   CSName  Description                                   Drive  EightDotThreeFileName                         Encrypted  EncryptionMethod  Extension  FileName  FileSize  FileType     FSCreationClassName  FSName  Hidden  InstallDate                InUseCount  LastAccessed               LastModified               Manufacturer         Name                                          Path                             Readable  Status  System  Version      Writeable
1179817     TRUE     C:Program FilesMozilla Firefoxfirefox.exe  FALSE                          CIM_LogicalFile    20190906213704.287820+060  Win32_ComputerSystem  XPS     C:Program FilesMozilla Firefoxfirefox.exe  c:     c:program filesmozilla firefoxfirefox.exe  FALSE                        exe        firefox   576032    Application  Win32_FileSystem     NTFS    FALSE   20190906213704.287820+060              20190907195815.492271+060  20190906213710.011611+060  Mozilla Corporation  C:Program FilesMozilla Firefoxfirefox.exe  program filesmozilla firefox  TRUE      OK      FALSE   69.0.0.7178  TRUE
C:Usersadaml>wmic datafile where name="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" get "file system name"

FSName
NTFS
C:Usersadaml>wmic datafile where name="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" get "file system class name"

FSCreationClassName
Win32_FileSystem

I don't want to do anything like take the extension-less filename and capitalize the first character. I want the accurate/real name which is shown to users.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
263 views
Welcome To Ask or Share your Answers For Others

1 Answer

I'm not sure this covers everything but it's the best I've gotten so far. The exiftool-vendored package allows you to get a ProductName "tag" which is what I'm looking for;

const exiftool = require('exiftool-vendored').exiftool;

exiftool
  .read('C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')
  .then(tags =>
    console.log(tags.ProductName))
  .catch(err => console.error('Something terrible happened: ', err));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...