Re: PostMessage return access denied
Yes, it's running. I've verified the error using "FormatMessage" as
well. I'm using following code to run "osk.exe" (please ignore memory
leak stuff)
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
SID_IDENTIFIER_AUTHORITY siaWorld = SECURITY_WORLD_SID_AUTHORITY;
PSID psidEveryone=NULL;
PACL pAcl=NULL;
INT iAclLength=0;
sa.nLength=sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle=FALSE;
if(!InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION))
{
MessageBox(L"Unable to initialize SD");
return ;
}
if(!AllocateAndInitializeSid(&siaWorld,1,SECURITY_WORLD_RID,
0,0,0,0,0,0,0,&psidEveryone))
{
MessageBox(L"Unable to initialize SID");
return ;
}
iAclLength=sizeof(ACL)+(sizeof(ACCESS_ALLOWED_ACE)-sizeof(DWORD))
+GetLengthSid(psidEveryone);
pAcl=(PACL)LocalAlloc(LPTR,iAclLength);
if(!pAcl)
{
MessageBox(L"Unable to allocate memory");
return ;
}
if(!InitializeAcl(pAcl,iAclLength,ACL_REVISION))
{
MessageBox(L"Unable to init ACL");
}
if(!AddAccessAllowedAce(pAcl,ACL_REVISION,GENERIC_ALL,psidEveryone))
{
MessageBox(L"Unable to add ACE");
return ;
}
if(!SetSecurityDescriptorDacl(&sd,TRUE,pAcl,FALSE))
{
MessageBox(L"Unable to set DACL");
return ;
}
sa.lpSecurityDescriptor=&sd;
TCHAR path[MAX_PATH];
STARTUPINFO sInfo;
PROCESS_INFORMATION pInfo;
memset(&sInfo,0,sizeof(STARTUPINFO));
memset(&pInfo,0,sizeof(PROCESS_INFORMATION));
sInfo.cb=sizeof(STARTUPINFO);
sInfo.dwFlags=STARTF_USESHOWWINDOW;
sInfo.wShowWindow=SW_SHOW;
GetSystemDirectory(path,MAX_PATH);
PathAppend(path,L"OSK.EXE");
BOOL
bResult=CreateProcess(NULL,path,&sa,&sa,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&sInfo,&pInfo);
if(!bResult)
{
MessageBox(L"Unable to create process");
}
On Jun 4, 6:41 pm, Joseph M. Newcomer <newco...@flounder.com> wrote:
See below....
On Mon, 04 Jun 2007 05:29:28 -0700, Gurmit Teotia <gurmits...@gmail.com> wrote:
HWND hKbd=::FindWindow(L"OSKMainClass",NULL);
if(hKbd)
{
if(!::PostMessage(hKbd,WM_QUIT,0,0))
{
TCHAR msg[100];
DWORD error=GetLastError();
wsprintf(msg,L"Unable to terminate process %d",error);
MessageBox(msg);
****
DWORD error = ::GetLastError();
CString msg;
msg.Format(_T("Unable to terminate process: %d"), error);
AfxMessageBox(msg);
You should try to avoid ever getting into a situation in which wsprintf makes sense.
I'm as perplexed as you are, though. You are clearly getting a non-NULL window handle,
there are no addresses being passed in the WM_QUIT message, and according to the Vista
documentation, PostMessage that violates the access rights issue will still return TRUE,
it is just going to lie about succeeding.
You're sure this program is actually running? I could imagine an error where the message
queue hasn't been created yet, but that doesn't seem sensible in this case.
Thus far, I've not seen PostMessage fail in Vista, but I've not been using it long.
Unfortunately, I probably won't have time for at least a month to check this out.
joe
*****
}
}
In message box I'm getting "Unable to terminate process 5".
Regards,
Gurmit
On Jun 4, 5:14 pm, Joseph M. Newcomer <newco...@flounder.com> wrote:
Show the code and the way you ascertained the access-denied error.
joe
On Mon, 04 Jun 2007 04:33:58 -0700, Gurmit Teotia <gurmits...@gmail.com> wrote:
Hello,
I've started osk.exe in other process using "CreateProcess" and I want
to terminate it by posting a WM_QUIT message to it. Earlier I used to
pass NULL in "SECURITY_ATTRIBUTES" parameter but after reading
documentation about Vista I added "GENERIC_ALL" ACE in ACL, which I'm
using in SECURITY_ATTRIBUTES. I'm still get access denied error. Could
some one please expaing how I can terminate the process in Vista?
Regards,
Gurmit
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm- Hide quoted text -
- Show quoted text -