AHK allow only to run on specific hdd serial Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kentpachi
Posts: 152
Joined: 15 May 2016, 01:23

AHK allow only to run on specific hdd serial

18 Oct 2020, 19:38

I want to prevent my ahk script getting pirated or avoid getting spread to public.

How to make it only work on a specific hdd serial?
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: AHK allow only to run on specific hdd serial

18 Oct 2020, 19:45

DriveGet

Code: Select all

DriveGet, sn, Serial, % SubStr(A_WinDir, 1, 2)
MsgBox, 64, Serial number, %sn%
Here is something related-- will be unique to the installation.

https://www.autohotkey.com/boards/viewtopic.php?p=354914#p354914
kentpachi
Posts: 152
Joined: 15 May 2016, 01:23

Re: AHK allow only to run on specific hdd serial

18 Oct 2020, 20:15

mikeyww wrote:
18 Oct 2020, 19:45
DriveGet

Code: Select all

DriveGet, sn, Serial, % SubStr(A_WinDir, 1, 2)
MsgBox, 64, Serial number, %sn%
Here is something related-- will be unique to the installation.

https://www.autohotkey.com/boards/viewtopic.php?p=354914#p354914
im really sorry as I am really newbie to this kind of stuff, a good sample of script is the way i learn fast.

This is my serial "50026B77828278E9"
Can you make a script that it only works on this hdd serial?
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: AHK allow only to run on specific hdd serial

18 Oct 2020, 20:22

My previous code showed the volume serial number. This one uses the HDD number.

Code: Select all

If !hddsn("50026B77828278E9") {
 MsgBox, 48, Failure, Maybe next time! Aborting.
 ExitApp
}
MsgBox, 64, Success, You are good to go!
; Main code goes here
ExitApp

hddsn(sn := "") {
 objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 colSettings := objWMIService.ExecQuery("Select * from Win32_DiskDrive")._NewEnum
 While colSettings[objOSItem]
  hddsn := Trim(objOSItem.SerialNumber)
 Return sn ? (hddsn = sn) : hddsn
}
kentpachi
Posts: 152
Joined: 15 May 2016, 01:23

Re: AHK allow only to run on specific hdd serial

18 Oct 2020, 22:27

mikeyww wrote:
18 Oct 2020, 20:22
My previous code showed the volume serial number. This one uses the HDD number.

Code: Select all

If !hddsn("50026B77828278E9") {
 MsgBox, 48, Failure, Maybe next time! Aborting.
 ExitApp
}
MsgBox, 64, Success, You are good to go!
; Main code goes here
ExitApp

hddsn(sn := "") {
 objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 colSettings := objWMIService.ExecQuery("Select * from Win32_DiskDrive")._NewEnum
 While colSettings[objOSItem]
  hddsn := Trim(objOSItem.SerialNumber)
 Return sn ? (hddsn = sn) : hddsn
}
I get an error" Maybe Next time! Aborting..." even tho im using this pc with the hdd serial " 50026B77828278E9 " .
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: AHK allow only to run on specific hdd serial

18 Oct 2020, 22:38

How did you identify your serial number? Does your string contain spaces?

You can run the following to see what it says.

Code: Select all

MsgBox, 64, Your HDD serial number, % hddsn := hddsn()
Clipboard := hddsn
ExitApp

hddsn(sn := "") {
 objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 colSettings := objWMIService.ExecQuery("Select * from Win32_DiskDrive")._NewEnum
 While colSettings[objOSItem]
  hddsn := Trim(objOSItem.SerialNumber)
 Return sn ? (hddsn = sn) : hddsn
}
kentpachi
Posts: 152
Joined: 15 May 2016, 01:23

Re: AHK allow only to run on specific hdd serial

18 Oct 2020, 22:45

mikeyww wrote:
18 Oct 2020, 22:38
How did you identify your serial number? Does your string contain spaces?

You can run the following to see what it says.

Code: Select all

MsgBox, 64, Your HDD serial number, % hddsn := hddsn()
Clipboard := hddsn
ExitApp

hddsn(sn := "") {
 objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 colSettings := objWMIService.ExecQuery("Select * from Win32_DiskDrive")._NewEnum
 While colSettings[objOSItem]
  hddsn := Trim(objOSItem.SerialNumber)
 Return sn ? (hddsn = sn) : hddsn
}
Now this one works bro, it shows "WCAV93215882"

Everything is good now, Bless you for bearing with me sir.
Have a great health and day
Thank you
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: AHK allow only to run on specific hdd serial  Topic is solved

18 Oct 2020, 22:51

This function seems to work more consistently.

Code: Select all

hddsn(sn := "") {
 objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 colSettings := objWMIService.ExecQuery("Select * from Win32_DiskDrive")._NewEnum
 Loop
  hddsn := Trim(objOSItem.SerialNumber)
 Until !colSettings[objOSItem] || StrLen(hddsn) > 4
 Return sn ? (hddsn = sn) : hddsn
}
kentpachi
Posts: 152
Joined: 15 May 2016, 01:23

Re: AHK allow only to run on specific hdd serial

20 Oct 2020, 10:04

mikeyww wrote:
18 Oct 2020, 22:51
This function seems to work more consistently.

Code: Select all

hddsn(sn := "") {
 objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 colSettings := objWMIService.ExecQuery("Select * from Win32_DiskDrive")._NewEnum
 Loop
  hddsn := Trim(objOSItem.SerialNumber)
 Until !colSettings[objOSItem] || StrLen(hddsn) > 4
 Return sn ? (hddsn = sn) : hddsn
}
hi, this one is not working, it says "Failure" while this one works

Code: Select all

hddsn(sn := "") {
 objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 colSettings := objWMIService.ExecQuery("Select * from Win32_DiskDrive")._NewEnum
 While colSettings[objOSItem]
  hddsn := Trim(objOSItem.SerialNumber)
 Return sn ? (hddsn = sn) : hddsn
}
[Mod edit: c-tags replaced with [code][/code] tags.]
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: AHK allow only to run on specific hdd serial

20 Oct 2020, 10:13

Interesting. Thanks for the feedback. With the original script, I found different results on different computers, according to the number of drives installed and perhaps other factors. The final version that I provided works on both of my computers, but your experience is different and informative!
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: AHK allow only to run on specific hdd serial

23 Oct 2020, 07:49

Return true (1) if SN is correct or false (0) if not

Code: Select all

hddsn(sn)
{
	for objItem in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_DiskDrive")
		if (InStr(objItem.SerialNumber, sn))
			return true
	return false
}
example

Code: Select all

if (hddsn("50026B77828278E9"))
	MsgBox % "Success"
else
	MsgBox % "Failure"
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: AHK allow only to run on specific hdd serial

23 Oct 2020, 07:54

Very nice! Thank you, @jNizM!
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: AHK allow only to run on specific hdd serial

23 Oct 2020, 12:33

Kind of funny that someone that barely understands AHK thinks their script is so great that it would be pirated. And that this "copy protection" can be foiled by any text editor like Notepad.

I guess it would protect your script from someone that does not know how to use Google.

Like two blind people playing "I Spy with my Little Eye".

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: AHK allow only to run on specific hdd serial

23 Oct 2020, 12:40

The customer shall be the judge! :D
User avatar
mackvitto
Posts: 3
Joined: 30 Jan 2021, 00:09

Re: AHK allow only to run on specific hdd serial

15 Aug 2023, 21:27

mikeyww wrote:
18 Oct 2020, 20:22
My previous code showed the volume serial number. This one uses the HDD number.

Code: Select all

If !hddsn("50026B77828278E9") {
 MsgBox, 48, Failure, Maybe next time! Aborting.
 ExitApp
}
MsgBox, 64, Success, You are good to go!
; Main code goes here
ExitApp

hddsn(sn := "") {
 objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 colSettings := objWMIService.ExecQuery("Select * from Win32_DiskDrive")._NewEnum
 While colSettings[objOSItem]
  hddsn := Trim(objOSItem.SerialNumber)
 Return sn ? (hddsn = sn) : hddsn
}
**********************************************
Hello, can you help me, since I see you have a lot of experience, I need to create an App that only runs if the application matches the USB flash serial, can you help me with this. this is the data of my usb.
Kingston DataTraveler 3.0 USB Device
\\.\PHYSICALDRIVE2
EE03DC5154E9
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: AHK allow only to run on specific hdd serial

16 Aug 2023, 05:31

Code: Select all

; This script checks a removable drive's serial number for validity
#Requires AutoHotkey v1.1.33
validSN := "EE03DC5154E9"
valid   := False
DriveGet driveList, List, REMOVABLE
Loop Parse, % driveList
{ DriveGet sn, Serial, % A_LoopField ":"
  If valid := sn = validSN
   Break
}
If !valid {
 MsgBox 48, Authorization, Authorization is not granted. Aborting.
 ExitApp
}
SoundBeep 1500
User avatar
mackvitto
Posts: 3
Joined: 30 Jan 2021, 00:09

Re: AHK allow only to run on specific hdd serial

16 Aug 2023, 12:21

mikeyww wrote:
16 Aug 2023, 05:31

Code: Select all

; This script checks a removable drive's serial number for validity
#Requires AutoHotkey v1.1.33
validSN := "EE03DC5154E9"
valid   := False
DriveGet driveList, List, REMOVABLE
Loop Parse, % driveList
{ DriveGet sn, Serial, % A_LoopField ":"
  If valid := sn = validSN
   Break
}
If !valid {
 MsgBox 48, Authorization, Authorization is not granted. Aborting.
 ExitApp
}
SoundBeep 1500
-----------------------------------------------
Hello, Thank you for your prompt response and help, but I have reviewed the code you provided and it does not work. The Serial of my USB is EE03DC5154E9 which in fact is already written in the code, but always when executing the script, whether I put the real serial or a false one, it always sends me the MsgBox 48, Authorization, Authorization is not granted. aborting.
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: AHK allow only to run on specific hdd serial

16 Aug 2023, 20:23

You can use the script to display all of the serial numbers found, so that you know what they are.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 205 guests