Page 1 of 1

Desktop or Laptop ?

Posted: 03 Apr 2024, 21:42
by yabab33299
I don't know if this is possible, but can a script detect if its desktop, do this, then if its laptop, do that ?

Re: Desktop or Laptop ?

Posted: 03 Apr 2024, 22:04
by mikeyww
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.

Re: Desktop or Laptop ?

Posted: 03 Apr 2024, 22:10
by flyingDman
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

Re: Desktop or Laptop ?

Posted: 03 Apr 2024, 22:19
by yabab33299
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 ?

Re: Desktop or Laptop ?

Posted: 03 Apr 2024, 22:24
by songdg
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.

Re: Desktop or Laptop ?

Posted: 03 Apr 2024, 22:28
by flyingDman
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

Re: Desktop or Laptop ?

Posted: 03 Apr 2024, 22:46
by mikeyww
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]
}

Re: Desktop or Laptop ?

Posted: 04 Apr 2024, 13:21
by kunkel321
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.

Re: Desktop or Laptop ?

Posted: 04 Apr 2024, 15:14
by yabab33299
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 ?

Re: Desktop or Laptop ?

Posted: 04 Apr 2024, 15:52
by mikeyww
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
}

Re: Desktop or Laptop ?

Posted: 05 Apr 2024, 06:56
by yabab33299
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
}

Re: Desktop or Laptop ?

Posted: 05 Apr 2024, 08:41
by flyingDman
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.

Re: Desktop or Laptop ?

Posted: 05 Apr 2024, 16:29
by yabab33299
Thankyou for the warning. I did not know that......