Desktop or Laptop ?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
yabab33299
Posts: 136
Joined: 06 May 2020, 17:16

Desktop or Laptop ?

03 Apr 2024, 21:42

I don't know if this is possible, but can a script detect if its desktop, do this, then if its laptop, do that ?
User avatar
mikeyww
Posts: 27200
Joined: 09 Sep 2014, 18:38

Re: Desktop or Laptop ?

03 Apr 2024, 22:04

Yes. You simply need to define each of them first! :)

Examples could be using a screen resolution, or a computer name of your choosing. A computer is a computer-- different shapes and sizes-- but your own situation might (and probably does) have some distinguishing features. Does one have a battery, and the other not have a battery? That can be a way to tell. Wi-Fi vs. no Wi-Fi. Etc.
User avatar
flyingDman
Posts: 2832
Joined: 29 Sep 2013, 19:01

Re: Desktop or Laptop ?

03 Apr 2024, 22:10

Try:

Code: Select all

a_clipboard := ""
Run a_comspec ' /c wmic systemenclosure get chassistypes | clip',,'hide'
if ClipWait(1)
	{
	regexmatch(a_clipboard, "(\d+)",&m)
	msgbox (m[1] = 9 or m[1] = 10) ? "laptop" : "desktop"
	}
This worked on my laptop but do not have a desktop to test.

edit added a clipwait
Last edited by flyingDman on 03 Apr 2024, 22:23, edited 1 time in total.
14.3 & 1.3.7
yabab33299
Posts: 136
Joined: 06 May 2020, 17:16

Re: Desktop or Laptop ?

03 Apr 2024, 22:19

flyingDman wrote:
03 Apr 2024, 22:10
Try:

Code: Select all

Run a_comspec ' /c wmic systemenclosure get chassistypes | clip',,'hide'
regexmatch(a_clipboard, "(\d+)",&m)
msgbox (m[1] = 9 or m[1] = 10) ? "laptop" : "desktop"
This worked on my laptop but do not have a desktop to test.
How do I make labels to assign commands if its desktop vs laptop ?
songdg
Posts: 609
Joined: 04 Oct 2017, 20:04

Re: Desktop or Laptop ?

03 Apr 2024, 22:24

flyingDman wrote:
03 Apr 2024, 22:10
Try:

Code: Select all

Run a_comspec ' /c wmic systemenclosure get chassistypes | clip',,'hide'
regexmatch(a_clipboard, "(\d+)",&m)
msgbox (m[1] = 9 or m[1] = 10) ? "laptop" : "desktop"
This worked on my laptop but do not have a desktop to test.
Works fine on my desktop.
User avatar
flyingDman
Posts: 2832
Joined: 29 Sep 2013, 19:01

Re: Desktop or Laptop ?

03 Apr 2024, 22:28

labels ?
Perhaps this will help:

Code: Select all

a_clipboard := ""
Run a_comspec ' /c wmic systemenclosure get chassistypes | clip',,'hide'
if ClipWait(1)
	{
	regexmatch(a_clipboard, "(\d+)",&m)
	if (m[1] = 9 or m[1] = 10) 
		msgbox "this is a laptop" 
	else 
		msgbox "this is a desktop"
	}
The exact list is:
1 - Other
2 - Unknown
3 - Desktop
4 - Low Profile Desktop
5 - Pizza Box
6 - Mini Tower
7 - Tower
8 - Portable
9 - Laptop
10 - Notebook
11 - Hand Held
12 - Docking Station
13 - All in One
14 - Sub Notebook
15 - Space-Saving
16 - Lunch Box
17 - Main System Chassis
18 - Expansion Chassis
19 - SubChassis
20 - Bus Expansion Chassis
21 - Peripheral Chassis
22 - Storage Chassis
23 - Rack Mount Chassis
24 - Sealed-Case PC
30 - Tablet
31 - Convertible
32 - Detachable
14.3 & 1.3.7
User avatar
mikeyww
Posts: 27200
Joined: 09 Sep 2014, 18:38

Re: Desktop or Laptop ?

03 Apr 2024, 22:46

That's cool. Here is just another way to do the same thing.

Get chassis type

Code: Select all

#Requires AutoHotkey v2.0
MsgBox chassisType(), 'Chassis type', 'Iconi'

chassisType() {
 Static chassis := Map(
     1, 'Other'
  ,  2, 'Unknown'
  ,  3, 'Desktop'
  ,  4, 'Low-profile desktop'
  ,  5, 'Pizza box'
  ,  6, 'Mini tower'
  ,  7, 'Tower'
  ,  8, 'Portable'
  ,  9, 'Laptop'
  , 10, 'Notebook'
  , 11, 'Handheld'
  , 12, 'Docking station'
  , 13, 'All in one'
  , 14, 'Sub-notebook'
  , 15, 'Space-saving'
  , 16, 'Lunchbox'
  , 17, 'Main system chassis'
  , 18, 'Expansion chassis'
  , 19, 'Sub-chassis'
  , 20, 'Bus expansion chassis'
  , 21, 'Peripheral chassis'
  , 22, 'Storage chassis'
  , 23, 'Rack-mount chassis'
  , 24, 'Sealed-case PC'
  , 30, 'Tablet'
  , 31, 'Convertible'
  , 32, 'Detachable'
 )
 queryEnum := ComObjGet('winmgmts:').ExecQuery('Select * from Win32_SystemEnclosure')._NewEnum()
 If queryEnum(&p)
  For t in p.ChassisTypes
   Return chassis[t]
}
User avatar
kunkel321
Posts: 1143
Joined: 30 Nov 2015, 21:19

Re: Desktop or Laptop ?

04 Apr 2024, 13:21

Does it need to detect any laptop vs desktop, or is it just your one laptop vs your one desktop? If you only care about specific ones (as Mike suggested) you might use the built in variable A_ComputerName.
ste(phen|ve) kunkel
yabab33299
Posts: 136
Joined: 06 May 2020, 17:16

Re: Desktop or Laptop ?

04 Apr 2024, 15:14

kunkel321 wrote:
04 Apr 2024, 13:21
Does it need to detect any laptop vs desktop, or is it just your one laptop vs your one desktop? If you only care about specific ones (as Mike suggested) you might use the built in variable A_ComputerName.
I have 2 DELL laptops and 1 desktop. I read that a precise way to differentiate the 2 laptops is by using its UUID, which is obtained by cmd command wmic csproduct get uuid. I often have to reinstall windows so ComputerName is not reliable. How do I put all this in a script where if it UUID matches certain DELL laptop, run this command, if the other, run some other command ?
User avatar
mikeyww
Posts: 27200
Joined: 09 Sep 2014, 18:38

Re: Desktop or Laptop ?

04 Apr 2024, 15:52

Your question has now changed from the original one. You are probably better off using a MachineGuid, but if you want the UUID, it is below. As noted, if you control these computers and set the computer name (or they simply have unique names), then that would be sufficient to distinguish all of them.

Code: Select all

#Requires AutoHotkey v2.0
dell1 := '123456'
dell2 := 'abcdefg'
MsgBox uuid(), 'UUID', 'Iconi'

If uuid() = dell1
     MsgBox 1
Else MsgBox 2

uuid() {
 queryEnum := ComObjGet('winmgmts:').ExecQuery('Select * from Win32_ComputerSystemProduct')._NewEnum()
 If queryEnum(&p)
  Return p.UUID
}
yabab33299
Posts: 136
Joined: 06 May 2020, 17:16

Re: Desktop or Laptop ?

05 Apr 2024, 06:56

I am currently using my desktop aka ASUS3, I am trying to set volume for ASUS3, but dell1 and dell2 audio devices don't exist in my desktop which is normal. A popup says Error: Device not found . Is it possible to ignore that warning and let script run with no popup ?

Code: Select all

#Requires AutoHotkey v2.0

dell1 := '827583f0-8fe7-417b-8a81-94641f0eb324'
dell2 := '9afd4898-2154-4ccb-98da-1f3abfbc408a'
ASUS3 := '28f11e28-6c02-76eb-8ea5-da9772715135'

MsgBox uuid(), 'UUID', 'Iconi'

If uuid() = dell1
     MsgBox 1
	SoundSetVolume "20", , "Speakers (Realtek(R) Audio)"
	
If uuid() = dell2
     MsgBox 2
    	 SoundSetVolume "30", , "Intel (Realtek(L) Audio)"
	
If uuid() = ASUS3
     MsgBox 3
	SoundSetVolume "20", , "MX279 (Intel(R) Display Audio)"
	
uuid() {
 queryEnum := ComObjGet('winmgmts:').ExecQuery('Select * from Win32_ComputerSystemProduct')._NewEnum()
 If queryEnum(&p)
  Return p.UUID
}
User avatar
flyingDman
Posts: 2832
Joined: 29 Sep 2013, 19:01

Re: Desktop or Laptop ?

05 Apr 2024, 08:41

Your issue is with the if and {} blocks (or lack thereof)

Also (because your UUID look real)
There are a few reasons why you should not post your UUID online. First, it could be used to track you across multiple websites and services. Second, it could be used to identify you if you are using a service that uses UUIDs to authenticate users. Third, it could be used to link your online activity to your real-world identity if you have ever used your UUID in a public setting.
If you need to share a UUID with someone, it is best to do so in a private message or email. You should also avoid posting your UUID on social media or other public websites.
14.3 & 1.3.7
yabab33299
Posts: 136
Joined: 06 May 2020, 17:16

Re: Desktop or Laptop ?

05 Apr 2024, 16:29

Thankyou for the warning. I did not know that......

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: No registered users and 42 guests