sa3q
asked on
i make my application as service but it run moment and after that it stop why?
why my application run a second and after that it close
what is the problem of that ?
please help me
what is the problem of that ?
please help me
Please also check the event viewer to see if there's any related log.
ASKER
i use the setup factory to make that the script i use
and my code have 2 threads and each of the two thread their is infinite loop
what is the problem of that ???
and my code have 2 threads and each of the two thread their is infinite loop
what is the problem of that ???
Service.Create("d:\\Program Files\\MYapp\\start.exe", "sa3qApp", "sa3qApp", SERVICE_WIN32_OWN_PROCESS, true, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, "", "", nil, "", "");
In your program (start.exe) put some error logging to a file, this way you can better debug what is happening and where it stops.
ASKER
3_S:
how can i put some error logging ?????????
how can i put some error logging ?????????
Use a try catch statement in your program
If you already have some error catch, put extra statement in the catch block to write the error to file.
If none use yet, put one around the code in your main.
If you already have some error catch, put extra statement in the catch block to write the error to file.
If none use yet, put one around the code in your main.
try{
Your code
}
catch( MyException ex )
{
StreamWriter* pwriter = new StreamWriter(S"c:\\log.txt");
pwriter->WriteLine(S"Error occured." + ex.Number + ": " + ex.Message );
pwriter->Close();
}
Not only the threads must have an infinite loop but the service_main as well. Your service_main was called by SCM and should do a permanent job until terminated by SCM. That also is done by callback using the status function you provided with your call to SCM.
ASKER
httheir many problems of the code
Error 4 error C2061: syntax error : identifier 'MyException' d:\Local\sa3qApp.cpp 1041
Error 5 error C2310: catch handlers must specify one type d:\Local\sa3qApp.cpp 1041
Error 6 error C2065: 'StreamWriter' : undeclared identifier d:\Local\sa3qApp.cpp 1043
Error 7 error C2065: 'pwriter' : undeclared identifier d:\Local\sa3qApp.cpp 1043
Error 8 error C2061: syntax error : identifier 'StreamWriter' d:\Local\sa3qApp.cpp 1043
Error 9 error C3921: Use of S-prefixed strings requires /clr:oldSyntax command line option d:\Local\sa3qApp.cpp 1043
Error 10 fatal error C1903: unable to recover from previous error(s); stopping compilation d:\Local\sa3qApp.cpp 1043
syntax error : identifier 'MyException' means you didn't include the header for MyException.
'StreamWriter' : undeclared identifier iis same issue
'StreamWriter' : undeclared identifier iis same issue
ASKER
what is the header of MyException
and the stram writer
and the stram writer
MyException is a private class where you should have a myexcept.h. If you don't have such a class or header you need to throw another class, e. g. std::string.
The stream writer also must be a known class. It is not standard c++. Use std::stringstream if you copied the code from somewhere elese as a substitute for streamwriter.
The stream writer also must be a known class. It is not standard c++. Use std::stringstream if you copied the code from somewhere elese as a substitute for streamwriter.
ASKER
please i don't want to go far from my question
i know that their web services and data base services that run in the start of the computer
i want my program to run befor any user log to his account in the log in on the start of the windows
how can i make like that
i know that their web services and data base services that run in the start of the computer
i want my program to run befor any user log to his account in the log in on the start of the windows
how can i make like that
Ok forget the logging then,
Can you just explain what your program must do a the startup of your computer?
Maybe you are just trying to get the logged in user, but no one is logged in yet.
Can you just explain what your program must do a the startup of your computer?
Maybe you are just trying to get the logged in user, but no one is logged in yet.
please put your executing/the code that works as service into a while loop...while(true)
See what happens.
Best regards.
See what happens.
Best regards.
ASKER
my program must run befor any user login to his account because the application i will put it on the server to make some services in the local network to the users on the lan
can any body help me how to run it ??
can any body help me how to run it ??
Service.Create("d:\\Progra m Files\\MYapp\\start.exe", "sa3qApp", "sa3qApp", SERVICE_WIN32_OWN_PROCESS, true, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, "", "", nil, "", "");
If we look at your command (from the manual)
AllowDesktopInteraction
(boolean) Whether to allow the service process to interact with the desktop. If set to true, the service must run in the "LocalSystem" account. This can be done by setting the ServiceStartName to "LocalSystem".
This is set true in your command, has the localsystem account all the right there are needed to run?
If we look at your command (from the manual)
AllowDesktopInteraction
(boolean) Whether to allow the service process to interact with the desktop. If set to true, the service must run in the "LocalSystem" account. This can be done by setting the ServiceStartName to "LocalSystem".
This is set true in your command, has the localsystem account all the right there are needed to run?
ASKER
yes i run the program on administrator user
Since your is program is supposed to runs when no desktop is yet loaded is would recommend to set it to false.
The program has no GUI?
The last two parameters of the command are User and password. This is not set, so now it runs under the localsystem account
So to set to run with administrator user (adjust accordinaly)
Service.Create("d:\\Progra m Files\\MYapp\\start.exe", "sa3qApp", "sa3qApp", SERVICE_WIN32_OWN_PROCESS, false, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, "", "", nil, "yourdomain\\administrator ", "yourpassword");
The program has no GUI?
The last two parameters of the command are User and password. This is not set, so now it runs under the localsystem account
So to set to run with administrator user (adjust accordinaly)
Service.Create("d:\\Progra
ASKER
3_S:
i make that but the same problem appear it appear to me
error 1053 the service not response for starting in the exact time
i make that but the same problem appear it appear to me
error 1053 the service not response for starting in the exact time
ASKER
the application like a server their is no GUI
did you implement the status callback function?
ASKER
>js-profi:
>did you implement the status callback function?
no???????
>did you implement the status callback function?
no???????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To get the service status to 'started' your service_main should set the service status to running after initialization like
SetTheServiceStatus(SERVIC E_RUNNING, 0, 0, 0);
where SetTheServiceStatus is a function like
SetTheServiceStatus(SERVIC
where SetTheServiceStatus is a function like
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
js-profi:
thank you for your attention
now i know that the problem from my code and i must code service main
but if you can help me i attached the main code it have 2 threads each one call function have infinte loop it listener how can i use my code with your code ???
please don't histate if you can help
thank you for your attention
now i know that the problem from my code and i must code service main
but if you can help me i attached the main code it have 2 threads each one call function have infinte loop it listener how can i use my code with your code ???
please don't histate if you can help
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
CWinThread* thread1 =AfxBeginThread(N_mang,NULL,THREAD_PRIORITY_NORMAL,0,0,NULL);
CWinThread* thread2 =AfxBeginThread(S_Data,NULL,THREAD_PRIORITY_NORMAL,0,0,NULL);
HANDLE h[] = {thread1->m_hThread,thread2->m_hThread};
for (int i = 0; i < 2; i++) {
WaitForMultipleObjects(2, h, FALSE, INFINITE);
}
return 0;
}
if your current app was started as service you already have some service_main which was calling WinMain. I know there are wrappers which make any win32 app a service. i assume you've used such a wrapper? or how did you get your app started as a service?
if i am right you only need to set the service status to running. do it in the WinMain after creating the threads but before waiting. use the SetTheServiceStatus function i copied from MSDN samples. you can get more docs and sample code searching for SCM or service.c in MSDN.
if i am right you only need to set the service status to running. do it in the WinMain after creating the threads but before waiting. use the SetTheServiceStatus function i copied from MSDN samples. you can get more docs and sample code searching for SCM or service.c in MSDN.
ASKER
js-profi:
i try to use all the code you type but their ten's of errors in compile
please can you give me full code include your code with my code
i try to use all the code you type but their ten's of errors in compile
please can you give me full code include your code with my code
/////////////////////////////
//on the above of the code i add the functions you make
///////////////////////////////
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
CWinThread* thread1 =AfxBeginThread(N_mang,NULL,THREAD_PRIORITY_NORMAL,0,0,NULL);
CWinThread* thread2 =AfxBeginThread(S_Data,NULL,THREAD_PRIORITY_NORMAL,0,0,NULL);
SetTheServiceStatus(SERVICE_RUNNING, 0, 0, 0);
HANDLE h[] = {thread1->m_hThread,thread2->m_hThread};
for (int i = 0; i < 2; i++) {
WaitForMultipleObjects(2, h, FALSE, INFINITE);
}
return 0;
}
/////////////////////////////
and the error
///////////////////////////////
Error 3 error C2065: 'SERVICE_RUNNING' : undeclared identifier
Error 4 error C2065: 'SERVICE_CONTROL_STOP' : undeclared identifier
Error 5 error C2051: case expression not constant
Error 6 error C2065: 'SERVICE_STOP_PENDING' : undeclared identifier
Error 7 error C2065: 'SERVICE_CONTROL_SHUTDOWN' : undeclared identifier
Error 8 error C2051: case expression not constant
Error 9 error C2065: 'SERVICE_STOP_PENDING' : undeclared identifier
Error 10 error C2065: 'SERVICE_CONTROL_INTERROGATE' : undeclared identifier
Error 11 error C2051: case expression not constant
Warning 12 warning C4065: switch statement contains 'default' but no 'case' labels
Error 13 error C3861: 'SetTheServiceStatus': identifier not found
Error 14 error C2065: 'SERVICE_CONTROL_STOP' : undeclared identifier
Error 15 error C2065: 'SERVICE_CONTROL_SHUTDOWN' : undeclared identifier
Error 16 error C2065: 'hStopEvent' : undeclared identifier
Error 17 error C3861: 'ErrorStopService': identifier not found
Error 18 error C2065: 'hStopEvent' : undeclared identifier
Error 19 fatal error C1903: unable to recover from previous error(s); stopping compilation
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok thank you the service run but it didn't run on the windows login
i mean befor any user logon
what is the problem ??
i mean befor any user logon
what is the problem ??
ASKER
the program running in the logon but it not interactive with any thing
you mean logon or boot? services - which you can watch in the services applet - were always started before first login. it depends on their account whether they have access to local network or not. if started with local system account they have no access to network. better create a user specially for that service and start the service using that account. then it should be able to do something. loggings should be made to file cause desktop is not available .
ASKER
yes i mean boot
i choose local network
i want to run the program in winlogon.
The program run perfect when i use any user desktop and the administrator account run the application when i log of the program not closed but it make like pause and if i login to other account it resume the session of the application i want the program to run without pause
may i have your advise
i choose local network
i want to run the program in winlogon.
The program run perfect when i use any user desktop and the administrator account run the application when i log of the program not closed but it make like pause and if i login to other account it resume the session of the application i want the program to run without pause
may i have your advise
i still have doubts whether your prog is a service. if you start it from desktop with admin rights it is not a service. a service can be installed once using an installer or have a own installing option, e. g. like invoking it by myservice -i. then the SCM (service control manager) applet form can be used to start/stop the service which keeps installed and it always runs at boot time before any login. after login you need process-to-process (P2P) communication to speek with the service or send jobs/request to it. P2P can be made based on sockets, shared memory, pipes, files, windows messages. if user logs out the service would still run.
if you want to start your prog after login, you could use the 'at' tool which can be easily configured using the explorer at windows\tasks folder.
ASKER
please understand me the program installed as service and i make it to start automaticly
and it start automatic
the program work with files and local network and interactive with windows
it must be run all times
i means by all times
1- when any user work on his desktop
2- when their is no users logon to his account
this computer will not be shut down and the service(program) must run in the winlogon screen
thank you for your attention
and it start automatic
the program work with files and local network and interactive with windows
it must be run all times
i means by all times
1- when any user work on his desktop
2- when their is no users logon to his account
this computer will not be shut down and the service(program) must run in the winlogon screen
thank you for your attention
ASKER
thank you
you solve the problem that appear to run the service
i will open new question because i want my program to be active if there is no user login to his account
you solve the problem that appear to run the service
i will open new question because i want my program to be active if there is no user login to his account
yes a service would all do what you request beside of interacting with the login screen. here a secured gina.dll would block any interference for login not being spied out by malware.
Could you post the code of the service?
Is there a some kind of loop in your service to execute as an infinite manner?
Best regards.