|
welcome , glad it was helpfull
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
I am trying to do something like this:
> STARTUPINFO si;
> PROCESS_INFORMATION pi;
> BOOL bRes = false;
> DWORD dwCode = 0;
> ZeroMemory ( &si, sizeof ( STARTUPINFO));
> si.cb = sizeof ( STARTUPINFO);
> si.dwFlags = STARTF_USESHOWWINDOW;
> si.wShowWindow = SW_SHOWNORMAL;
>
> bRes = CreateProcess( NULL,
> (char *)it->second.c_str(), // some exe
> NULL,
> NULL,
> TRUE, // also tried FALSE
> NORMAL_PRIORITY_CLASS, //also tried 0
> NULL,
> NULL,
> &si,
> &pi
> );
> DWORD error = GetLastError();
> XERROR1( "ExecuteFailoverCommand :after execution Error=%d", error);
> if( bRes == false )
> {
> XERROR3( "ExecuteFailoverCommand :Error=%d, Could not invoke process %s
> for service %s", error, it->second.c_str(), ServiceName.c_str());
> }
> else
> {
> XTRACE2("ExecuteFailoverCommand : executed command %s on failure of %s
> returned %d", it->second.c_str(), ServiceName.c_str(),bRes);
> return true;
> }
This is working fine when I am calling CreateProcess from an exe but same is not working when it is being called from a running service. This may be due to reason that service puts the UI on a different desktop.
So, is there any other solution to this problem.
thanks in Adv
|
|
|
|
|
laksh2204 wrote: This may be due to reason that service puts the UI on a different desktop.
Possibly.
laksh2204 wrote: So, is there any other solution to this problem.
Maybe, depends on your definition of the "this problem". Most services don't have a user interface because they don't need one due to the nature of the problem they are solving. What problem are you trying to solve?
led mike
|
|
|
|
|
laksh2204 wrote: This may be due to reason that service puts the UI on a different desktop
It would be helpful to know if that's actually the case.
"not working" is pretty vague don't you think?
Have you tried using the STARTUPINFO.lpDesktop field?
You may also want to consider using CreateProcessAsUser() instead of
creating the process as the user the service is running as.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Well you were a little late, but welcome to the fishing derby!
led mike
|
|
|
|
|
led mike wrote: you were a little late
Yeah, but nothing else going on here - so what the heck
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Actually, I have a service running on Windows Server2003 sp2 called locator. This service keeps a control over another 4 services in the system. If any one of these four is down, I am supposed to run a process say Handler which is yet to be developed.
So I was trying with an existing like cmd,calc etc...
Now As Mark is saying use CreateProcessAsUser() and lpDesktop, I have a problem that I am new to windows domain. I don't know what should be the value for lpDesktop or for hToken i.e. first parameter of CreateProcessAsUser(). I am getting error 6 INVALID_HANDLE.
I think, The discussion stopped due to timezone difference.
--Arun
|
|
|
|
|
hello,
you said that you already have the "locator" service that keep control of the other 4 ones.
I think,if possible, that instead of developing another service, the "handler" that would execute a certain code under the scrash event of one of the other 4 services,then just put that code in the "locator", why complicate it ? Of course I suppose here that you have hands on the "locator" source code, something you didn't said.
Regarding the use of createProcess,etc..I wonder why you develop an MFC app
for such thing as to respond to the crashing of an NT service, then may be restart it from using that MFC app.
It is right, your UI wo'nt showup when exectued in context of a service.It's like there is a fictiouness desktop with which services interact I remember myself even to have problem trying to debug a service by trying to catch the TRACEs and log them into an UI application Window.
I am also know that it is said that it is not advised even to try make a service interact with session-wise objects : for example try to communicate something in the desktop of a logged user by the service. Do not even suppose that while your service is running or that when it has crashed that there is a user who is logged that time in order to notify him.
I have something like that : a remote service (developed by means of CUTService : a very good class that helps you write services : it is included in Ultimate TCP/IP you find here in CodeProject) which I control by a remote application which collects performances and key indicators but also with another local service (ie in the same server machine as the first service) which can open local socket channel and do efficient control of the service state..but no interaction with the desktop of the remote server machine)
Anyway..try do something and come here back if there is something to talk about.
Our Philosophy, Mohammed Baqir Al Sadr
|
|
|
|
|
laksh2204 wrote: I don't know what should be the value for lpDesktop
You could try "Winsta0\default".
Which desktop you use and which account the spawned process runs
as are two separate issues. If your service runs with privileges
above what the user should have (as is often the case), then
you need to use CreateProcessAsUser().
You should really study the docs carefully - I haven't gone into why a
service that interacts with the desktop and/or current user is a bad idea.
It's not guaranteed to work in future operating systems.
Services[^]
Window Stations and Desktops[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I think its not a bad idea in general scenario. But might not be good idea in my scenario.
As according to my problem when a particular service is down, the user which is logged in must have a process running which can handle the situation. In this way, that user is required to be logged in permanently. Which for me doesn't seems to be a good idea. In other words, What if no user is logged in and one of those services goes down. No one will be there to handle the situation.
However, "Winsta0\default" looks quite different to me. May be like someone who is always there. In this case it should work. I'll try it out.
Thanks everyone for your valuable time.
This forum is really one of the bests I've ever seen.
|
|
|
|
|
Hi,
in my application if I connect a new USB HID device I want to access the property (Location ) of the USB Human INterface Device from the devicemanager.
Can anybody suggest me a way for doing that ......
|
|
|
|
|
Hi,
in my application if I connect a new USB HID device I want to access the property (Location ) of the USB Human INterface Device from the devicemanager.
Can anybody suggest me a way for doing that ......
Thanks in advance....
|
|
|
|
|
Hello,
a long time ago I've developed a project using the resources from The HID Page[^]. Good Luck!
Best regards,
Mihai Moga
|
|
|
|
|
Hi All
I have a problem to call function. I have delara a function type is public [code]void abc(PDEV_BROADCAST_DEVICEINTERFACE pDevInf, WPARAM wParam)[/code].
And define in .cpp file. It is working well but i need to call this function in [code]OnInitDialog()[/code]. Can i call it or not? If yes then plz help me
singh
|
|
|
|
|
I'm not sure why you wouldnt be able to call it. Where are you calling it now?
|
|
|
|
|
polopo wrote: Can i call it or not?
Yes.
polopo wrote: If yes then plz help me
With what exactly?
"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
|
|
|
|
|
polopo wrote: I have delara a function type is public
Sorry, I never heard about public function s.
BTW what about a good C++ tutorial?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Definetely we can call it.. Don't know what problem you are facing? Could you elaborate please?
|
|
|
|
|
If you are saying that you have a class and inside that you have a public member function, then
you need to create an object of the class at the place where you want to call it. And then using that object you can call the function. You need to include the .h file in which you have created your class.
Well this is like targeting in dark..
If you can put the problem in detail. You may get right solution.
|
|
|
|
|
Im having a problem when I SetWindowRgn I lose the visual appearance of XP and Vista, as seen in Figure 1[^]. Any ideas of what I'm doing wrong?
Here is the code i'm using DialogTest.rar
Thanks
|
|
|
|
|
Yes, that's what SetWindowRgn does. How can Windows know how to attach a title bar to your region?
Applications that do this draw their own title bar and respond to WM_NCHITTEST to tell Windows which part of the UI has been hit. You can draw standard Windows controls with DrawThemeBackground/DrawThemeIcon/DrawThemeText etc, if theming is enabled, or DrawCaption/DrawFrameControl if not.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
No, I understand that. I’m setting the region when the user presses the button, then unsetting the region when it's pressed again. The problem is that when I put back WS_CAPTION the window was being redrawn without visual styles. I just figured out that I was clearing the region after setting WS_CAPTION back to my window. I switched the order and every thing worked perfectly....
Thanks for your response.
|
|
|
|
|
Hi All
How can i remove duplicate values from listbox.Plz help me
|
|
|
|
|
How did your list box end up with duplicate values at first? The right way would be to not add duplicate values.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Thx's for responce
I am adding values at the run time in the list box.And i want if all ready data(same name of data) present then no new data add in the exiting list box.If different type of data(different name of data)came then add in this listbox.
Right now data add in proper way but i need to remove duplicate data.
Plz help me
|
|
|
|