In the office users often leave my application running when they go for lunch. While they are away the PC will go into standby or suspension, and the network access will be lost, causing a error message when the users return to their machines, not to mention that the backend is usually blocked from edits even though noone is actually using the database.
Is there any way to react to windoze going into standby and force - quit access?
17 7156
Smiley,
They key may be to keep it from going into standby mode....
See this thread, which was actually spawned by your question: Reset System Idle Time
This may be a workaround....
You can use WMI for this. You'll want to put it in a .VBS file and call it when the database is opened. - Option Explicit
-
-
Dim objWMIService, colItems, objLatestEvent
-
-
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
-
Set colItems = objWMIService.ExecNotificationQuery("Select * from Win32_PowerManagementEvent")
-
-
While True
-
Set objLatestEvent = colItems.NextEvent
-
WScript.Echo "A power management event happened" & vbcrlf & "Event type: " & objLatestEvent.EventType
-
' EventType
-
' 4 - Entering suspend
-
' 7 - Resuming from suspend
-
' 18 - Resume Automatic happened
-
WEnd
I was wondering if the code worked for you?
Sorry for not getting back to you. To be honest I dont immediately understand your solution and need to spend a bit of time on google first.
Basically, windows has this object called the WMI, or Windows Management Instrumentation. This object allows you to access all kinds of information about windows, hardware, software, and events happening on the computer.
Lines 1 and 3 are self explanatory.
Line 5 retrieves the WMI object for the current computer. (It can be used to get info about and manage remote computers as well.)
Line 6 runs a query for power management events.
Lines 8 and 15 establish an infinite loop to check for events.
Line 9 retrieves the next power management event.
Line 10 is a message box to describe what event just occurred.
And so what you want to do is replace line 10 with something like, if the event type is 4, then the computer is about to enter suspend mode, so quit out of Access.
Thank you. I still need to check up on how to run a vbscript from Access and how to make the vbscript quit access, and preferably the right session in case the user has another database open.
I suspect the answer may be that the users run a vbscript that creates an access application and opens the database and then sits in the background and monitors.
Would there be any benefit or trouble from running the access application from a script?
The main benefit would be that you get to run code outside the Access process. Which allows you to do stuff without tying up Access. If you plan on doing other stuff aside from monitoring when the computer goes into sleep mode however, you will need to use the asynchronous version of the WMI query.
For example, you can use it to update the front end, monitor computer resources, idle time, lock state, etc. While all of this, with the exception of updating the front end, can be done within the access application itself, it ties up the application to do the monitoring tasks.
As far as drawbacks, I haven't seen any nor do I forsee any. There might be some slight hiccups, such as if the script fails to initialize, then the database won't open. You can get around that by creating and opening the database first. Because even if the script crashes during it's run, it won't close the database unceremoniously.
A fully functioning script could look something like this - Option Explicit
-
-
Dim objAccess, objWMIService, colItems
-
-
Set objAccess = CreateObject("Access.Application")
-
objAccess.Visible = True
-
objAccess.OpenCurrentDatabase "C:\Database1.accdb"
-
-
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
-
Set colItems = objWMIService.ExecNotificationQuery("Select * from Win32_PowerManagementEvent")
-
-
Do While True
-
If colItems.NextEvent.EventType = 4 Then
-
objAccess.Quit
-
Set objAccess = Nothing
-
Set colItems = Nothing
-
Set objWMIService = Nothing
-
Exit Do
-
End If
-
Loop
Would it also be possible to run this from a blank, hidden form that starts any time the database is opened, and simply runs this code in the background?
I use that trick to force users out remotely when I want to run updates.
And.... methinks I could learn much from this Jedi named Rabbit.....
@twinny, unfortunately no. Here's why.
The NextEvent method will not return until an event has occurred. So Access will freeze up until a power management event occurs. E.G. the computer goes to sleep.
Having said that, there is an asynchronous version of the WMI query. Unfortunately, I have not found a way to get that working within Access itself. You get some error about it not being able to find the remote host. And I haven't found a way around that error yet.
Having said that I had yet to find a way to get the asynchronous query to work, I have gotten the asynchronous query to work.
I used a class module for this. Conceivably you can do it all in a form if you wanted. You will have to add a reference to the Microsoft WMI Scripting Vx.xx Library. Whatever your version turns out to be. - Option Explicit
-
Dim WithEvents sink As SWbemSink
-
-
Private Sub sink_OnObjectReady(ByVal objWbemObject As SWbemObject, ByVal objWbemAsyncContext As SWbemNamedValueSet)
-
If objWbemObject.EventType = 4 Then
-
Application.Quit
-
End If
-
Set objWbemObject = Nothing
-
End Sub
-
-
Private Sub Class_Initialize()
-
Dim services As SWbemServices
-
Set sink = New SWbemSink
-
Set services = GetObject("winmgmts:\\.\root\cimv2")
-
services.ExecNotificationQueryAsync sink, "Select * from Win32_PowerManagementEvent"
-
End Sub
And in your form, something like this. - Option Compare Database
-
Option Explicit
-
Public sinker As Class1
-
-
Private Sub Form_Load()
-
Set sinker = New Class1
-
End Sub
Thank you very much for your help so far. I will try to implement this during the next week.
Just wanted to follow up, were you able to get this to work?
Embarrassed to say that I have not found the time to test this yet. I did notice you putting together an article as well, which looks very nice.
Thank you Rabbit! The class module and form worked for me. Is there a way to use late binding instead of Microsoft WMI Scripting library reference?
It's been forever since I've looked at this. I don't know if you can late bind it due to the events, but I've never tried.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Shelley |
last post by:
Is there a way to prevent standby mode with VB.NET?
Thanks,
Shelley
|
by: jbizzy |
last post by:
SQL Users/DBAs,
I'm trying to move data files around for a database that is in standby
mode. I can detach/attach the database fine using
SP_DETACH_DB/SP_ATTACH_DB , but when I re-attach the...
|
by: annie |
last post by:
Hi all,
I have recently ported my Access 2000 app to SQL Server, keeping the
Access client as the front end using linked tables.
I am also using triggers on my SQL tables to trap orphan...
|
by: mcnaman |
last post by:
I have IBM S50 and want to know how to set to standby mode using a vb script for a set duration
|
by: sherifffruitfly |
last post by:
Hi,
I load the contents of an excel sheet into a dataset via the excel
object library (couldn't get the #$%#$^ oledb/ado route to work -
#^$%&^%$ connection strings... grrr.... )
Anyway,...
|
by: Frank Rizzo |
last post by:
I have an WinForm app that sits around doing nothing most of the time.
However, several times during the 24 hour period, based on a timer
event, it goes and does a couple of things (connects to a...
|
by: gator69uf |
last post by:
On Lenovo notebook running Windows XP Pro SP2 when I attempt to go to 'standby' mode I get message that .NET upgrade v1.1.4322 is preventing going to standby.
Has anyone seen this or have an idea...
|
by: Pekboy |
last post by:
I'm having problem opening a .accdr file from a developer package installation. All I get is a blank Access window. This Runtime mode issue is happening both in my development machine with the Full...
|
by: =?Utf-8?B?Z3Jsb25n?= |
last post by:
I have a dell 1210 running XP Media ver 2002. I Have recently done a clean
reinstall of the OS. I have downloaded all of the current drivers and
windows updates. I have tried every conceviable...
|
by: JT |
last post by:
Hi,
I've realized that my good fortune of not having my computer go into
standby mode was the result of my application accessing a file on a
shared network drive. Not going into standby is a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |