-2

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 Files\Mozilla Firefox\firefox.exe
wmic datafile where name="C:\\Program Files\\Mozilla Firefox\\firefox.exe" get Name

Name
C:\Program Files\Mozilla Firefox\firefox.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 Files\Mozilla Firefox\firefox.exe  FALSE                          CIM_LogicalFile    20190906213704.287820+060  Win32_ComputerSystem  XPS     C:\Program Files\Mozilla Firefox\firefox.exe  c:     c:\program files\mozilla firefox\firefox.exe  FALSE                        exe        firefox   576032    Application  Win32_FileSystem     NTFS    FALSE   20190906213704.287820+060              20190907195815.492271+060  20190906213710.011611+060  Mozilla Corporation  C:\Program Files\Mozilla Firefox\firefox.exe  \program files\mozilla firefox\  TRUE      OK      FALSE   69.0.0.7178  TRUE
C:\Users\adaml>wmic datafile where name="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" get "file system name"

FSName
NTFS
C:\Users\adaml>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.

Adam Lynch
  • 3,341
  • 5
  • 36
  • 66
  • 1
    For macOS, using Objective-C or Swift, you would get the "display name" for the item at a path (or URL). E.g. `[[NSFileManager defaultManager] displayNameAtPath:path]`. (That's what would show up in the Finder and Dock. Note that, when the app is running, a different name may show up as the title of the application menu in the menu bar.) – Ken Thomases Sep 07 '19 at 20:13

1 Answers1

0

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));
Adam Lynch
  • 3,341
  • 5
  • 36
  • 66