|
You may want to look carefully at the event access rights.
You don't need EVENT_ALL_ACCESS.
EVENT_MODIFY_STATE is the only access your app needs.
You certainly shouldn't have to run with elevated privileges just
to get a handle to a global event object
Synchronization Object Security and Access Rights[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have tried that way also ( SYNCHRONIZE | EVENT_MODIFY_STATE ,etc ),i am getting the same error 5.
|
|
|
|
|
I don't know what you have going on.
I just tried the following on Vista (not running elevated)...
HANDLE ghRequestEvent = ::CreateEvent(NULL, FALSE, FALSE, _T("Global\\Role_Set")) ;
if(NULL == ghRequestEvent)
{
return;
}
::WaitForSingleObject(ghRequestEvent, INFINITE);
::CloseHandle(ghRequestEvent);
HANDLE ghRequestEvent = ::OpenEvent(EVENT_MODIFY_STATE, FALSE, _T("Global\\Role_Set"));
if(NULL == ghRequestEvent)
{
DWORD dwErr = ::GetLastError();
return;
}
::SetEvent(ghRequestEvent);
::CloseHandle(ghRequestEvent);
Worked fine first try.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Is the first application a service ?
|
|
|
|
|
navaneethm wrote: Is the first application a service ?
No, but I'll test that as well - I'll get back to you shortly
on that
What account is your service running under?
Also, I used OpenEvent( EVENT_MODIFY_STATE, not OpenEvent( SYNCHRONIZE|EVENT_MODIFY_STATE.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
OK got it. Here's code that works on Vista with the event
created in a service:
SECURITY_DESCRIPTOR sd = {0};
::InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
::SetSecurityDescriptorDacl(&sd, TRUE, 0, FALSE);
SECURITY_ATTRIBUTES sa = {0};
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
HANDLE ghRequestEvent = ::CreateEvent(&sa, FALSE, FALSE, _T("Global\\Role_Set")) ;
if(NULL == ghRequestEvent)
{
return;
}
::WaitForSingleObject(ghRequestEvent, INFINITE);
::CloseHandle(ghRequestEvent);
HANDLE ghRequestEvent = ::OpenEvent(EVENT_MODIFY_STATE, FALSE, _T("Global\\Role_Set"));
if(NULL == ghRequestEvent)
{
return;
}
::SetEvent(ghRequestEvent);
::CloseHandle(ghRequestEvent);
I would expect OpenEvent() to return NULL with GetLastError returning an access
denied error but instead it returns a valid handle that does nothing when you use it.
SetEvent() succeeds as well.
Hopefully that will work for you
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thank you Mr.Mark Salsbery,
Thank you very much
The problem solved with your help.
Thanks & Regards
Navaneeth
|
|
|
|
|
i made a sample service and a console application for testing .i am putting complete code bellow.
Service ( Application 1)
#include <windows.h>
SERVICE_STATUS FireServiceStatus;
SERVICE_STATUS_HANDLE FireServiceStatusHandle;
HANDLE hevent;
HANDLE hFile;
HANDLE ghTestEvent;
HANDLE ghIPCthread = NULL ;
void WINAPI ServiceMain(DWORD argc, LPTSTR* argv);
void ServiceInstall();
DWORD WINAPI Ipcthread(LPVOID lpParam);
void servicestop();
void WINAPI FireServiceHandler(DWORD dwctrl);
VOID CALLBACK ApcProc(ULONG_PTR dwparam)
{
}
void __cdecl _tmain(int argc, _TCHAR* argv[])
{
if(lstrcmpi(argv[1],TEXT("Install"))==0)
{
ServiceInstall();
return;
}
SERVICE_TABLE_ENTRY DispatchTable[] = {{TEXT("SampleService"),ServiceMain},{NULL,NULL} };
if(!StartServiceCtrlDispatcher(DispatchTable))
{
}
}
void WINAPI ServiceMain(DWORD argc, LPTSTR* argv)
{
FireServiceStatus.dwCheckPoint = 1;
FireServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN ;
FireServiceStatus.dwCurrentState = SERVICE_START_PENDING;
FireServiceStatus.dwServiceSpecificExitCode = 0;
FireServiceStatus.dwServiceType = SERVICE_WIN32;
FireServiceStatus.dwWaitHint = 3000;
FireServiceStatus.dwWin32ExitCode = 0;
FireServiceStatusHandle = RegisterServiceCtrlHandler(TEXT("SampleService"),FireServiceHandler);
if(!FireServiceStatusHandle )
{
goto cleanup;
}
if(!SetServiceStatus(FireServiceStatusHandle,&FireServiceStatus))
{
goto cleanup;
}
FireServiceStatus.dwCheckPoint = 0;
FireServiceStatus.dwCurrentState = SERVICE_RUNNING;
FireServiceStatus.dwWaitHint = 0;
FireServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN ;
SetServiceStatus(FireServiceStatusHandle,&FireServiceStatus);
ghIPCthread = CreateThread(NULL,0,Ipcthread,NULL,0,NULL);
servicestop();
cleanup:
FireServiceStatus.dwCheckPoint = 0;
FireServiceStatus.dwCurrentState = SERVICE_STOP;
FireServiceStatus.dwWaitHint = 0;
SetServiceStatus(FireServiceStatusHandle,&FireServiceStatus);
if( ghIPCthread == NULL)
{
QueueUserAPC(ApcProc,ghIPCthread,NULL);
ghIPCthread = NULL;
}
}
DWORD WINAPI Ipcthread(LPVOID lpParam)
{
HANDLE ghTestEvent;
TCHAR buf[50];
DWORD err;
hFile = CreateFile( TEXT("D:\\eventerror.txt"),
GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
ghTestEvent = CreateEvent(NULL,FALSE,FALSE,TEXT("Global\\sampleEvent"));
if(ghTestEvent == NULL)
{
wsprintf(buf,TEXT("CreateEvent failed %d"),GetLastError());
WriteFile(hFile,buf,sizeof(buf),NULL,NULL);
RtlZeroMemory(buf,sizeof(buf));
goto Cleanup;
}
err = WaitForSingleObject(ghTestEvent,INFINITE);
if( err == WAIT_FAILED)
{
wsprintf(buf, TEXT("WaitForSingleObject failed %d"),GetLastError());
WriteFile(hFile,buf,sizeof(buf),NULL,NULL);
RtlZeroMemory(buf,sizeof(buf));
goto Cleanup;
}
wsprintf(buf, TEXT("WaitForSingleObject Success:Got the event") );
WriteFile(hFile,buf,sizeof(buf),NULL,NULL);
RtlZeroMemory(buf,sizeof(buf));
Cleanup:
CloseHandle(ghTestEvent);
CloseHandle(hFile);
return err;
}
void ServiceInstall()
{
SC_HANDLE sc_manager;
SC_HANDLE sc_service;
TCHAR szPath[MAX_PATH];
if(GetModuleFileName(NULL,szPath,MAX_PATH))
{
printf("GetModuleFileName failed %d",GetLastError());
}
sc_manager = OpenSCManager( NULL,NULL,SC_MANAGER_ALL_ACCESS);
if(sc_manager == NULL)
{
printf("openSCManager failed with error code %d \n",GetLastError());
return;
}
sc_service = CreateService( sc_manager,
TEXT("SampleService"),
TEXT("SampleService"),
SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS,
SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL,
szPath,
NULL,
NULL,
NULL,
NULL,
NULL );
if( sc_service == NULL )
{
printf("Create service failed %d\n",GetLastError());
CloseServiceHandle(sc_manager);
return;
}
else
printf("service installed successfully\n");
CloseServiceHandle(sc_service);
CloseServiceHandle(sc_manager);
}
void WINAPI FireServiceHandler(DWORD dwCtrl)
{
switch(dwCtrl)
{
case SERVICE_CONTROL_SHUTDOWN:
case SERVICE_CONTROL_STOP:
FireServiceStatus.dwCheckPoint = 0;
FireServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
FireServiceStatus.dwWaitHint = 0;
FireServiceStatus.dwControlsAccepted = 0 ;
SetServiceStatus(FireServiceStatusHandle,&FireServiceStatus);
SetEvent(hevent);
break;
case SERVICE_CONTROL_INTERROGATE:
break;
default:
break;
}
return ;
}
void servicestop()
{
hevent=CreateEvent(NULL,TRUE,FALSE,NULL);
while(1)
{
WaitForSingleObject(hevent,INFINITE);
FireServiceStatus.dwCheckPoint = 0;
FireServiceStatus.dwCurrentState = SERVICE_STOPPED;
FireServiceStatus.dwWaitHint = 0;
SetServiceStatus(FireServiceStatusHandle,&FireServiceStatus);
return;
}
}</windows.h>
Console Application (Application 2)
#include<windows.h>
#include<stdio.h>
#include<tchar.h>
int main()
{
HANDLE ghEvent;
BOOL res;
ghEvent = OpenEvent( SYNCHRONIZE|EVENT_MODIFY_STATE , FALSE, TEXT("Global\\sampleEvent"));
if (ghEvent == NULL)
{
printf("error on opening the event %d ",GetLastError());
getchar();
return 1;
}
res = SetEvent(ghEvent);
if(!res)
{
printf("SetEvent failed,%d",GetLastError());
getchar();
return 1;
}
printf("SetEvent success\n");
return 0;
}
|
|
|
|
|
I'm working on an antivirus software application. I would like to know how can we send or install the updates to the client systems through sever system remotely using VC++ and COM. Is it possible without using COM??? I'm working on VC7.1
|
|
|
|
|
brucewayn wrote: I would like to know how can we send or install the updates to the client systems through sever system remotely using VC++ and COM. Is it possible without using COM??? I'm working on VC7.1
Please read the guidelines[^]. If you pin point a specific technical problem and ask how to solve it, someone may answer you.
But with this question, there won't be much of luck.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Thanks Rajesh for reminding me the guidelines however I truly feel that my question is straight forward. i would like to know how can we send or install the updates to the client systems through sever system remotely using VC++ and COM.I did try using Windows Management Instrumentation (WMI) however i realized that with WMI we can see the process in the client sever but we can't install the updates. I hope you had got some idea about what i required and i'm quite sure that you would come out with some good solution.
|
|
|
|
|
I would agree on the fact that the question is pretty much straight forward. I meant to tell that you have not even decided on an approach on how to go about it. But if the approach is what you wanted opinions on, then fair enough.
You mentioned that you wouldn't want to use COM in your original post, so you could try sockets? It does not look like a good idea if installation or some kind of 'push' activity happens from the server side. This design could be troublesome, as the client may not be ready all the time.
A better approach would be to make the client 'poll' for updates on a regular interval. If there is an update available, the client could request a download from the server, get it and do a ShellExecute() or something, as per the design to apply the latest updates.
This way, the user would get an option to specify when should the updates happen.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Hello !
I am working on an MFC dialog based project from past few days, today i tried to add a combobox ( or button , etc) to my dialog it gives the following message :
Add/Remove operation is impossible, because code element "MyDlg" is read only
i also checked the properties of my file, it was selected read only, i disabled it. Again i checked it it automatically selects to "Read only".
is there any solution to this problem !!
|
|
|
|
|
|
Hai all,
In my project I have used many dialog boxes. When I call tree control in one of the dialog boxes I get a Debug assertion failure (In dlgdata.cpp at the location ASSERT(!pDX->m_bSaveAndValidate); line number 636). Please any one help me.
Thanks and Regards
Bhanu
|
|
|
|
|
What are you trying to do ? Please, post some relevant code. Did you try debugging to see what is going on ?
|
|
|
|
|
Actually in my project I use 6 dialog. In one of my dialog I need to place CTreeCtrl. I created variable name for the control and when I run the program in debug mode, it shows Debug Assertion error like the above.
When I try to debug further, I just got struck up at the first line of the DoDataExchange and this is very strange to me.
If I debug further it shows error in the dlgdata.cpp file and m_hWnd is showing that "expression cannot be evaluated". I found that the error is occured when I set (true) the properties "Has Lines", "Has Buttons" and "Lines at root" of CTreeCtrl. Please help me.
|
|
|
|
|
bhanu_8509 wrote: I created variable name for the control
How did you do this ? When is the crash occuring exactly ?
|
|
|
|
|
I created the variable using the wizard. When I try to show the dialog the error occurs.
|
|
|
|
|
bhanu_8509 wrote: When I try to show the dialog the error occurs
How are you trying to do that ? Please post some usefull code (using the "code block" tag).
|
|
|
|
|
bhanu_8509 wrote: When I try to debug further, I just got struck up at the first line of the DoDataExchange and this is very strange to me.
You probably deleted a control after having created a control variable for it? May be DDX is trying to operate on a control that doesn't exist. Have you tried disabling that first line and compiling?
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
If I comment then it shows on the next line.
|
|
|
|
|
Why don't you try to analyse the problem? Have you verified that ALL the IDs that are listed in the DDX function actually exist?
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
bhanu_8509 wrote: When I try to debug further, I just got struck up at the first line of the DoDataExchange and this is very strange to me.
This is an indicator that you have a call to DDX_Control() for a non-existant control. Why not comment them all out and note the result?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
The debugger is not working?
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|