Using environs to limit use to a particular PC

jpl458

Well-known member
Local time
Today, 08:53
Joined
Mar 30, 2012
Messages
1,198
I looked around and can't find anything that floats my boat. What is the best way to use environs to get the name of the PC then store. so the app checks to see if this is the permissible PC, or words to that effect.
 
Environ("ComputerName") .... BUT this can be spoofed.
Better to use CreateObject("WScript.Network").ComputerName
 
Simplest case would be the Environ function.


You can use this for Username, Computername, and a few other things. HOWEVER, unscrupulous and excessively clever nasty persons can fake the environment variables unless you have a diligent IT department whose local security profiles prohibit changing them.

There is also the ability to read from the registry though you might have to search for the proper keys.


That article contains a very important warning: Read all you want but don't write to the registry unless you know for a fact that you have the right registry key and know what effect your change will make, because a busted registry is a machine that will need a LOT of work, possibly a ground-up reload of Windows itself - and potential loss of all user data. It would be harder to fake registry keys so these would be more reliable, but the complexity of the keys also makes this a harder task.
 
you can also Save the IP address or MAC address (i prefer this).
Code:
Public Function getMyIP() As String

    Dim myWMI As Object, myObj As Object, itm As Object
    
    Set myWMI = GetObject("winmgmts:\\.\root\cimv2")
    Set myObj = myWMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
    For Each itm In myObj
      getMyIP = itm.IPAddress(0)
      Exit Function
    Next
End Function

Public Function MAC_Address() As String

    Dim myWMI As Object, myObj As Object, itm As Object
    
    Set myWMI = GetObject("winmgmts:\\.\root\cimv2")
    Set myObj = myWMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
    For Each itm In myObj
      MAC_Address = itm.MACAddress
      Exit Function
    Next
End Function
 
I looked around and can't find anything that floats my boat. What is the best way to use environs to get the name of the PC then store. so the app checks to see if this is the permissible PC, or words to that effect.
I use queries similar to those arnelgp is sharing. I like to start those "machine fingerprints" with the machine's username. Then I like to get from the operating system: hostname, type, architecture, release and platform. And from the bios: name, serial number and version. The resulting string would look like these:
Machine: DESKTOP-APSNG19 - Windows_NT x64 10.0.19044 - win32 Name F3 SerialNumber Default string SMBIOSBIOSVersion F3
Machine: SATELLITE - Windows_NT x64 6.3.9600 - win32 Name 5.20 SerialNumber 7E056384U SMBIOSBIOSVersion 5.20
Machine: DESKTOP-4QGCC89 - Windows_NT x64 10.0.19044 - win32 Name F.10 SerialNumber 8CQ043086G SMBIOSBIOSVersion F.10

So, in combination with a username, it's pretty hard that a match happens. It also helps me know which OS releases cause trouble on my programs.

It's up to you, I believe, to decide how much information is enough for a machine fingerprint.
 
Simplest case would be the Environ function.


You can use this for Username, Computername, and a few other things. HOWEVER, unscrupulous and excessively clever nasty persons can fake the environment variables unless you have a diligent IT department whose local security profiles prohibit changing them.

There is also the ability to read from the registry though you might have to search for the proper keys.


That article contains a very important warning: Read all you want but don't write to the registry unless you know for a fact that you have the right registry key and know what effect your change will make, because a busted registry is a machine that will need a LOT of work, possibly a ground-up reload of Windows itself - and potential loss of all user data. It would be harder to fake registry keys so these would be more reliable, but the complexity of the keys also makes this a harder task.
Messing with the registry is verboten.
you can also Save the IP address or MAC address (i prefer this).
Code:
Public Function getMyIP() As String

    Dim myWMI As Object, myObj As Object, itm As Object
   
    Set myWMI = GetObject("winmgmts:\\.\root\cimv2")
    Set myObj = myWMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
    For Each itm In myObj
      getMyIP = itm.IPAddress(0)
      Exit Function
    Next
End Function

Public Function MAC_Address() As String

    Dim myWMI As Object, myObj As Object, itm As Object
   
    Set myWMI = GetObject("winmgmts:\\.\root\cimv2")
    Set myObj = myWMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
    For Each itm In myObj
      MAC_Address = itm.MACAddress
      Exit Function
    Next
End Function
How and where do you call the functions. Is it possible to use this in such a way that the information is gathered when first opened/installed, and the info is gathered then stored somewhere in the app, so the each time it opens it checks to see if it is running on the correct pc? Never had to do this before, so I am unfamiliar with the technique.

Thanks for the response.
 
Read my last paragraph in the post from which you got that quote.
I tried this and it seems works, but I have one question. If you load the program for the first time and it gets the MAC and IP Addresses, where do you store them, so they can be looked up every time the app is opened. to make sure it's running on an authorized pc?

Thanks again, Doc.
 
where do you store them, so they can be looked up every time the app is opened. to make sure it's running on an authorized pc?

That becomes more difficult since most normal ways of storage leave the special "keys" visible to someone with just a little knowledge of how to poke around. One way I've seen done a few times is to generate a hash-code of the string in question. Then you store the hash code in a table somewhere. You don't really want to store the raw ID string. Then, the next time the program launches, you look up the original values in question and compute a new hash string from them. Compare the old and new hashes. If they match, you are good to go. This, too, can be defeated. Look at some of Colin's (Isladog's) posts about hidden and deep-hidden tables as a place to put things you don't want seen. Remember that what the mind of man can imagine, the mind of man can analyze.
 
That becomes more difficult since most normal ways of storage leave the special "keys" visible to someone with just a little knowledge of how to poke around. One way I've seen done a few times is to generate a hash-code of the string in question. Then you store the hash code in a table somewhere. You don't really want to store the raw ID string. Then, the next time the program launches, you look up the original values in question and compute a new hash string from them. Compare the old and new hashes. If they match, you are good to go. This, too, can be defeated. Look at some of Colin's (Isladog's) posts about hidden and deep-hidden tables as a place to put things you don't want seen. Remember that what the mind of man can imagine, the mind of man can analyze.
Some time ago, I wrote an ACCESS app for a friend of mine for use at a driving range. Since the cashiers were not TGIT's (technical giants in training), I hide stuff in invisible globals. And I even had a pixel area on one of the lesser used screens, that when clicked allowed me to go into design mode. That was ten years ago and it it's still used, and no one has found the magic dot, .......yet.

I really like the hash code idea.

Thanks again.
 

Users who are viewing this thread

Back
Top Bottom