|
Thanks for your answer but I don't know the word for administrator in all the different languages where the application will be deployed.
There has to be an easier way.
Cathy
|
|
|
|
|
Try this
If it works, maybe its a good one for the FAQ
|
|
|
|
|
It works! Thanks!
It's not short though. You have to define SetPrivilege(...)
BOOL SetPrivilege(
HANDLE hToken, // access token handle
LPCTSTR lpszPrivilege, // name of privilege to enable/disable
BOOL bEnablePrivilege // to enable or disable privilege
)
{
TOKEN_PRIVILEGES tp;
LUID luid;
if ( !LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid ) )
{ // receives LUID of privilege
printf("LookupPrivilegeValue error: %u\n", GetLastError() );
return FALSE;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// Enable the privilege or disable all privileges.
AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL);
// Call GetLastError to determine whether the function succeeded.
if (GetLastError() != ERROR_SUCCESS)
{
printf("AdjustTokenPrivileges failed: %u\n", GetLastError() );
return FALSE;
}
return TRUE;
}
It's a common enough thing to have to do. I'm sure there must be some built in function somewhere.
|
|
|
|
|
Hi
OK - I didn't realize that SetPriviledge wasn't an API call - looks like you should work for Bill
I've messed it up a bit more, and humbly submit this orangey splotch of test level code, hastly hacked into an unsuspecting CMainFrame class:
BOOL CMainFrame::SetPriviledge(HANDLE hToken, LPCTSTR lpszPrivilege, BOOL bEnablePrivilege)
{
TOKEN_PRIVILEGES tp;
LUID luid;
if ( !LookupPrivilegeValue(
NULL,
lpszPrivilege,
&luid ) )
{
printf("LookupPrivilegeValue error: %u\n", GetLastError() );
return FALSE;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL);
int err = GetLastError();
if(0 != err)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0,
NULL
);
char buf[256];
sprintf(buf,"SetPriviledge failed:\n\n%s",lpMsgBuf);
MessageBox( buf, "Error", MB_OK | MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
return FALSE;
}
return TRUE;
}
void CMainFrame::OnAdminLookup()
{
HANDLE hToken;
if (!OpenProcessToken( GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES, &hToken) )
{
char buf[80];
sprintf(buf,"OpenProcessToken failed: %u\n", GetLastError() );
MessageBox(buf);
}
else {
if(!SetPriviledge(hToken,SE_TAKE_OWNERSHIP_NAME,TRUE)) {
}
}
}
With the FormatMessage thingy you should get a 1300 ERROR_NOT_ALL_ASSIGNED with the "Not all priviledges referenced are assigned to the caller." message displayed, for whatever that's worth.
Works on Win 2000 as well. Nice work.
|
|
|
|
|
Oh...I didn't do any work. I copied that function out of the MSDN topic "Take Object Ownership". I believe you referenced it in your post. You should submit your new and improved version to Microsoft. Then maybe you could go to work for Bill. Yes, I know you probably don't want to.
I'm going to try NetUserGetInfo(..) when I get back to that project. If it doesn't work out I'll use your new and improved version of SetPrivilege(...)I'll let you know so you can add it to the FAQ's page.
Thanks again for your help!
P.S.
How do you do the orange block of code in the forums?
|
|
|
|
|
Surround it with <pre> </pre> tags:
Jon Sagara
Sagara Software
|
|
|
|
|
Thanks! (sorry had to try it out)
Cathy
|
|
|
|
|
Hi
Just use the html <pre> and </pre> tags in your text - if you want < and > to actually show up, use < and >.
Yes, it looks like NetUserGetInfo is the way to go. I just did a test where I fired all the privileges at SetPriviledge and found about 5 that failed, so in a sense there might be a finer grain available here, but wadduino.
Guess originally it was a question of finding an alternative to NetUserGetInfo, so in that sense nothing lost!
Cheers
T
-----
Would anyone have a spare signature I could use?
|
|
|
|
|
Call NetUserGetInfo() with level 3.
Jon Sagara
Sagara Software
|
|
|
|
|
Thanks!
|
|
|
|
|
Hello all,
I need to determine if a given port number is available for a socket. Please correct me if I'm wrong, but I think the reserved port numbers are output by "netstat /a". I'm guessing there's something in Winsock that lets me test for a given port's availability, but I'm not sure. Can anyone suggest how I can do this? Thanks.
|
|
|
|
|
Its all a little fuzzy, but I think a call to bind should fail if the sockets local address + local port specified in the SOCKADDR is already in use.
Also, winsock has the ability to bind to a port generated for you (specify a 0 for port), which you can query with getsockname .
|
|
|
|
|
What is the MFC function call to allow a resouce dll to run within the context of an application without resource ID conflicts?
|
|
|
|
|
Use:
//every entry to the resource dll
HINSTANCE m_hInstOld = AfxGetResourceHandle();
AfxSetResourceHandle(extensionDLL.hResource);
//do stuff
//last call before returning in the resource dll
AfxSetResourceHandle(m_hInstOld);
Regards
Boris
|
|
|
|
|
Might need this as well...the extensionDll above is your extension module for the dll, eg the line given by
static AFX_EXTENSION_MODULE extensionDLL = { NULL, NULL };
above the main dll entry point, eg
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
Regards
Boris
|
|
|
|
|
Here's something that's puzzling me: the purpose of the callback function for AVISave is to update a Progress control with the percent done. But the callback function must be global or static, and only takes an int nPercent argument, so how can I access any Progress control or dialog member variables from this callback function??
*****
Jake Palmer
www.duke.edu/~jp6
|
|
|
|
|
I think you might get away with something similar to the following;
YourDialog.h:
class CYourDialog : ... {
static CYourDialog * pThis;
static LONG SaveCallback ( int nPercent );
};
YourDialog.cpp:
CYourDialog * CYourDialog::pThis = NULL;
CYourDialog::CYourDialog () {
pThis = this;
}
LONG CYourDialog::SaveCallback ( int nPercent ) {
}
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Recently, a new website about C++ started.
The site has very powerful databases, that will make you find what you are looking for in a matter of seconds!
The site has:
-> Tutorials
-> Code
-> News
-> Utilities/Tools
-> Links
-> Forums
-> Interviews with programmers
The users can also publish their own tutorials, code, link and tools. This is made by automatic process. So, the user just types the text, and some additional information, and his article gets online immediately!
Come!
The address is: www.cpp-home.com
If you want directly to access the forums, go to: http://forums.cpp-home.com
Thank You!
Ilia Yordanov,
www.cpp-home.com
|
|
|
|
|
Hi, I have a multiline edit box and I am trying to insert text into it, but when I insert one line it does not go to the next line, and anytime I add text afterwards it just keeps it all on one line. Any suggestions?
Marco
|
|
|
|
|
I had this problem for a while - if I am remembering correctly the solution is to NOT have the style AutoHScroll set. That should wrap at the end of each line instead of scrolling. Good luck!
*****
Jake Palmer
www.duke.edu/~jp6
|
|
|
|
|
CString l_sNewText;
between each line instead of '\n' add 13 and 10.
like this:
==========
l_sNewText= "1st line";
l_sNewText+= 13;
l_sNewText+= 10;
l_sNewText+= "2nd line";
l_sNewText+= 13;
l_sNewText+= 10;
l_sNewText+= "3rd line";
m_YourCEditControl.SetWindowText( l_sNewText);
==========
this definitely will work
The characters 13 and 10 works together as a new line(like '\n').
why is it like that and '\n'????
I really don't know!!!
Name: STR
Mission: Take Over The World (c:
Tips: If you build it, he will come.
More Tips: If you lick it, she will cum.
|
|
|
|
|
This function do not work, why...
CSpecialControl is derived from CWnd
BOOL CSpecialControl::Create(const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
BOOL Oktemp;
//after this line hbm is null, IDB_BITMAP1 is a valid resource...
//why it does'nt work? How I am supposed to use it?
HBITMAP hbm = ::LoadBitmap(NULL,MAKEINTRESOURCE(IDB_BITMAP1));
//this work
CBitmap MyBitmap;
MyBitmap.LoadBitmap( IDB_BITMAP1);
//this work
Oktemp = CWnd::Create
(NULL,_T(""),WS_CHILD|WS_CLIPCHILDREN, rect, pParentWnd, nID ,pContext);
//this work, I can see the button and catch his command
Oktemp &= m_cBouton_1.Create
(_T(""),WS_CHILD |BS_PUSHBUTTON|BS_BITMAP|WS_VISIBLE ,CRect(0,0,100,100),this,IDC_BUTTONGAUCHE);
//and the bitmap is never displayed on the button....
//do I have to set a different Style ti my button?
m_cBouton_1.SetBitmap(MyBitmap);
m_cBouton_1.ShowWindow(SW_SHOWNORMAL);
return Oktemp;
}
Remi Morin
Rmorin@Operamail.com
Remi.Morin@Lyrtech.com
|
|
|
|
|
> //why it does'nt work? How I am supposed to use it?
> HBITMAP hbm = ::LoadBitmap(NULL,MAKEINTRESOURCE(IDB_BITMAP1));
Use AfxGetInstanceHandle instead of NULL as the first parameter
|
|
|
|
|
The MyBitmap goes out of scope, so the bitmap is destroyed. Make the object a member variable so it stays around for the life of the control.
--Mike--
http://home.inreach.com/mdunn/
A recent survey reports that 1/4 of all internet users in England surf for porn.
The other 3/4 just didn't want to admit it.
|
|
|
|
|
Hello,
I am trying to populate a list control (report style) on "A" Dialog box from "B" Dialog.. can this be done? What I have tried so far is.. I setup a listbox on "A" and created a member function called Populate().. What I cant figure out is how can I use this Populate() function from the "B" Dialog box?
Any ideas?
Thanks,
RobJones
|
|
|
|
|