-
April 30th, 2013, 10:42 AM
#61
Re: running a GUI program in the background
the service installed fine but it won't start
Why not? What error is being reported? What is your service doing and what is causing the error?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 30th, 2013, 10:45 AM
#62
Re: running a GUI program in the background
when i try start the service from the system control management the message error 2: system cannot find the file specified appears and when i run the batch file in the cmd i get the same message
-
April 30th, 2013, 11:14 AM
#63
Re: running a GUI program in the background
Originally Posted by beginner91
can't debug a service program
All programs can be debugged, unless the program has anti-debugger features in it.
Second, even if you couldn't figure out how to debug, you always have OutputDebugString() and programs such as DebugView from sysinternal.com to see output messages.
Third, let's ask you to see if you understand what everyone is saying:
What do you think the result of this operation is?
Code:
CString path = GetExeFolderName() + TEXT("C:\\testService\\Debug\\testService.exe");
?
What string is going to be created from this?
Regards,
Paul McKenzie
-
May 1st, 2013, 04:33 AM
#64
Re: running a GUI program in the background
What string is going to be created from this?
i don't know. i thought that code just told the program where the exe file is
-
May 1st, 2013, 05:43 AM
#65
Re: running a GUI program in the background
Originally Posted by beginner91
i don't know. i thought that code just told the program where the exe file is
It would probably be useful if you posted your code so we could see how you are trying to achive and so we could provide better guidance.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
May 1st, 2013, 06:15 AM
#66
Re: running a GUI program in the background
i am using the code igor posted to this thread (post #42). the only line i changed was the path
-
May 1st, 2013, 06:32 AM
#67
Re: running a GUI program in the background
Please post the code here that you are actually using.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
May 1st, 2013, 06:44 AM
#68
Re: running a GUI program in the background
ok i attached the code
code.zip
-
May 1st, 2013, 08:21 AM
#69
Re: running a GUI program in the background
the service installed fine but it won't start
How do you know that the service installed fine? Have you checked it with the services program? What does sc query MyServiceX say from the command line? What is the contents of the file mysvcx.log (not sure which folder it'll be in - do a search for it)?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
May 1st, 2013, 08:33 AM
#70
Re: running a GUI program in the background
How do you know that the service installed fine?
i can see its installed because it appears in the Service Management Console list.
What does sc query MyServiceX say from the command line?
C:\testService>if -u == goto UNINSTALL
C:\testService>sc create MyServiceX binPath= "C:\testService\mysvcx.exe"
[SC] CreateService FAILED 1073:
The specified service already exists.
C:\testService>sc start MyServiceX
[SC] StartService FAILED 2:
The system cannot find the file specified.
What is the contents of the file mysvcx.log
when i try run the service the file is empty but when i run the exe file it says:
[05/01/13 14:29:07] ++ Start ++
[05/01/13 14:29:14] -- Stop --
-
May 1st, 2013, 08:57 AM
#71
Re: running a GUI program in the background
Originally Posted by beginner91
i am using the code igor posted to this thread (post #42). the only line i changed was the path
No, you're not using my code. What you made of it is a horrible mess, while what you were just supposed to do is to run Visual Studio Command Prompt and run make.bat there to build mysvcx.exe as well as test.exe.
Best regards,
Igor
-
May 1st, 2013, 09:06 AM
#72
Re: running a GUI program in the background
i don't have experience using batch files so i wasn't sure what to do.
run Visual Studio Command Prompt and run make.bat
i got this error:
test.cpp
test.cpp(1) : fatal error C1083: Cannot open include file: 'windows.h': No such
file or directory
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
10.cpp
10.cpp(2) : fatal error C1083: Cannot open include file: 'windows.h': No such fi
le or directory
-
May 1st, 2013, 09:06 AM
#73
Re: running a GUI program in the background
what does sc qc MyServiceX show? Especially for the BINARY_PATH_NAME?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
May 1st, 2013, 10:42 AM
#74
Re: running a GUI program in the background
Originally Posted by beginner91
i don't know. i thought that code just told the program where the exe file is
So basically you don't have any idea what that line of code does or what type of string will be created?
I don't know what you believe C++ is, but it isn't a scripting language or HTML. It requires that you know the language, and obviously you need to learn the language.
Code:
CString path = GetExeFolderName() + TEXT("C:\\testService\\Debug\\testService.exe");
What does the "+" in red do? It joins two strings together to create a single string. It joins the string on the left with the string on the right to create a single string.
What does the "=" in blue do? It assigns the value of the operation on the right hand side of the "=" to the variable on the left hand side of the "=". So "path" will contain the value of the concatenation of the two strings.
Now, look at the two strings you're joining -- you are taking the value of GetExeFolderName(), and adding to it C:\testService\Debug\testService.exe. So for arguments sake, let's say that GetExeFolderName() returns "C:\MyFolder\MyEXE\". So what is the result of "path" after the concatenation is done?
Code:
C:\MyFolder\MyEXE\C:\testService\Debug\testService.exe
(extra slashes were removed for ease looking at the real value)
Does that look like a valid directory name to you? Forget about C++, have you ever seen a directory name that looks like that? That name is not even a valid Windows directory name, regardless of what you want to do. If you want to be convinced, go to a command prompt and do a "DIR" on the name that "path" happens to be -- do you get back a listing or does the DIR give you an error?
That's why you keep getting the error and why you should have checked the result of "path" so that you know what you are using.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; May 1st, 2013 at 10:49 AM.
-
May 1st, 2013, 11:52 AM
#75
Re: running a GUI program in the background
Originally Posted by beginner91
i don't have experience using batch files so i wasn't sure what to do.
i got this error:
test.cpp
test.cpp(1) : fatal error C1083: Cannot open include file: 'windows.h': No such
file or directory
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
10.cpp
10.cpp(2) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
Considering the error what you opened is not Visual Studio Command Prompt. You should use Search in Start Menu.
Best regards,
Igor
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|