Author Topic: Modifying script behavior according to computer it runs on  (Read 91 times)

ubacher

  • Super Hero
  • ****
  • Posts: 1925
Modifying script behavior according to computer it runs on
« on: February 12, 2019, 03:41:12 PM »
I would like to have some apps behave differently when they run on the laptop instead of the desktop.
How can I find out what computer I run on?  Only thing I could find which might allow system identification
is a call to v1/utility/registry.  (Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName)
Any better way?

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 21218
Re: Modifying script behavior according to computer it runs on
« Reply #1 on: February 12, 2019, 03:55:41 PM »
The /info endpoint returns a lot of useful information, including the machineName.
See the Info App for details and usage.

ubacher

  • Super Hero
  • ****
  • Posts: 1925
Re: Modifying script behavior according to computer it runs on
« Reply #2 on: February 12, 2019, 09:15:15 PM »
Perfect, Thank you.

Carlo Didier

  • Super Hero
  • ****
  • Posts: 1167
Re: Modifying script behavior according to computer it runs on
« Reply #3 on: February 14, 2019, 11:07:30 AM »
If you want to check independently from IWS, the script could simply read the environment variable "COMPUTERNAME".
Don't know the syntax for javascript, but you should be able to find that.

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 21218
Re: Modifying script behavior according to computer it runs on
« Reply #4 on: February 14, 2019, 11:39:33 AM »
JavaScript apps run in the browser sandbox, which prevents access to environment variables and other potentially harmful things.

If you need to access environment variables or other system functions, use Node.js or Python or ,NET or PowerShell or whatever programming language you prefer. They all work with IMWS much in the same way as native IMatch apps do.

Or you call a PowerShell script from an IMatch app. So many ways to do so many things.

IMWS and IMatch provide a range of low-level functions, like reading/writing files, access to system directories etc. The machine name (computer name) is delivered by the /info endpoint, among user system information.

Check out the /info /process /filesystem endpoints in the documentation for a full list.
« Last Edit: February 14, 2019, 11:44:18 AM by Mario »