getenv / setenv conundrum

getenv / setenv conundrum

john.uhden
Mentor Mentor
889 Views
6 Replies
Message 1 of 7

getenv / setenv conundrum

john.uhden
Mentor
Mentor

I am trying to secure a .FAS program from being used by anyone outside my client's company.

I checked out the OS environment  and found that their USERDOMAIN appeared unique, e.g. "COMPANY.COM"

So,

(if (/= (getenv "USERDOMAIN") "COMPANY.COM")(exit))

But then I thought, what if some psychic pirate wanted to make it run on his own PC?

He could use setenv to create the registry key.

But without some FSO trickery he can't change an OS setting, right?

Well, no he can't, but AutoCAD allows a registry key to be named the same as an OS variable.  And AutoCAD looks to its own registry entries first.

So someone could (setenv "USERDOMAIN" "COMPANY.COM") and the program would run.

IMO, AutoCAD should must not allow this to happen.

Yes, I know that this scenario is leptokurtotic (I know the word 'cause a good sailing friend named his E-Scow "Leptokurtosis."  He had a PhD in statistics.  He explained it to me as "the odds of extreme events happening," like his ever winning a race. <yuk yuk>  Barnegat Bay has and has had some world class sailors, but Doug was not one of them.)

Should I stick with the odds and stop worrying?

Well, I guess I could include checking the AutoCAD registry and vla-registry-delete the entry.  It would be a deterent at least.  Hmm, I could perform the check/delete before getenv.  Did I answer my own question?

John F. Uhden

0 Likes
Accepted solutions (1)
890 Views
6 Replies
Replies (6)
Message 2 of 7

daniel_cadext
Advisor
Advisor

I think that’s (USERDOMAIN) “Volatile”, as in you can change it, but it won’t stick. I never tried though.

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 3 of 7

Sea-Haven
Mentor
Mentor

Locking programs as your trying to do various ways,

 

(setenv "USERDOMAIN" "COMPANY.COM") why not read the full Registry windows key for this, yes maybe can be changed but they have to know the key. My Userdomain appears multiple times in the registry so take your pick.

 

Get hard disk serial number

Get IP of network card

Get the cad serial number _pkser  try it but note I have seen 000-000000 which is not useable. Yes it works from personal experience very simple, blocked an install.

get user login name (setq who (strcase (getenv "username")))

 

 

Hope some ideas help.

0 Likes
Message 4 of 7

Kent1Cooper
Consultant
Consultant

@Sea-Haven wrote:

.... a simple (setenv "JOHNUHDEN" 1) ... x more trials ... resets the setenv each time. ....


[Bear in mind that environment variable values must be text strings, not numbers.  It could still be done that way, but incrementing would require conversion of the string to a number, then incrementing that, then converting it back to a string to set the environment variable again.]

Kent Cooper, AIA
0 Likes
Message 5 of 7

Sea-Haven
Mentor
Mentor

Thanks Kent yes need "1" I just typed it off the top of my head I have it in code and it works.

 

SeaHaven_1-1713408762431.png

 

0 Likes
Message 6 of 7

john.uhden
Mentor
Mentor
Accepted solution

@daniel_cadext , et al,

Found what I wanted at AfraLisp (which I shortened to get just the OS UserDomain)...

(defun getDiskInfo (/ driveList)
  ;; first access the WScript.Network and find some
  ;; useful information
  (cond ((setq wscript (vlax-create-object "WScript.Network"))
         (setq pcname (vlax-get-property wscript "ComputerName")
               pcdom  (vlax-get-property wscript "UserDomain")
               pcuser (vlax-get-property wscript "UserName")
         )
         ;; won't need wscript anymore, so release it
         (vlax-release-object wscript)
         ;; then access the FileSystemObject and proceed if succesfull
         (cond ((setq fso (vlax-create-object "Scripting.FilesystemObject"))
                ;; access the Drives collection
                (setq drives (vlax-get-property fso 'Drives))
                ;; walk thru each drive while collecting information and
                ;; save each piece of information in a list
                (vlax-for n drives
                  (setq driveList (cons (driveInfo n) driveList))
                )
                ;; release objects in reversed sequence of creation
                (vlax-release-object drives)
                (vlax-release-object fso)
               )
         )
        )
  )
  (list pcName pcDom pcUser driveList)
)

 But thank you all for your interest and suggestions.

I can now release a .FAS that is company secure.  👍

John F. Uhden

Message 7 of 7

scot-65
Advisor
Advisor

@john.uhden 

 

Two methods I can think of - both are "Menu Domain" related:

 

a. A Registry key is written at the time of a new install (on a new workstation) via a custom install package specific to our environment. I will later reference this key as a check when issuing update packages (similar to the Inno Setup).

 

MsgBox "The current AutoCAD version is not R2024-LT.\nUpdates will not be installed."

 

b. Menu domain name as session gremlin that is initiated in S::STARTUP, the .MNL file, acadDOC.lsp, or similar.

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes