What OS to you use? Cause on Vista I do not find any way to block the shutdown (ShutdownBlockReasonCreate needs a window...).
But the service itself works fine.
Here some eventlog-output:
SERVICE_CONTROL_SHUTDOWN (<- shutdown event caught)
AbortSystemShutdown failed! Error=1115 (<- means shutdown already in progress, very funny errorcode )
The only thing left is to stop the shutdown.
On WinXP your code should work. How do you test your service?
You can just catch this event if your app really runs as service
in debug mode you will never see this event.
Here some code-changes I made (but nothing very special):
1. The "problem" that your SetServiceStatus always "fails":
2. In "...::Handler(...)" I made some changes to get more eventlog entries:
3. AbortShutdown changes: (AbortShutdown is now part of your Module class, just for LogEvent)
BOOL ...::AbortShutdown(LPTSTR lpMachineName)
HANDLE hToken; // handle to process token
TOKEN_PRIVILEGES tkp; // pointer to token structure
BOOL fResult; // system shutdown flag // Get the current process token handle so we can get shutdown // privilege. if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
// TRACE("OpenProcessToken failed.\n");
// Get the LUID for shutdown privilege. if(!LookupPrivilegeValue(lpMachineName, SE_SHUTDOWN_NAME, &tkp.Privileges.Luid))
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges.Attributes = SE_PRIVILEGE_ENABLED;
// Get shutdown privilege for this process. if(!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0))
// Cannot test the return value of AdjustTokenPrivileges. /*if (GetLastError() != ERROR_SUCCESS)
//TRACE("AdjustTokenPrivileges(setting) enable failed.\n");
}*/// Prevent the system from shutting down.
fResult = AbortSystemShutdown(NULL); // <---- changed to NULL for local pcif (!fResult)
swprintf((wchar_t*)&test, TEXT("AbortSystemShutdown failed! Error=%d"), (DWORD)GetLastError());
//Cxcutter objexe;//objexe.Write_W3C_Log ("ZDEVSERVICE" , "1.0" , "" , "AbortSystemShutdown Successful" , "In CtrlHandler" , "" , "");
//m_bIsShuttingDown = false; // Reset shut down flag// Disable shutdown privilege.
tkp.Privileges.Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
// TRACE("AdjustTokenPrivileges(re-setting) disable failed.\n"); returnfalse;
Like you see I never changed something special and your service gets the SHUTDOWN notification.
Now its just the question how to abort the shutdown? Maybe this code works on WinXP.
I would say, at first try out some more logging to the eventlog just to find out if your service
catches the event SERVICE_CONTROL_SHUTDOWN. If so then you have to find out where an error occurs.
And make sure every time you test your service really runs as service.
Let me you know what you find out, cause your code is fine.
I was able to abort shutdown and execute my scripts when the user was logged on to the system by making the service as an interactive service but in case when user was logged off and the shutdown was scheduled , the shutdown was aborted but no scripts were executed.Please suggest what to do in this case when no user is logged on to the system and shutdown was made a scheduled task.
I have a strange problem with me..... I have an application(vc++) in which i am taking login to SYBASE database.For that i am using Sybase SDk.My code is working fine with MS-2000 OS,But when i am working the same code in vista machine i am getting login crash when I enter wrong password/username....But working successfully with correct details...
I have code like this... _dbproc = dbConnect (&_loginfo, _T("Phoenix")); (this is calling of my function)
DBPROCESS NEAR * CALLBACK dbConnect (LPLOGINFO li, LPSTR app)
DBPROCESS NEAR *dbproc;
if ((login = dblogin ()) == NULL)
return (DBPROCESS NEAR *) NULL;
dbproc = dbopen (login, li->dbsrv); (My Login crashes here when i enter wrong username/password)
if (dbproc != (DBPROCESS NEAR *) NULL)
dbuse (dbproc, li->dbdb);
As i said above dblogin() is a function that returns LOGINREC structure pointer when we provide correct login details otherwise FALSE...
And dbopen() function takes the LOGINREC as a first input argument and tries to open the application...
But not returning back when i enter incorrect login details.....There it is crashing...
So I have Visual C++ 2008 Express, won't be buying Std edition any time soon, and I'm very annoyed to find out the Express doesn't have all the libraries, like the MFC libraries.
So I had this problem where my program would not compile because it couldn't find "winres.h" I just renamed "winresrc.h" to "winres.h" to get it to compile. I don't know if that is going to work out or not.
So, I'm guessing winres.h just isn't part of the Windows SDK, instead it is included in the MFC libraries?
My next step is to get the Windows Template Library, and see if that helps.
Yeah, Just beginning to learn C++ last couple of months.
I would recommend you stick to pure C++ until you feel totally comfortable with it, and avoid trying to understand MFC, WTL or the like. I went through this process some years back and got totally confused trying to learn C++ and MFC at the same time.
The MFC has the advantage that the wizards of the VC work with it but the disadvantage that it is like outdated glue. Sigh
I thought MFC is like hot glue. It's great for quick or simple work, even after years you can pull out your hot glue gun and it does the job. I once borrowed a van and lost a mirror on the Autobahn, luckily we could make one from spare parts (hand mirror and a plastic bowl), hotglued it back on and continued the travel. Can Silverlight do that?
Working with glue is fine if you do a "glue" job. But if you want to engineer a car you need finer tools.
I do a lot with MFC, but for finer control, lighter setups you better stick to ATL or WTL. Or the code isnt portable to other platforms. A time ago after I throw all MFC stuff out of my code to get running on MAC OS with GCC. Since than I try to separate "pure C" and MFC code in classes.
Press F1 for help or google it.
Greetings from Germany
I am developing a MDI based application. In that i have two set of splitter. For ex splitter1 has TestView1, TestView2 and splitter2 has TestView3, TestView4. In this situation i am loading the splitter1 as initial view for my application. Here i want to open the splitter2 by some menu selection in the same document. How can i get this result.
Expect your guidance to solve this issue.
Thanks in advance
That said, I thoroughly recommend the Day in the life articles.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[^]
I'm using Visual C++ 2005 and have added a dialog to my project.
When i tried to add class for this dialog by right click and select "Add Class"
It pops up a script error: "Line: 815
Error: Object doesn't support this property or method".
Last Visit: 31-Dec-99 18:00 Last Update: 24-Sep-23 1:53