|
i have wrote code logon admin in limited user like the following
****************************************************************
BOOL CEKLoaderDlg::OnLogonUser()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
HANDLE hToken;
LPCTSTR lpszPrivilege = "SeTcbPrivilege";
BOOL bEnablePrivilege = TRUE;
BOOL bDisEnablePrivilege = FALSE;
LPDWORD lpExitCode;
char* username = "administrator";
char* password = "xxx";
char* cmdLine = "cmd.exe";
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
static LUID luid;
static TOKEN_PRIVILEGES tp;
if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
{
AfxMessageBox("OpenProcessToken() error \n");
}
else
// AfxMessageBox("OpenProcessToken() is OK\n");
//********************* Enabling (Disabling) privilege ***************************
// Call the user defined SetPrivilege() function to enable privilege
if( SetPrivilege(hToken, lpszPrivilege, bEnablePrivilege))
{
if(LogonUser(username,".",password,LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT,&hToken))
{
if(ImpersonateLoggedOnUser(hToken))
{
if(CreateProcessAsUser(hToken,0,cmdLine,0,0,FALSE,NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW,0,0,&si,&pi))
{
// editbootini();
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
TerminateProcess(hToken,0);
return TRUE;
}
else
{
AfxMessageBox("Failed");
}
// Cleanup...
if( pi.hProcess != NULL )
CloseHandle( pi.hProcess );
if( hToken != NULL )
CloseHandle( hToken );
}
}
else
{
AfxMessageBox("Administrator password is wrong");
exit(0);
}
}
SetPrivilege(hToken, lpszPrivilege, bDisEnablePrivilege);
return TRUE;
}
Then wrote code for restart like the following
*********************************************
m_stcCalling.SetWindowText("Restarting Your System");
AfxEnableControlContainer();
HANDLE hToken; // handle to process token
TOKEN_PRIVILEGES tkp; // pointer to token structure
BOOL fResult;
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
*******************************************//return failure
{
log("Error Type : Error in Restarting");
log("Severity Level : Critical");
return FALSE;
}
// Get the LUID for shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
fResult =InitiateSystemShutdown(NULL, "System is being restarted ", 0, TRUE, TRUE);
if (!fResult)
{
fResult = GetLastError();
log("Error Type : Restarting Failed");
log("Severity Level : Critical");
return FALSE;
}
return 1;
}
But restart wont done .why?
|
|
|
|
|
Please indent the code and use appropriate tags for the code blocks. It is very difficult to read your code.
Regards,
Sandip.
|
|
|
|
|
What function is failing? Have you bothered to use the debugger to find out what is going on?
"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
|
|
|
|
|
When I delete the code of a class's menber function, the class view cann't flash, why?
Thanks!
|
|
|
|
|
Why would the "class view" flash?
"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
|
|
|
|
|
Hi all,
I have made a application on VC-2005. Now my problem is its not working on windows-2003, i.e when i click on exe nothing happens...
Why my exe is not working on windows-2003...
Can anybody help me in this?
Thanks in advance
|
|
|
|
|
|
|
Try installing it. That installation is necessary if we want to run a VS 2005 exe in a OS where Visual studio 2005 is not installed.
Also confirm that you are trying to run the release version of the binaries.
|
|
|
|
|
Naveen wrote: That installation is necessary if we want to run a VS 2005 exe in a OS where Visual studio 2005 is not installed.
Isn't it sufficient to create an installation along with necessary dlls found in the Program Files\Microsoft Visual Studio 8\VC\redist\x86 folder?
Have you tried out this way? Just curious.
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
I havent tried that way. Since those binaries are implemented as side-by-side assemblies, I guess it will be little difficult to include them in the installation.
|
|
|
|
|
I am making a chat application. I need to send & recieve emoticons/smileys. I am getting their codes. What to do to retireve the smileys properly
Thanks In advance
Dhiraj
|
|
|
|
|
What do you mean exactly ? Emoticons are just a specific combination of symbols (e.g. : and ) ). Those symbols are then interpreted by your application and replaced by a small image representing the emoticon. But you have to do that yourself.
|
|
|
|
|
Thanx! I will try to do it.
|
|
|
|
|
Hi all,
I have made a simple text file using CStdioFile object and writing and reading strings using that file and saved it using different file extension suppose .ehn. Now i want to hide this file i.e it must be shown when i click on folder option show hidden files and folder...
how can i do this......
thanks in advance
|
|
|
|
|
Use the api - SetFileAttributes() by passing FILE_ATTRIBUTE_HIDDEN as parameter.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
|
I have a dialog-based application that contains a combo box.
I've subclassed the combo box like this :
HBRUSH CSubClassedComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if (nCtlColor == CTLCOLOR_EDIT)
{
if (m_CmbEditBox.GetSafeHwnd() == NULL)
m_CmbEditBox.SubclassWindow(pWnd->GetSafeHwnd());
}
else if (nCtlColor == CTLCOLOR_LISTBOX)
{
if (m_CmbListBox == NULL)
{
m_CmbListBox = new CListBoxEx;
if (m_CmbListBox->GetSafeHwnd() == NULL)
{
m_CmbListBox->SubclassWindow(pWnd->GetSafeHwnd());
}
}
}
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
return hbr;
}
m_CmbEditBox and m_CmbListBox are objects of CEdit and CListBoxEx(derived from CListBox) respectively
and declared in SubClassedComboBox.h as the class CSubClassedComboBox's members.
During run-time of my application, I pull down the list box and right-click on any of the
list box items. My control reaches here :
void CListBoxEx::OnContextMenu(CWnd* pWnd, CPoint point)
{
GetParent->TestFn();
}
Now, in CListBoxEx::OnContextMenu, I want to call a member function ( say TestFn() ) available in class CSubClassedComboBox.
Please see the following code :
void CListBoxEx::OnContextMenu(CWnd* pWnd, CPoint point)
{
((CSubClassedComboBox *)GetParent())->TestFn();
GetParent())->TestFn();
}
As in the comments, the second statement doesn't work. I don't want to cast the pointer returned
by GetParent() to CSubClassedComboBox * bcoz this wouldn't be in generic sense.
By this, I mean to say that GetParent() should be able to give the parent pointer which is
CSubClassedComboBox * in this case, but could be anything else (eg. another container window that contains
the CListBoxEx object).
In summary,
GetParent()->TestFn(); should call TestFn() of CSubClassedComboBox as per the requirement above.
But GetParent())->TestFn(); should be able to call TestFn() of say CSubClassedSomeContainerWindow
if m_ListBox is a member of CSubClassedSomeContainerWindow
So, I am looking for a solution that is generic, to find the parent.
Any help would be appreciated.
Thanks in advance.
|
|
|
|
|
SherTeks wrote: So, I am looking for a solution that is generic, to find the parent.
If I understood your question properly...
Define a message for your parent class, for e.g. WM_TEST_FN . So all the parent needs to do is define a handler for this message. So if the handler is there then the function will be called.
So then you can use SendMessage to send this message.
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
ok. You won this time
|
|
|
|
|
Naveen wrote: ok. You won this time [Frown]
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Thanks for your reply.
May be I need to make my question a bit more clearer.
Just assume that my dialog application has 2 controls : 1) a Combo Box and 2) another container control similar to
combo box (but not exactly combo box).
The common trait between the two controls is that they both embed the list box object derived from CListBoxEx.
Now, I could right-click on any one list box at a particular point of time during run-time.
The right-click would bring the control to the OnContextMenu of CListBoxEx::OnContextMenu. In this place, I should be
able to identify the parent ie. either control 1) or 2) using GetParent(). But the only condition is that I shouldn't
cast the pointer returned by GetParent() to any of the parent control pointers ie. GetParent()->TestFn() must call
the TestFn() member function of the appropriate control of which the list box was right-clicked.
Thanks
|
|
|
|
|
SherTeks wrote: But the only condition is that I shouldn't
cast the pointer returned by GetParent() to any of the parent control pointers ie. GetParent()->TestFn() must call
the TestFn() member function of the appropriate control of which the list box was right-clicked.
Well you don't need any casting right if you are using messages. Take a look...
GetParent()->SendMessage( WM_TEST_FN, SomewParam, SomelParam );
Now all the parent class needs to do is add a message map entry to handle this event.
BEGIN_MESSAGE_MAP(...)
ON_MESSAGE( WM_TEST_FN, TestFn)
END_MESSAGE_MAP()
TestFn signature should look like this...
LRESULT TestFn( WPARAM wParam, LPARAM lParam );
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Correction : In my previous post, please consider m_CmbEditBox as of type
CEditEx and not of type CEdit.
My exact requirement is like this :
On right-clicking the list box item the control reaches
CListBoxEx::OnContextMenu. Please see the comment :
void CListBoxEx::OnContextMenu(CWnd* pWnd, CPoint point)
{
GetParent()->TestFn();
}
What am I doing wrong for list box bcoz the same mechanism for the child
edit box of the CSubClassedComboBox works fine ie.
void CEditEx::OnContextMenu(CWnd* pWnd, CPoint point)
{
GetParent()->TestFn();
}
Is there anything to do with the temporary creation of the list box which
is not the case with edit box ? If so, how could I acquire the desired result ?
Thanks
|
|
|
|
|
One method is to send a USER message to the parent window and you should write a ahndler for that message in the parent window instead of TestFn(). And offourse it is generic.
|
|
|
|