Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Lisp File Lock

Pihu_2024
Contributor

Lisp File Lock

Pihu_2024
Contributor
Contributor

Dear Sir,

 

I want to lisp file locking prgramming.

any body please help me.

 

0 Likes
Reply
2,264 Views
40 Replies
Replies (40)

paullimapa
Mentor
Mentor

**correction to post made**

Let’s break it down to see whats causing the error.
1. As I requested before what is the response  in AutoCAD when you copy and paste the following at the command prompt 

 

 (car (vl-registry-descendents "HKEY_CURRENT_USER\\Software\\Microsoft\\IdentityCRL\\UserExtendedProperties"))

 

** 2. What happens when you change the code to this:

 

(setq des (open (strcat (getvar 'dwgprefix) "MyTextFile.txt") "w"))
(write-line "This is a test" des)
(close des)

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

Pihu_2024
Contributor
Contributor

Dear Sir,

 

Thanks for replay.

 

Plaese see the error video.

Please send complete programming.

0 Likes

paullimapa
Mentor
Mentor

I don’t see β€œ error video β€œ in your post. 

Since we are troubleshooting the problem no need for complete program. You should copy and paste the code one line at a time to AutoCADs command prompt to see at which line returns an error. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

diagodose2009
Collaborator
Collaborator

Please you test my demo Normal and Lisp+codpin15.lsp

This is demo, if you need more test/s , more locker, more ..features, , then w hope , we will can more.

.. I am sure70%, i can make same-way-of-your-lisp or part-of-your-lisp, for your-projects.

>that

 

0 Likes

Pihu_2024
Contributor
Contributor

Dear Sir,

 

Thanks for the reply.

How to use this Programming.

Actually don't Lisp programming.

0 Likes

john.uhden
Mentor
Mentor

@Pihu_2024 ,

Thar's so sad.  It worked for me using 2002 with GMail.

John F. Uhden

0 Likes

paullimapa
Mentor
Mentor

Now I see both of your videos. I see the unique email address that is returned when you entered the code I posted and that is good. Now each user should have their own unique email address. You can lock the lisp code using a single email address that the code must match. So to change it to match with your email address modify the code I posted in msg 8 like this:

 

; get default user email account from registry
(setq emlid (car (vl-registry-descendents "HKEY_CURRENT_USER\\Software\\Microsoft\\IdentityCRL\\UserExtendedProperties")))
(if(not(wcmatch emlid "towercad@yahoo.com")) ; replace with your specific email address to check
 (progn ; then email account name did not match
  (alert "Account Not Authorized...Exiting") ; alert user with a dialog box
  (exit) ; exit lisp function
 )
 (progn ; else email account name match
  (princ "Account Validated.") ; alert user at the command line
  ; include the rest of your lisp code here
 )
) ; if

 

 

Or you can check for a list of email addresses that are approved to run the code like this:

 

; setup a list of email addresses all lowercase that are approved to run the lisp code
(setq emlidlst (list "towercad@yahoo.com" "example@company.com" "email@msn.com"))
; get default user email account from registry
(setq emlid (car (vl-registry-descendents "HKEY_CURRENT_USER\\Software\\Microsoft\\IdentityCRL\\UserExtendedProperties")))
(if(not(member (strcase emlid T) emlidlst)) ; chk if acquired email address from user registry is a member of approved email addresses
 (progn ; then email account did not match
  (alert "Account Not Authorized...Exiting") ; alert user with a dialog box
  (exit) ; exit lisp function
 )
 (progn ; else email account is a member of approved list
  (princ "Account Validated.") ; alert user at the command line
  ; include the rest of your lisp code here
 )
) ; if

 

 

So you do need to know a little bit more about lisp to make this work. You'll have to take the section of the code you're trying to lock and place that inside the above code. Then convert the lisp into a FAS or VLX file as described here:
https://help.autodesk.com/view/ACD/2025/ENU/?guid=GUID-D39EA37A-4248-4F05-A822-0F41EA4ECF68

 

As to your 2nd question about saving the registry code to a text file, my original post had a bad quotation mark character that caused the error you see on your AutoCAD command prompt:

paullimapa_0-1728759277754.png

Now enter the following lines of code should work:

 

(setq des (open (strcat (getvar 'dwgprefix) "MyTextFile.txt") "w"))
(write-line "This is your email address:" des)
(write-line(car (vl-registry-descendents "HKEY_CURRENT_USER\\Software\\Microsoft\\IdentityCRL\\UserExtendedProperties"))des)
(close des)

 

 

Your email address retrieved from the registry should be successfully written out to a text file in your current drawing folder. You can copy & paste the following line of code to open the text file for viewing:

 

(startapp "Notepad" (strcat (getvar 'dwgprefix) "MyTextFile.txt"))

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

diagodose2009
Collaborator
Collaborator
I need work together, on your-project.vlax?
Do you known , other method of encrypted?, even no, I need repair my compilator.exe with online-your-project.lisp, that is my problem.
If you do not develop long-time-your-project.lisp, then "you google" and found compilator.exe, online,
but the future of mycompilator.exe, are mixed=mycompilator.exe+your-project.lisp,.
Thank, you.
0 Likes

Pihu_2024
Contributor
Contributor

Dear Sir,

 

Thanks for the reply.

How to export emid id in domin computer.

0 Likes

paullimapa
Mentor
Mentor

I'm not sure what you're referring to with your response. 

But to demonstrate how this all works, I've attached a zip file containing all the files I'm referring to in this post.

Here's a very simple example to demonstrate how you can lock a lisp file.

LZE.lsp contains the following code which shows an example function that draws a line then zoom extents:

(defun c:lze (/)
  (command "_.Line" "0,0" "11,8" "")
  (command "_.Zoom" "_E")
  (princ) ; clean exit
) ; defun

When this is not locked to your email address then anyone can load and run this.

Now LZE-Lock.lsp contains code that works with your computer because it retrieves from the registry your email address of: towercad@yahoo.com

(defun c:lze-lock (/)
; setup a list of email addresses all lowercase that are approved to run the lisp code
(setq emlidlst (list "towercad@yahoo.com" "example@company.com" "email@msn.com"))
; get default user email account from registry
(setq emlid (car (vl-registry-descendents "HKEY_CURRENT_USER\\Software\\Microsoft\\IdentityCRL\\UserExtendedProperties")))
(if(not(member (strcase emlid T) emlidlst)) ; chk if acquired email address from user registry is a member of approved email addresses
 (progn ; then email account did not match
  (alert "Account Not Authorized...Exiting") ; alert user with a dialog box
  (exit) ; exit lisp function
 )
 (progn ; else email account is a member of approved list
  (princ "\nAccount Validated.\n") ; alert user at the command line
 )
) ; if
  (command "_.Line" "0,0" "11,8" "")
  (command "_.Zoom" "_E")
  (princ) ; clean exit
) ; defun

Next LZE-Lock-tcad.lsp contains code that does not include your email address so retrieving from your computer registry will not allow it to run. But it includes my email address so it runs fine on my computer.

(defun c:lze-lock-tcad (/)
; setup a list of email addresses all lowercase that are approved to run the lisp code
(setq emlidlst (list "paulli_apa@hotmail.com" "example@company.com" "email@msn.com"))
; get default user email account from registry
(setq emlid (car (vl-registry-descendents "HKEY_CURRENT_USER\\Software\\Microsoft\\IdentityCRL\\UserExtendedProperties")))
(if(not(member (strcase emlid T) emlidlst)) ; chk if acquired email address from user registry is a member of approved email addresses
 (progn ; then email account did not match
  (alert "Account Not Authorized...Exiting") ; alert user with a dialog box
  (exit) ; exit lisp function
 )
 (progn ; else email account is a member of approved list
  (princ "\nAccount Validated.\n") ; alert user at the command line
 )
) ; if
  (command "_.Line" "0,0" "11,8" "")
  (command "_.Zoom" "_E")
  (princ) ; clean exit
) ; defun

I created this lisp function called Lsp2Fas.lsp that makes it possible for you to select a lsp file to convert it to a fas file so users cannot open and change the contents:

; lsp2fas selects lsp file & converts to fas
; requires AutoCAD 2021 and up
; OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-file-lock/m-p/13081169#M472876
(defun c:lsp2fas (/ ext fas fil filedia fld REMEMBERFOLDERS ttl)
 (if (> (atoi(getvar 'acadver)) 23)
  (progn
   (setq ttl "Select Lsp File To Convert to Fas"
         fld (getvar"dwgprefix")
         ext "lsp"
         flg 2
   )
   (if (and(member "acetutil.arx"(arx))acet-ui-getfile) ; chk if express tools loaded
    (progn ; then it's loaded
     (setq filedia (getvar"filedia")
           REMEMBERFOLDERS (getvar"REMEMBERFOLDERS")
     ) ; save current setting
     (setvar "filedia" 1) ; make sure set this on
     (setvar "REMEMBERFOLDERS" 0) ; don't remember last selected folder location
     (setq fil (acet-ui-getfile ttl fld ext "" flg))
     (setvar "REMEMBERFOLDERS" REMEMBERFOLDERS) ; restore
     (setvar "filedia" filedia) ; restore
    )
    ; else use standard selection dialog
    (setq fil (getfiled ttl fld ext flg))
   ) 
   (if (not(zerop(strlen fil))) ; chk if ok clicked
    (progn ; then proceed
     (setq fas (strcat (vl-filename-directory fil) "\\" (vl-filename-base fil) ".fas"))
     (vlisp-compile 'st fil fas)
     (startapp "explorer.exe" (strcat "/root," (vl-filename-directory fil)))  ; open folder location to review results
     (alert (strcat "Lsp file:\n\t[" fil "]\nSuccessfully Converted to Fas file:\n\t[" fas "]"))    
    )
    ; else cancelled dialog
   (alert "Lsp2Fas Conversion Cancelled.")    
   ) ; if
  ) ; progn
  (alert "Lsp2Fas Conversion Requires AutoCAD 2022 and Higher.")
 ) ; if
 (princ) ; clean exit
) ; defun 

Finally, I also included LZE-Lock-tcad.fas which is a typical fas file that you would give to others to run the lisp code. This can be loaded into AutoCAD exactly like a lsp file. It can be dragged and dropped into the drawing area or you can enter the following at the command prompt to load:

(load"LZE-Lock-tcad.fas")

Any attempts to open the file like with Notepad looks like this which means it cannot be modified. So you cannot change this file to make it work on your computer:

paullimapa_0-1728786695739.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

Pihu_2024
Contributor
Contributor

Dear Sir,

 

Thanks for the reply πŸ™.

I want to export email address in domain computer .

MSG27 Programming load domain computer email ID not showing.

0 Likes

paullimapa
Mentor
Mentor
(setq emlid (car (vl-registry-descendents "HKEY_CURRENT_USER\\Software\\Microsoft\\IdentityCRL\\UserExtendedProperties")))

This code which retrieves from computers registry the user's email address only works if an email address is setup on the user window's login. If no email account is established then this locking method will not work for you.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

Sea-Haven
Mentor
Mentor

In my post #17 I asked a question which you did not answer and its important to try to help you. So again.

 

Is the code to be used only within the company you work for, so some CAD users do not have access.

Or is the code to be provided to people outside of your company ie sell a program to someone.

 

Please answer it will help to work out a solution.

 

0 Likes

Pihu_2024
Contributor
Contributor

Dear Sir,

Thanks for the reply πŸ™,

I want to limit user using the Lisp programming.

Please help sir.

0 Likes

paullimapa
Mentor
Mentor

Since you cannot always get the email address with the code I provided previously, then you can also try the username method which is not as effective but may work. This is based on the user's windows login name:

For example, when you enter the following at AutoCAD's command prompt it should return your windows login name which is unique to you:

(getenv "username")

So for every user you want to give access to use the lisp program you ask them to enter the above line of code at the AutoCAD command prompt. Then send the result back to you.

Now you would do something similar to the code I provided previously. But instead of matching with email addresses, the code will now match with username.

So if for example, your username returns as:

towercad

Then the lisp code example I provided before to check for your username instead of email address will look like this:

(defun c:lze-lock (/ username usernamelst)
; setup a list of usernames all lowercase that are approved to run the lisp code
(setq usernamelst (list "towercad" "hp-spector")) 
; change yours from "towercad" to what you see in AutoCAD
; hp-spector is my home computer's windows username login
; get username while running AutoCAD
(setq username (getenv "username"))
(if(not(member (strcase username T) usernamelst )) ; chk if acquired username is a member of approved list
 (progn ; then username  did not match
  (alert "Account Not Authorized...Exiting") ; alert user with a dialog box
  (exit) ; exit lisp function
 )
 (progn ; else username is a member of approved list
  (princ "\nAccount Validated.\n") ; alert user at the command line
 )
) ; if
  (command "_.Line" "0,0" "11,8" "")
  (command "_.Zoom" "_E")
  (princ) ; clean exit
) ; defun

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

Pihu_2024
Contributor
Contributor

Dear Sir,

 

Thanks for the reply πŸ™ 

User name Lock working good.

I want to one more requirement lisp file lock by Date Month year 

Please give.

0 Likes

paullimapa
Mentor
Mentor

Any particular year month and date you’re looking at locking the file so it won’t run after a certain date?  


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes

Sea-Haven
Mentor
Mentor

Easy for date, you can see today 15th October 2024.

(getvar 'cdate)
20241015.0940598

,  

0 Likes

diagodose2009
Collaborator
Collaborator
b)How to calculate integrity of lisp?
c)How to blocked the your-lisp, if the client do not , more pay to you, the money??
Please help-me, help, help , help-me , help me..
==Try my solution,
You must run "windosXP-mode" inside "win10 or win11" .
https://sourceforge.net/projects/vlaxcompil/files/kitt2025/
== Please you use, this programe-exe, and send to me, your-problems.

0 Likes

Pihu_2024
Contributor
Contributor

Dear Sir,

Please give one sample programming.

0 Likes