|
Hello all,
I have made an MFC application with invisible window and invisible in Applications tab of taskmanager designed to run in different sessions depending upon the number of users who are logged into the system. Thus, according to user events the instances used to capture logoff/Shutdown/Logon events for that particular session.Also, I have made one instance of this executable to run in 'SYSTEM' account to capture scheduled shutdown in cases when no user was logged on the machine. However in this case 'WM_QUERYENDSESSION' is never recieved by this running instance of my application which runs in 'SYSTEM' account.Can some one tell me how to abort scheduled shutdown in Windows from an application running in system account , in a case when no user is logged on in the machine.
Regards,
Kushagra
I hate coding but I luv to develop
modified on Wednesday, October 21, 2009 9:22 AM
|
|
|
|
|
I'm not sure that WM_QUERYSESSION is sent to apps running in system account. You could try SetConsoleCtrlHandler() and catch the CTRL_SHUTDOWN_EVENT . I don't think this allows you to stop the shutdown.
|
|
|
|
|
I got your point, but how do we use SetConsoleCtrlHandler in an MFC application..I can always do shutdown -a inside it if I recieve a CTRL_SHUTDOWN MEssage. Please Detail me how to include it in an MFC application ?
Kushagra
|
|
|
|
|
The MSDN article has a link at the bottom to an example. It's not MFC, but you should be able to use it in an MFC app.
|
|
|
|
|
Thanks Hans,
But yes we can only intercept the message here and not abort shutdown here
Kushagra
|
|
|
|
|
It will sound funny, where actually are you catching WM_QUERYENDSESSION Message?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hey Alok,
I am trapping the message in WndProc(Windows Procedure Method) of the application. Then using the message handler for WM_QUERYENDSESSION I am returning false to abort logoff/shutdown and doing my functionality in between.
Regards,
Kushagra
|
|
|
|
|
Kushagra Tiwari wrote: However in this case 'WM_QUERYSESSION' is never recieved by this running instance...
Where is this message being sent from? Is that process sending it to your window directly, or to all top-level windows via HWND_BROADCAST ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hello David,
Generally when windows receives shutdown event it broadcasts WM_QUERYENDSESSION to all top level windows applications , here the issue is as my MFC application is running silently from 'System' account somehow the broadcasted message from Windows is not able to identify this as a Top level windows application.Hence, this application never recives the message whcih is why I am stuck here. All i need to do is to stop scheduled shutdown from a process running in 'System' account. I am open to suggestions , if this can be done in any other way too.
Regards,
Kushagra
|
|
|
|
|
Kushagra Tiwari wrote: Generally when windows receives shutdown event it broadcasts WM_QUERYENDSESSION to all top level windows applications...
I'm very familar with all of this. I was inquiring about the WM_QUERYSESSION message.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: I was inquiring about the WM_QUERYSESSION message
Most likely a typo since the heading of the post says WM_QUERYENDSESSION , don't you think?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
One can choose to make assumptions, or not. I've been around long enough to know that folks don't always ask the right question.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: I've been around long enough to know that folks don't always ask the right question.
I'm well aware of that and you are not the only one.
For the record my post wasn't meant as criticism as you seem to have understood it.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hey David,
I am sorry It was a TYPO from my side . But kindly suggest some way so that I can achieve my goal.
Kushagra
|
|
|
|
|
Kushagra Tiwari wrote: But kindly suggest some way so that I can achieve my goal.
Do you receive the message if the window is visible? What about if it's running in a non-SYSTEM account?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I have made it invisible , and I recieve this message for all accounts other than SYSTEM account and they are working pretty neat , but only for this particular case for monitering scheduled shutdowns through system account my logic goes for a toss as the message WM_QUERYENDSESSION never comes to the application.
Kushagra
|
|
|
|
|
With services, there is the "Allow service to interact with desktop" option. Is there a similar option for an app running as the SYSTEM account?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I am afraid , I did not found any thing of such kind with an application running from System account.
Kushagra
|
|
|
|
|
Does anybody knows the solution ???
Kushagra
|
|
|
|
|
You might want to also pose this question to the folks in the microsoft.public.vc.language newsgroup. Several sharp folks are active there.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
From MSDN: "Console applications receive shutdown notifications in their handler routines. To register a console handler, use the SetConsoleCtrlHandler function.
Service applications receive shutdown notifications in their handler routines. To register a service control handler, use the RegisterServiceCtrlHandlerEx function."
Maybe that helps.
|
|
|
|
|
Kushagra Tiwari wrote: I have made an MFC application with invisible window and invisible in Applications tab of taskmanager
....
I have made one instance of this executable to run in 'SYSTEM' account
Does this mean that you have created a service?
Kushagra Tiwari wrote: how to abort scheduled shutdown in Windows from an application running in system account
Are you certain that you really want to do this even if it's possible?
What do you mean by 'scheduled'?
Personally I find it suspicious that you have created an application that runs "invisible" from user perspective that aims to block the system from being brought down. I would consider it to be a very anti-social application that I wouldn't want running on any of my machines.
However, if an application calls ::ExitWindowsEx() with the EWK_FORCE parameter, WM_QUERYENDSESSION will not be sent - all processes will be terminated and possibly with data lost.
How do you distinguish from a 'scheduled' shutdown and one triggered by a user in your message handler or callback? I guess the user won't be able to bring the system down either....
What if your application runs on a machine with UPS; the power is lost and the UPS service wants to bring the system down safely? Will you block it if possible?
I guess my question really is "what are to trying to accomplish and why"? There may be a better solution.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Here is a example showed how to pass the string parameter to the javaScript function.
http://www.codeproject.com/KB/COM/jscalls.aspx
but I want to pass a userdefined data type such as a struct.
this is my code but Invoke method failed (incorrect variable type). please help me,thanks.
typedef struct
{
CComBSTR s;
int n;
}MyData;
bool CWebPage::CallJScript(const CString strFunc,CComVariant* pVarResult)
{
CComPtr<IDispatch> spScript;
if(!GetJScript(spScript))
{
ShowError(_T("Cannot GetScript"));
return false;
}
CComBSTR bstrMember(strFunc);
DISPID dispid = NULL;
HRESULT hr = spScript->GetIDsOfNames(IID_NULL,&bstrMember,1,
LOCALE_SYSTEM_DEFAULT,&dispid);
if(FAILED(hr))
{
ShowError(GetSystemErrorMessage(hr));
return false;
}
DISPPARAMS dispparams;
memset(&dispparams, 0, sizeof dispparams);
dispparams.cArgs = 1;
dispparams.rgvarg = new VARIANT[dispparams.cArgs];
SAFEARRAY *psaData = NULL;
SAFEARRAYBOUND saBound = {1,0};
MyData *pMyData = NULL;
psaData = SafeArrayCreate(VT_VARIANT,1,&saBound);
SafeArrayAccessData(psaData,reinterpret_cast<void **>(&pMyData));
pMyData[0].s = SysAllocString(L"Steve");
pMyData[0].n = 8;
SafeArrayUnaccessData(psaData);
dispparams.rgvarg[0].parray = psaData;
dispparams.rgvarg[0].vt = VT_ARRAY;
dispparams.cNamedArgs = 0;
EXCEPINFO excepInfo;
memset(&excepInfo, 0, sizeof excepInfo);
CComVariant vaResult;
UINT nArgErr = (UINT)-1;
hr = spScript->Invoke(dispid,IID_NULL,0,
DISPATCH_METHOD,&dispparams,&vaResult,&excepInfo,&nArgErr);
delete [] dispparams.rgvarg;
if(FAILED(hr))
{
ShowError(GetSystemErrorMessage(hr));
return false;
}
if(pVarResult)
{
*pVarResult = vaResult;
}
return true;
}
<script type="text/javascript">
var obj = {
string: "sss",
ints: 123
}
function showMessage(obj){
alert(obj.string);
alert(obj.ints);
}
</script>
I like c++
|
|
|
|
|
AFAIK You should pass automation-compliant types to Javascript code.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Just have a look at this [^]
Величие не Бога может быть недооценена.
|
|
|
|