|
Can someone help me out.. I am trying to get hToken so that I can call CreateProcessAsUser inorder to install software as the specified domain user with admin rights on the local box.. when I run this code in the debugger I always get a "LogonUser failed. Error = 522".. I am running this code on a windows 2k box, I havent tried a NT box Any ideas?
ULONG CInstAdminDlg::Impersonate()
{
ULONG iLastError = 0;
HANDLE hToken = 0;
char *szUserName = "rjones";
char *szDomain = "mydomain";
char *szPassword = "mypassword";
DWORD dwSize = 50+1;
char szUser[50+1]={0};
GetUserName(szUser, &dwSize);
OutputDebugString("*** Before ImpersonateLoggedOnUser: ");
OutputDebugString(szUser);
OutputDebugString("\n");
LUID Luid;
if(!LookupPrivilegeValue(NULL, SE_TCB_NAME, &Luid))
{
OutputDebugString("LookupPrivilegeValue failed.\n");
iLastError = GetLastError();
goto Exit;
}
HANDLE hProcToken;
if(!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY|TOKEN_DUPLICATE, &hProcToken))
{
OutputDebugString("OpenProcessToken failed.\n");
iLastError = GetLastError();
goto Exit;
}
TOKEN_PRIVILEGES TokenPriv;
TokenPriv.PrivilegeCount = 1;
TokenPriv.Privileges[0].Luid = Luid;
TokenPriv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED ;
if(!AdjustTokenPrivileges(hProcToken, FALSE, &TokenPriv, 64, NULL, NULL))
{
OutputDebugString("AdjustTokenPrivileges failed\n");
iLastError = GetLastError();
goto Exit;
}
if (!LogonUser(szUserName, szDomain, szPassword, LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT, &hToken))
{
OutputDebugString("LogonUser failed.\n");
iLastError = GetLastError();
goto Exit;
}
if (!CreateProcessAsUser(
hToken,
"C:\\CodeProjectSearchBar.exe",
NULL,
NULL,
NULL,
TRUE,
NULL,
NULL,
NULL,
NULL,
NULL
))
{
OutputDebugString("Process failed.\n");
iLastError = GetLastError();
goto Exit;
}
RegCloseKey(HKEY_CURRENT_USER);
Exit:
if (iLastError)
{
char szErr[64];
sprintf(szErr,"Error = %x\n",iLastError);
OutputDebugString(szErr);
}
return iLastError;
}
|
|
|
|
|
You are passing NULL for both the STARTUPINFO and PROCESS_INFORMATION parameters. This is not possible, you have to initialize a STARTUPINFO struct and pass it to CPAU and also to retrieve the process information via a PROCESS_INFORMATION struct.
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
Something has happend to my workspace, so each time when i change something in the resource menu's toolbar's or dlg's and rebuild an error says that it was unable to find a TLB file.
in the RC file - look's like this
1 TYPELIB "MCTRACK.tlb"<br />
#endif // not APSTUDIO_INVOKED
When the line is removed everythings oki until you change in the resources again.
This is very anoying... someone how know whats wrong... I have looked the workspace settings trough, but could not find anything..??
Hmm...
|
|
|
|
|
Most likely you have a line elsewhere in the .rc file that looks something like this:
"1 TYPELIB ""MCTRACK.TLB""\r\n"
If that is the case, you can comment out that line as well.
A much better proposition would be to modify the path so that it can find the file. It was put there for some reason, right?
John
|
|
|
|
|
You where rigth.. it helped a lot..thank's
And it came in there or put in there,when the project where, by mistake openede in VC7..
Hmm...
|
|
|
|
|
how can i get the width and the height of the jpeg file??
I found this article in microsoft.com. but i don't know and can't find what is CHECKJPEGFORMAT ???
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_6145.asp
<br />
<br />
<br />
ul = CHECKJPEGFORMAT;<br />
<br />
if (<br />
<br />
(ExtEscape(hdc, QUERYESCSUPPORT,<br />
sizeof(ul), &ul, 0, 0) > 0) &&<br />
<br />
<br />
(ExtEscape(hdc, CHECKJPEGFORMAT,<br />
pvJpgImage, nJpgImageSize, sizeof(ul), &ul) > 0) &&<br />
<br />
<br />
(ul == 1)<br />
)<br />
{<br />
<br />
memset(&bmi, 0, sizeof(bmi));<br />
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);<br />
bmi.bmiHeader.biWidth = ulJpgWidth;<br />
bmi.bmiHeader.biHeight = -ulJpgHeight;
bmi.bmiHeader.biPlanes = 1;<br />
bmi.bmiHeader.biBitCount = 0;<br />
bmi.bmiHeader.biCompression = BI_JPEG;<br />
bmi.bmiHeader.biSizeImage = nJpgImageSize;<br />
<br />
<br />
iRet = StretchDIBits(hdc,<br />
ulDstX, ulDstY, ulDstWidth, ulDstHeight,<br />
0, 0, ulJpgWidth, ulJpgHeight,<br />
pvJpgImage,<br />
&bmi,<br />
DIB_RGB_COLORS,<br />
SRCCOPY);<br />
<br />
if (iRet == GDI_ERROR)<br />
return FALSE;<br />
}<br />
else<br />
{<br />
}<br />
|
|
|
|
|
try any of the image classes on this site. finding dimensions of a JPG is not a trivial task, due to the way they're encoded.
-c
Though the cough, hough and hiccough so unsought would plough me through,
enough that I o'er life's dark lough my thorough course pursue.
--Stuart Kidd
|
|
|
|
|
try libjpeg, http://www.ijg.org/
|
|
|
|
|
I thought I had read something about a tri-state control but not sure if it was a button. I would like to have a push button that stays down when you click it until you click it again and then it would pop up. Of course, I would change the bitmap on the button so that the user would know what state it is in.
Anyone know if this is possible?
|
|
|
|
|
See this class/exaple here at codeproject.
Sonork 100.15206;PavelK
|
|
|
|
|
Ok. I'll look into it. Thanks.
|
|
|
|
|
I cant find this addressed anywhere. If I want to assign an incoming function parameter set1 to a member set m_set can I do :
m_set = set1
or do I have to iterate through them ? Thanks,
ns
|
|
|
|
|
I think this depends on whether the operator "=" is overloaded for your specific class. If so, no itemration is necessary.
|
|
|
|
|
Can't find this in docs, but the STLPort which I use have the assignment operator defined. The copy algorithm can be used of course.
Sonork 100.15206;PavelK
|
|
|
|
|
I have a bunch of names of unknown length. I need to show them in so that they are stacked in adjacent columns . I know a listcontrol in "list" view will do that. But I dont want the user to think that by clicking in this box something is going to happen. SO I am wondering if I set the disabled property if that would work. its just supposed to show the list of words thats all. Even if its disabled, will I still be able to do insertItem and populate it?
Is there a better control for this purpose? I dont have a lot of vertical space to display the names.
Thanks,
ns
|
|
|
|
|
You could just give it a shot and see if it's what you want. (The traditional approach. )
An additional idea is to make the control a list view in report mode. Don't insert anything into the first column and make it of zero width. The second column can hold your list items. This arrangement could make it so that the user can't make the control look as though something is selected.
Another idea is to simply use a read-only multi-line edit control.
John
|
|
|
|
|
Hi guys, This seems like it should be really easy, but... I have this ActiveX control started with the MFC 7 wizard. The wizard always sets up a dispinterface (not a dual interface). So, I got the control working wonderfully and decided that certain performance conditions weren't good enough and am currently switching it to a dual interface. My problem is that I can't get the stock font property to appear in the font property page. A simple switch back to dispinterface causes it to work again... Any idea why?
John
|
|
|
|
|
hello,
i'm having trouble while reading a cd, i insert a written cd and read the directory with a cfilefind. then i eject the cd and put in another. the cfilefind displays the correct new directory. but when i insert a blank cd, the cfilefind returns the old directory of the cd inserted before. but with an explorer opened in the background, i see the cd name disappear from 'my computer' when i eject the disc, and then the cfilefind finds no data on the blank cd. but this only works when the explorer window is opened.
what can i do to get the blank directory instead of the old one without the explorer opened?
i hope, someone could help,
thanks
enrico
|
|
|
|
|
My destructor for a database class I wrote looks like:
~DbClass()
{
Close();
m_pConn.Release();
m_pConn = NULL;
m_strConnection = _T("");
m_pConnPhoto.Release();
m_pConnPhoto = NULL;
m_strConnection1 = _T("");
::CoUninitialize();
}
I have these various connection objects floating around that are created for different databases. I just realized that maybe this destructor is not good. What if I'd already closed the m_pConn elsewhere (I dont)> what if I create some third connection object to a third database locally. Then certainly the local conn name cant be put into the destructor. MAybe that closes automatically when it goes out of scope.
When exactly does the destructor run? When I exit the program? What if some of the objects mentioned in it were already dealt with. it doesnt hurt to close them again? I need all the three (to be) connections to co-exist thats why I didnt recycle the same name.
I hope my problem makes sense. Maybe I'm needlessly confusing myself because things seem to work. I just never thought about it and merrily added the extra conn objects to be dealt with in the same ~destructor (theres alwyas only one, right? )
Thanks,
ns
|
|
|
|
|
The destructor runs in two cases:
1. When the object goes out of scope
2. When delete is called on an object that was created with new
AFAIK, if you create an object using new, and forget to delete it (memory leak), the destructor won't get called.
Hope this helps...
Some examples:
void MyFunc()
{
SomeObject :bob:;
}
void MyFunc2()
{
SomeObject *:bob: = new SomeObject;
delete :bob:;
}
There are three types of people in this world: those who can count, and those who can't.
|
|
|
|
|
Without knowing what resources you are using and how they are being used, I cannot really suggest if the items that you have listed belong in the class destructor. However I can give you some information about when the destructor is called, and that may help you make the decision.
The destructor is called when your object is being destroyed. Your object can be destroyed in two ways.
1) if you created it on the stack like this: Object x; When the object x goes out of scope it will automatically be destroyed.
2) If you created it on the heap like this: Object *pX = new Object; then it will not be destroyed until you call delete pX.
One more tip, unless your object is the thread itself, I would not suggest calling ::CoUnitialize() in the destructor. It is best to call CoInitailze() when your thread or program starts up, and CoUninitialize() when the program or thread is shutting down. If you call CoUnitialize too many times, then the the COM dlls will unload itself for your current thread, and you will not be able to instantiate any more COM objects on that thread.
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Hmmm. Threads. Thats a new complication. I only have a single threaded app so I suppose I'm safe. Hope you can confirm this.
As for the dilemma I was having, I had createInstanced all the stuff I was destroying in the constructor (in preparation for potentially using those objects). And I forgot that each new instance makes its own copy of those objects, so one instance going out of scope wont mean that my other instances are crippled because their connection closed etc.)That was a conceptual problem that got me by surprise.
Thanks,
ns.
Though in the process I did learn about static member variables that can be shared betweeen instances....
Thanks,
ns
|
|
|
|
|
It looks like you're using the smart pointers supplied by the #import command (since "m_pConn.Release()" wouldn't normally compile otherwise).
If that is the case, you could remove the "m_pWhatever.Release()" statements and simply replace them with the already existing "m_pWhatever = NULL". The null statement will cause the smart pointer to release the object if it's there, plus an already NULL smart pointer won't care if you set it to NULL again.
John
|
|
|
|
|
Thanks. Yes I am using stuff like _RecordsetPtr etc, so its good to know they manage themselves. I am new at this memory conservation thing and am living in dread that I am doing things that I dont know about that wil make me have memory problems later. So at least I wont have to suspect the database code. The only thing I close when I can in my code is the recordset. I never close the conn object myself, because I keep needing it in various unpredicatble events.
Thanks,
ns
|
|
|
|
|
I created a set by inserting values into it <cstring>
Then I try to find if a new incoming one is already there:
NamesSet::iterator it;
it = namesSet.find(NewName);
If I find it , I want to do something, if not, another thing. To detect it
MSDN says:
const_iterator find(const Key& key) const;<br />
The member function returns an iterator that designates the earliest element in the controlled sequence whose sort key equals key. If no such element exists, the iterator equals end().<br />
So would my test be:
if(it != namesSet.end())
{
}
else
{
}
Thanks,
ns
|
|
|
|
|