Ok,
So.... I have a simple but dirty way to solve the problem. It's a bit like a hammer to crack a nut but it works fine and doesn't involve coding up loads of stuff. IF you have several Access routines on the machine you can use this for all of them with no extra coding.
I needed to find a 100% foolproof way to deal with this as I just knew that users would abuse the system if I didn't do it.
It revolves around psexec. Now part of Microsoft's tools, the PsTools Suite is a very useful set of tools to do stuff like this. PsExec.exe can perform system tasks so I decided to investigate.
First of all I created a new user on the machine with admin rights.
I downloaded and installed the PsTools executables into C:\Pstools and then called psexec from a batch file to turn OFF the Wifi adapter when the user launches Access using the new user with the required rights. A simple "call" instruction holds the batch file in memory until the user exits Access and the rest of the code in the batch then runs.
A simple shortcut on the desktop launches the required routine. Although it's not elegant at all (no, really - it's not) it works just fine every time.
I put the Access Frontend file into folder "C:\Access_Frontend" and called the file "Access_Frontend.accdb".
Just create a batch file called "Access_Launch.bat" (doesn't matter where as you can hide it if you want - or even convert it to an exe if you want to get picky about security) then link a shortcut to it (add a nice icon) and that's it.
Batch file looks like this:
...........................
rem WiFi-Disable batch file with Elevated Rights
rem Change to PSTools Folder
C:
cd\
cd PsTools
rem Disable Wifi - "WiFi" is the NAME of the WiFi adapter
psexec -u USERNAME -p PASSWORD netsh interface set interface name="WiFi" admin=disabled
rem Now change to the Access application folder
C:
CD\
CD\Access_Frontend
rem call the Access application
call Access_Frontend.accdb
rem Batch now waits until you're done
@echo Re-Enabling WiFi
rem Re-Enable Wifi
rem Change to the PsTools folder
C:
cd\
cd PsTools
rem RE-Enable the WiFi
psexec -u USERNAME -p PASSWORD netsh interface set interface name="WiFi" admin=enabled
rem Set Dynamic Addressing on the Interface - Might not be necessary but best to do it anyway
psexec -u USERNAME -p PASSWORD netsh interface ip set address "WiFi" dhcp
rem Exit the routine - Back to Normal!
exit
...........................
I like simple solutions. No need to get complicated and unless the user is hell bent on circumventing what we're doing here (by re-enabling the Wifi manually), it should ensure that they NEVER use the database on WiFi. No need to even detect it. If the Wifi is already off, the routine does nothing, although it does enable it when the routine exits but even that doesn't really matter as if you're connected on cable it's ignored anyway as the wired connection almost always takes priority.
I tried this method on all my laptops. With a slight change on one of them to rename the interface name in the batch file (it was named differently), the routine works on all of them without incident.
Could be useful for someone I suppose...
