|
PS: in that example of his you have to type the path of a folder in the edit box, or it the empty field will cause it to crash.
|
|
|
|
|
can anyone help with this function parameters, i cant get them at all
"AdjustTokenPrivileges"
|
|
|
|
|
Security structures in the Windows API tend to be of the 'extensible array' type, where the last field is declared as an array of 1 element, but Windows will actually accept bigger arrays. You can consider the structure you declare as being a header for the full structure.
Let's say, for the sake of argument, that you want to disable the SE_TAKE_OWNERSHIP_NAME privilege (which permits the principal to change the owner of a resource, even if they don't have Write Owner access) and the SE_DEBUG_NAME privilege, which permits the principal to debug processes they don't own.
You would write something like the following:
DWORD dwPrivsSize =
sizeof( DWORD ) + 2 * sizeof( LUID_AND_ATTRIBUTES );
TOKEN_PRIVILEGES* pPrivsIn =
(TOKEN_PRIVILEGES*) malloc( dwPrivsSize );
pPrivsIn->PrivilegeCount = 2;
LookupPrivilegeValue(
NULL,
SE_TAKE_OWNERSHIP_NAME,
&( pPrivsIn->Privileges[0].Luid )
);
LookupPrivilegeValue(
NULL,
SE_DEBUG_NAME,
&( pPrivsIn->Privileges[1].Luid )
);
pPrivsIn->Privileges[0].Attributes = 0;
pPrivsIn->Privileges[1].Attributes = 0;
HANDLE hToken = NULL;
OpenThreadToken(
GetCurrentThread(),
TOKEN_ADJUST_PRIVILEGES,
FALSE,
&hToken
);
AdjustTokenPrivileges(
hToken,
FALSE,
pPrivsIn,
dwPrivsSize,
NULL,
NULL
);
CloseHandle( hToken );
free( (void*) pPrivsIn ); You should save the previous state of the privileges somewhere if you want to re-enable them later. You should also check the return values of all the functions called - this is especially critical in security code.
No warranties for the above code; I just typed it straight into CP's editor
On Server 2003, you can specify SE_PRIVILEGE_REMOVED for the attributes to cause AdjustTokenPrivileges to remove the privileges from the token permanently - they cannot be re-enabled except by creating a new token.
|
|
|
|
|
Hi im writing a dialog based program in mfc ive made a large icon for it and it displays fine for the exe however if i add the program to my quick launch or go to it in a file dialog it shows the default mfc small icon how do i set the small icon for the exe? the regular icon works fine within the program on the system menu so whats the deal why isnt the exe's small icon being set?
Thanks
|
|
|
|
|
In the VC++6 ide, bring up your icon in the resource editor then click on the combo box next to where it says "Device:" above the icon you have open.
Now select Small (16X16) and edit it to your liking.
|
|
|
|
|
Hi
Anyone knows a fn that shut down the pc?!
thanks in advance
|
|
|
|
|
ExitWindowsEx() is the way to go
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks but i tried it, but it only causes the pc to log off, i'm trying it with win XP...
|
|
|
|
|
ExitWindowsEx(EWX_POWEROFF,0)
Here are some notes about using it:
Shuts down the system and turns off the power. The system must support the power-off feature.
Windows NT/2000/XP: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.
Windows NT/2000/XP: To shut down or restart the system, the calling process must use the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege.
John
|
|
|
|
|
There is a framework in MFC where you dont create an SDI or MDI . What I mean is you start off the project with as an MDI but remove the view classes .
This is the MSDN article
HOWTO: Add Multiple Window Types to a Non-Document/View MDI App
ID: Q201045
From within a ChildView how can one manipulate the Toolbar buttons ?
|
|
|
|
|
I think my last post wasn't understandable.
I am trying to create a function that can accept any type of an array as a paramater.
char[] or double[] or int[] etc.
wouldn't it be myFunction(void *data){ do stuff }
char tmp[100];
myFunction(tmp);
I hope this makes sense.
Steven
|
|
|
|
|
Yes that would work, but once inside your function, you have to know what type of array has been passed. You could do something like this:
<code>
enum TYPES
{
CHAR,
DOUBLE,
INT,
...other types...
};
void myFunc(void* data, int data_type)
{
switch (data_type)
{
case CHAR: char* carray = (char*)data;
.... do stuff
break;
case DOUBLE: double* darray = (double*)data;
...etc.
}
...
}
</CODE>
You will probably also want to add a size parameter to myFunc as well, unless all your arrays will be a fixed size.
--Dean
|
|
|
|
|
|
Not being funny, or mean to be offensive, but that's about the worst solution I could imagine in C++.
* it requires massive amounts of work if you wish to add a new type.
* it's still not typesafe - you can't validate what's passed in
* and there are far far better approaches in C++ (eg, templates)
--
Ian Darling
If I was any more loopy, I'd be infinite.
|
|
|
|
|
Yes, I agree -- it's quick, dirty, ugly... I get the feeling though that going into something like templates would not have been understood if the above could not have been done without help from this board (no offense meant to anyone).
I try to approach these things from the standpoint that a less elegant but easier to understand solution might better serve beginners. Then, at a later time, the better way to do something can be learned when the supporting knowledge is available. A fine line has to be drawn however, as the easy code might be a terrible way to do things. I suppose I should have added a disclaimer saying that there are better ways of doing things. With that said, I hadn't even thought about templates at the time
--Dean
|
|
|
|
|
|
What's wrong with templates?
template<class T> void MyFunction(T* start, T* end)
{
for(T* iter=start; iter <= end; iter++)
{
cout << *iter;
}
}
char temp [100];
MyFunction(temp, &temp[99]);
The beauty of this approach is that it works with things that provide iterators such as std::vector, as well as standard arrays. Untested code, so YMMV.
--
Ian Darling
If I was any more loopy, I'd be infinite.
|
|
|
|
|
template <typename ForwardIter> void MyFunction(ForwardIter start, ForwardIter end)
{
while(start != end) {
doSomething(*start);
++start;
}
}
char temp[100];
MyFunction(temp, temp + 100); Would be a cleaner solution, as your will only work with std::vector . This'll work with any iterator.
--
Gnnnnmmmpppppppfffffhhh!
|
|
|
|
|
Like I said, untested code, and I'm a little rusty on C++ templates, but I figured it was essentially ok, and certainly illustrated what I wanted to suggest.
--
Ian Darling
If I was any more loopy, I'd be infinite.
|
|
|
|
|
[EDIT]
Sorry did not read all the posts, but this problem screams for a template approach...
[/EDIT]
template<class T>myFunction(T* data)
{
}
int main()
{
char tmp[100];
float fTmp[1000];
myFunction<char>(tmp);
myFunction<float>(fTmp);
}
John
|
|
|
|
|
Hi,
I use the function ShellExecute to open a PDF-file from my c++-programm (ActiveXControl). I want to highlight one word on the pdf-file. Can I do this with ShellExecute or have you another idea how I can realize that.
Julia
|
|
|
|
|
In my SDI application , I have a ToolBar with 10 buttons .
I am unable to Change the text displayed in this Button .
I named the button ID_NEWBUTTON and have a event handler in CMainFrame.
I tried to change the text in the Toolbar button using
m_wndToolBar.SetButtonText(m_wndToolBar.CommandToIndex(ID_NEWBUTTON),"Please change text");
Still nothing seems to be happenning ?
|
|
|
|
|
How can I programatically change the Color of a ToolBar ?
|
|
|
|
|
Hi,
try this
<br />
SetClassLong(m_wndToolBar.m_hWnd, GCL_HBRBACKGROUND, (LONG)::GetStockObject(WHITE_BRUSH));<br />
Regards
|
|
|
|
|
I have an SDI framework where my Chidlview creates many Dialogs within itself .
I want to trap a keyboard entry in one of the dialogs . For this I went to ClassView and added the event Handler with a dummy AfxMessageBox
This event is not getting fired ? Suggestions are needed .
|
|
|
|