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.
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 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: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.
Messing with the registry is verboten.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.
![]()
Read and Write Windows Registry with VBA
VBA offers the functions GetSetting , SaveSetting , GetAllSettings and DeleteSetting for reading and writing the Windows Registry. (For detailed info see the Microsoft VBA help for these functions or look at the MSDN ) But unfortunately you can't access the entire registry, only the path…vba-corner.livejournal.com
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.
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.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
Messing with the registry is verboten.
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?Read my last paragraph in the post from which you got that quote.
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?
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.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.