|
Hi,
Does anyone know the function that allows a running application to be closed and re-started?
Is it possible to run this function from within the application I'd like restarted?
Thanks in advance
|
|
|
|
|
In a word, no. If you are calling it from your own application, you could call GetModuleFileName to get your EXE name, then CreateProcess to reexecute you, then PostQuitMessage to shut yourself down.
If you want to do it to someone else, then you will need to find the window that you wish to kill, get the related process name for that window, post a WM_CLOSE to that window, or a WM_QUIT to that window's thread, then restart the app.
There isn't, AFAIK, a function that does all this for you.
|
|
|
|
|
Thanks for the reply.
Decided to go antoher route. Just about to implement and test.
|
|
|
|
|
Hi All
Does any one, know of a way to detect if a user is logged to his/her
pc with administrative rights ?
thanks
Simon
|
|
|
|
|
Like this:
BOOL IsAdministrator(void)
{
BOOL fRet = TRUE;
HANDLE hProcess = INVALID_HANDLE_VALUE;
HANDLE hAccessToken = INVALID_HANDLE_VALUE;
UCHAR InfoBuffer[1024] = {0};
PTOKEN_GROUPS ptgGroups = (PTOKEN_GROUPS)InfoBuffer;
DWORD dwInfoBufferSize = 0;
PSID psidAdministrators = NULL;
SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
UINT x = 0;
hProcess = GetCurrentProcess();
if(!OpenProcessToken(hProcess,TOKEN_READ,&hAccessToken))
return(FALSE);
if(!GetTokenInformation( hAccessToken,TokenGroups, InfoBuffer, 1024, &dwInfoBufferSize))
return(FALSE);
fRet = AllocateAndInitializeSid(
&siaNtAuthority, 2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0, &psidAdministrators);
if (!fRet)
return(FALSE);
for(x = 0; x < ptgGroups->GroupCount; x++)
{
if(EqualSid(psidAdministrators, ptgGroups->Groups[x].Sid))
{
FreeSid(psidAdministrators);
return(TRUE);
}
}
FreeSid(psidAdministrators);
return(FALSE);
}
Which will return true if the current user is a member of BUILTIN\Adminstrators group or false otherwise
|
|
|
|
|
IsUserAnAdmin[^] will test whether the user is a member of the Administrators group. This is one of the Settlement Program Interfaces[^], so you may need to use LoadLibrary and GetProcAddress to use it.
However, this only works well in the default environment. An administrator may have assigned rights to other user accounts or groups to give them raised privileges. A better way is simply to try whatever operation needs to be performed, and handle any access-denied errors that occur.
|
|
|
|
|
|
Maybe it was only ever exported by ordinal.
The Settlement Program is something that came out of the anti-trust suit: this is one of the 'revealed' APIs. If you get hold of a recent Platform SDK (December 2002 or later, currently at February 2003), you'll find this function in ShlObj.h. I assume that the appropriate import library (shell32.lib?) contains the necessary import to call the function.
I stand by my earlier statement that this is the wrong way to do it anyway.
|
|
|
|
|
Hello all:
can any one please help me how can I get HGLOBAL for the data contained in CRichEditCtrl ,I've to strore the data as BLOB and the class i am using for BLOB need HGLOBAL for that data..please help me in this context...
Muhammad Ahmed
ahmed
|
|
|
|
|
Use CRichEditCtrl::StreamOut() and write your own stream callback function, in that you copy raw bits from rich edit control to HGLOBAL .
See the EDITSTREAM and CRichEditCtrl documentation for details.
Robert-Antonio
|
|
|
|
|
thanks alot brother..you solved the problem almost 95 %
Regards
Muhammad Ahmed
ahmed
|
|
|
|
|
the callback function is called, passing the data in segments, so should i allocate memory on the heap for each call and the integrate the whole data in a newly allocated memory or is there a way to keep appending data to the buffer allocated only once....(or is there a way to find in advance how much buffer we should have?)
thanks
ahmed
|
|
|
|
|
The callback function takes the cb parameter, which contains required size of CRichEditCtrl data. You can grow the HGLOBAL memory with GlobalRealloc .
Robert-Antonio
|
|
|
|
|
hello every body
I want to know how can i end an sdi application like what we do in the Dialog application by calling CDialog::OnOk()
Best Regards
|
|
|
|
|
I believe the best practice is to post a WM_CLOSE message to your CFrameWnd-derived object. Something like that: AfxGetMainWnd()->SendMessage(WM_CLOSE);
|
|
|
|
|
thank u for it is working now
Best Regards
|
|
|
|
|
Hi!
I want in my program to be able to input text into an edit control and instead of having to move the mouse and click on the button to get the text input, I want it so that when you press enter, rather than closing the dialog, it will work the same as clicking on the button.
Can someone please help?
Thankyou
Ashman
|
|
|
|
|
I have done this some time ago. I don't know exactly how I have done it anymore, but I think I have used CWnd::PreTranslateMessage. If you overload it in your dialog class you can capture the key event before it is sent to the window!
|
|
|
|
|
Hi
I think to deactivate Enter Key u have to cancel OnOk() in the virtual member function like the following:
//////////////////////////////////////////////
void CanyDlg::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
//////////////////////////////////////////////
Best Regards
|
|
|
|
|
Capture the WM_COMMAND message for your default button (lets say here your default button has the ID IDOK) by overriding the relavant function, CYourDialog::OnOk in this case, then rather than calling the base CDialog::OnOk, move the focus to your edit control, either like this:
GetDlgItem(IDC_MY_EDIT_CTRL)->SetFocus();
Or like this:
SendMessage(WM_NEXTDLGCTL, (WPARAM)GetDlgItem(IDC_MY_EDIT_CTRL)->GetSafeHWnd(), TRUE);
The difference between them is the second is usually more suited to moving the keyboard focus around a dialog box as it updats the button borders correctly, so in full:
void CMyDialog:::OnOk()
{
if(CWnd::GetFocus() == GetDlgItem(IDC_MY_EDIT_CTRL))
{
// edit control focused, so do normal stuff
CDialog::OnOk();
}
else
{
// move focus to edit control
SendMessage(WM_NEXTDLGCTL, (WPARAM)GetDlgItem(IDC_MY_EDIT_CTRL)->GetSafeHWnd(), TRUE);
}
}
This will make enter move the focus to the edit control if something other than the edit control is foucsed, or make enter behave as normal if it is the edit control that's focused
|
|
|
|
|
That's all U need in MFC. I know very similar solution in win32sdk. If U need tell?
Cheers!
Siddharth
|
|
|
|
|
hi Ashman,
all you have to do is to set the focus on the specific control... you can use
(CEdit*)GetDlgItem(YOUR_Edit_ID))->SetFocus(); to avoid you to move explicitly your mouse upon the EditBox, and in the OnInitDialog() , you tell which button to be pressed when the user presses Enter key by giving it the property Default
TOXCCT
|
|
|
|
|
I want to initialize a executable, making OS to search for the file.
STARTUPINFO si = {sizeof(si)};<br />
PROCESS_INFORMATION pi;<br />
TCHAR szCommandLine[1024] = {0},*pszCommandLine = 0;<br />
<br />
DWORD lFileName = <br />
SearchPath(NULL,(LPCWSTR)"YPager",(LPCWSTR)".exe",(DWORD)sizeof(szCommandLine), szCommandLine, *pszCommandLine);<br />
<br />
BOOL bCreate = CreateProcessNULL,szCommandLine,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);
there is no complier error but szCommandLine cannot fill the path.
Any other suggestions to achieve the same goal is appreciated.
Cheers!
Siddharth
|
|
|
|
|
It will not help you to get a response faster!
|
|
|
|
|
There was a bit problem with my server. Hence it's like that. Any way sorry if anyone get anoyed
|
|
|
|