|
Can anyone tell me why NetUserSetInfo gives an error when using the
structure USER_INFO_1005 . The error value is 87 and the value of the
last parameter of the function is 997.Any idea about it..
Here is the code, I need to change the current Login User with Normal Rights to Administrator rights.
char lpBuffer[255];
USER_INFO_1005 usriPriv;
DWORD netRet = 0;
usriPriv.usri1005_priv = USER_PRIV_ADMIN;
netRet = NetUserSetInfo( NULL, (unsigned short *)lpBuffer, 1005, (LPBYTE)&usriPriv,NULL);
if( netRet == NERR_Success )
printf("Success!\n");
else
printf("ERROR: %d Returned from NetUserSetInfo\n", netRet);
|
|
|
|
|
Hint: Error 87 = "The parameter is incorrect".
1. You aren't specifying a server, so this will assume that the lpBuffer is an account name on the local machine.
2. Is the executing account sufficiently privileged (see docs on NetUserSertInfo).
3. When you say the value of the last parameter is 997, have you tried testing it against values like USER_PRIV_INFOLEVEL or USER_PRIV_PARM?
(How do you know it's 997, you're passing in NULL, so it doesn't give you the value?)
Steve S
|
|
|
|
|
I've done some work with C# and one of the things I really like was the fact that I could have the same handler for many different controls on a form. For example if I had five buttons and an event handler called OnButtonClick I could setup every button to call that same handler. Is it possible to do something like this in MFC? If so how? I have a bunch of edit controls that all need to do the same processing after losing focus and I'd rather have one function for them all instead of having to have a bunch of handlers that do that exact same thing. Thanks in advance for the help.
I just thought of something...would this be as simple as adding a message map entry to map the edit boxes I want to use the function to that function?
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
ON_EN_KILLFOCUS(IDE_BOX1, OnKillFocusEdit)
ON_EN_KILLFOCUS(IDE_BOX2, OnKillFocusEdit)
ON_EN_KILLFOCUS(IDE_BOX3, OnKillFocusEdit)
ON_EN_KILLFOCUS(IDE_BOX4, OnKillFocusEdit)
END_MESSAGE_MAP() Would that work? Just thought of something else. If that did work how would I know which edit box called the function?
Thanks
- monrobot13
|
|
|
|
|
Yeah, you can have one handler handle as many messages as you like. To get the HWND of the caller, you'll need to look at the LPARAM of the message, which for WM_COMMAND is the HWND of the control that sent the message: GetCurrentMessage()->lParam
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Pinky, are you pondering what I'm pondering?
I think so Brain, but if we shaved our heads, we'd look like weasels!
|
|
|
|
|
Michael Dunn wrote:
which for WM_COMMAND is the HWND of the control that sent the message
Is this the same for WM_KILLFOCUS?
Thanks for the help
- monrobot13
|
|
|
|
|
In the message map definition use:
ON_CONTROL_RANGE(EN_KILLFOCUS, IDE_BOX1, IDE_BOX4, OnKillFocusEdit)
and declare the handler as:
OnKillFocusEdit(UINT nID)
This will reflect EN_KILLFOCUS notification message from all controls in range IDE_BOX1 - IDE_BOX4 and pass the appropriate ID to nID parameter.
Robert-Antonio
"A piece of paper is an ink-lined plane.
An inclined plane is slope up.
A slow pup is a lazy dog.
Q.E.D.: A piece of paper is a lazy dog."
|
|
|
|
|
This sounds like a good idea, but
Robert A. T. Káldy wrote:
and pass the appropriate ID to nID parameter
confuses me. If the functions is called internally and not specifically by me how do I pass in an ID or am I misunderstanding and is the ID passed in automatically?
Thanks for the help
- monrobot13
|
|
|
|
|
Use can use ON_CONTROL_RANGE as said earlier but you must be sure that the ranges of the controls given are contigious and in order.
What is meant by "pass the appropriate ID to nID parameter" is that when the method is called, the nID parameter will be the ID of the control that just lost focus.
(Note that if you are planning to do something like validate and keep the user on a certain control if validation fails, this is a bad GUI design decision.)
Peace!
-=- James (Sonork:100.21837)
[Tip for SUV winter driving survival: "Professional Driver on Closed Course" does not mean "your Dumb Ass on a Public Road"!] [Get Delete FXP Files Now!]
|
|
|
|
|
Thanks for the clarification James. Not to worry, I am planning on validating, but not keeping the uesr on the control. I've dealt with programs like that before and it drove me insane.
- monrobot13
|
|
|
|
|
the execute method doesn't supports concatination. Meaning
.Execute("Select * form table where ID ='" + val,NULL, -1);
|
|
|
|
|
So why not just create the string first and then call it for the function?
CString csQuery (_T ("Select * from table where ID = "));
csQuery += val;
AdoConnection.Execute(csQuery, NULL, -1);
- monrobot13
|
|
|
|
|
Ananymous wrote:
Execute("Select * form table where ID ='" + val,NULL, -1);
what is the variable type of val
try this.
CString strQuery;
strQuery.Format("Select * from table where ID = %?",val);
.Execute(strQuery,NULL,-1);
|
|
|
|
|
Whether or not the concatination works here has nothing to do with the Execute method. The Execute method is not involved in the concatination of "Select * from table where ID='" + val, it would be called with the result of the concatination as a parameter.
In what way does the concatination fail?
|
|
|
|
|
Hi
I have created a service out of a program using the program SRVANY.EXE.
When you click the minimise button of the program, an icon of the program is automatically added to the tray bar. When you double click the icon, the program is shown.
Now, when i minimise the program, which runs as interactive service with local system account .. it is added to the tray bar. When i log out and then log in, the icon is removed from the tray bar and i still can see the program (process) in my task manager so it still runs.
I thought my code removed the icon itself, so i checked that but the 'WM_DESTROY' isn't send by the system when you logout so my program doesn't remove it itself (Windows does).
Is there any way around this? And does anyone know which messages the service manager sends to the program to stop or reboot? I would highly appreciate any help.
Best regards,
Jens
|
|
|
|
|
I guess it is due to recreation of the tasktray and you are not notified and you are not putting ur icon back on the tasktray....
you should listen to the user defined message with message string "TaskbarCreated"
like this
const UINT WM_TASKBARCREATE = RegisterWindowMessage(_T("TaskbarCreated"));
when you get this message update the taskbar icon.
|
|
|
|
|
ah ok. I will try this right now.
Greetings,
Jens
|
|
|
|
|
Yes, now i get the Windows message that the tray bar is created and i add my icon to it. So that problem is solved Thanks alot!
However, i got one problem left. Every time when i run the service and log off and then i login a second time .. the program is shown correctly with an interface (interactive using local system account). But i can't use the menu .. it's somehow impossible to use the menu or do some actions with the program. How is this possible? (never had that problem until i used it as service)
<just edited="">
I only have this weird problem on my computer. On any other computer it works great.
Greetings,
Jens
|
|
|
|
|
I am glad that it worked.
Sorry, no idea about the problem, i never had this problem before, so i have little idea about it.
|
|
|
|
|
Hi All!
I am using SetWindowsHookEx(...) to set WH_CBT hook, but the problem is that it never get called in system context. But only works on my application's main window. Don't know whats wrong? May be i am missing a simple thing that is causing the hook to install as system wide.
Here is the piece of code i am using to install the hook
//Installs the hook
//g_hInstDll is set to hInstance in DllMain()
g_hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)Dll_HookProc,(HMODULE)g_hInstDll,0);
Is there anything specific i need to do in order to install hook system wide?
Best Regards,
Bilal Anjum
|
|
|
|
|
The call to SetWindowsHookEx looks fine, what does it return when you call it?
I assume Dll_HookProc is in a DLL and is of the correct type.
|
|
|
|
|
g_hHook is a proper handle and yes all of this is within the DLL. Here is the piece of code:
BOOL DLL_USE WINAPI Dll_HookApp()<br />
{<br />
g_hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)Dll_HookProc,(HMODULE)g_hInstDll,(DWORD)NULL);<br />
if (g_hHook)<br />
return TRUE;<br />
else<br />
return FALSE;<br />
}<br />
<br />
BOOL DLL_USE WINAPI Dll_UnhookApp()<br />
{<br />
if (g_hHook != NULL)<br />
return ::UnhookWindowsHookEx(g_hHook);<br />
else<br />
return FALSE;<br />
}<br />
<br />
static LRESULT CALLBACK Dll_HookProc(int nCode, WPARAM wParam, LPARAM lParam)<br />
{<br />
LRESULT lRes = 0;<br />
<br />
if(nCode < 0)<br />
return CallNextHookEx(g_hHook, nCode, wParam, lParam);<br />
<br />
<br />
return lRes;<br />
}
Best Regards,
Bilal Anjum
|
|
|
|
|
The only difference I can see between your code and the code I have written is in the definition of the callback function. Mine is defined as:
DLL_USE LRESULT CALLBACK CBTHandler(int nCode, WPARAM wParam, LPARAM lParam)<br />
{<br />
}
So it is not static and it is marked as exported from the DLL. This could be causing the problems.
Mike
|
|
|
|
|
well static can be or is unnecessary but exporting the Hook proc doesn't make any sense, coz the calling application can only set the hook or remove the hook, hook proc will be used internally, so i think need not to export the hook proc.
Anyway thanks a lot for the reply, if you have some suggestion like setting up my project (i am using VC++ 6 may be i am not setting up the project), then it might be helpful.
if you can send me the basic code for your hook dll (Only hook setup code), it can solve the issue.
Best Regrads,
Bilal Anjum
|
|
|
|
|
My basic code is the same as yours apart from the definition of the hook function.
The DLL will be loaded into the adderess space of all the other application running on your system, they will call the hook function so exporting it could make a difference. Try it, it will only take a minute to test it.
|
|
|
|
|
Hi!
I have solved my problem, infact there was no problem at all. What i was trying to do was to debug a system wide installed hook in the VC debugger, which is not possible as such, so all the events i got were from the application i was dubugging in context with. So if i run the program (not debug it), it works fine. Thanks a lot for your patience and help. Now the real problem is still there, how to debug my program (system wide hook)?
Best Regards,
Bilal Anjum
|
|
|
|