It only means you set a wrong path/name! Fix it!
Printable View
It only means you set a wrong path/name! Fix it!
the only line that has a path in it is this:
and that is the correct path to the exe file so i don't know where the problem isCode:CString path = GetExeFolderName() + TEXT("C:\\testService\\Debug\\testService.exe");
contents of what? i don't understandQuote:
What do you expect path to contain after this statement? Have you examined its contents?
The contents of path. Have you looked at it in the debuuger or shown it on screen to be sure it's what you are expecting as you are concatenating the result of GetExeFolderName() with the TEXT string? As the TEXT string contains both a drive letter and folder names I'm not sure what you are trying to achieve by concatenating this TEXT string with the result of GetExeFolderName().
ok so i entered the wrong path name?
if GetExeFolderName() gets the folder, then the path should just be testService.exe?
Have you checked what GetExeFolderName is actually returning? As you are hardcoding the full path to your testservice.exe, you probably don't need GetExeFolderName at all at the moment whilst you are testing.
this is the code for GetExeFolderName
so if i don't need that should i just call the path like this:Code:CString GetExeFolderName()
{
TCHAR path[MAX_PATH] = {0};
GetModuleFileName(GetModuleHandle(NULL), path, MAX_PATH);
LPTSTR p = _tcsrchr(path, _T('\\'));
if (p)
{
*p = TEXT('\0');
return path;
}
return (LPCTSTR)NULL;
}
CString path = TEXT("C:\\testService\\Debug\\testService.exe");
Yes. What debugging of the program have you done - as this should have been picked up by using the debugger.Quote:
so if i don't need that should i just call the path like this:
CString path = TEXT("C:\\testService\\Debug\\testService.exe");
can't debug a service program and i can't test the service because of this error
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?Quote:
the service installed fine but it won't start
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
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
i don't know. i thought that code just told the program where the exe file isQuote:
What string is going to be created from this?
i am using the code igor posted to this thread (post #42). the only line i changed was the path
Please post the code here that you are actually using.
ok i attached the code
Attachment 31371
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)?Quote:
the service installed fine but it won't start
i can see its installed because it appears in the Service Management Console list.Quote:
How do you know that the service installed fine?
C:\testService>if -u == goto UNINSTALLQuote:
What does sc query MyServiceX say from the command line?
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.
when i try run the service the file is empty but when i run the exe file it says:Quote:
What is the contents of the file mysvcx.log
[05/01/13 14:29:07] ++ Start ++
[05/01/13 14:29:14] -- Stop --
i don't have experience using batch files so i wasn't sure what to do.
i got this error:Quote:
run Visual Studio Command Prompt and run make.bat
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
what does sc qc MyServiceX show? Especially for the BINARY_PATH_NAME?
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.
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.Code:CString path = GetExeFolderName() + TEXT("C:\\testService\\Debug\\testService.exe");
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?
(extra slashes were removed for ease looking at the real value)Code:C:\MyFolder\MyEXE\C:\testService\Debug\testService.exe
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
no i definately used Visual Studio Command Prompt
c:\Program Files\Microsoft Visual Studio 9.0\VC\run_process_from_service>make.bat
this is the only visual studio command prompt i found:
Attachment 31377
Given you have document entries for VS2010 and VS2012, perhaps your environment is screwed up? Did you install VS2010/VS2012 and then uninstall them? Have you looked at the system and/or user path settings - are there any entries that are stale? Is the path too long? To check, open a command prompt and type set.
Well, if you really run that, and compiler is not able to find windows.h, please take my condolences, as most probably your VS installation is broken. I used Visual Studio all versions since v4.0, and never had a problem like that. Never.
This is what my VSCP gives with my sample placed in C:\testService folder:
Windows 7, VS2010
Same source code, Windows XP SP3, VS.NET2003Code:Setting environment for using Microsoft Visual Studio 2010 x86 tools.
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>cd \testService
C:\testService>make
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
test.cpp
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test.exe
test.obj
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
10.cpp
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:10.exe
/out:mysvcx.exe
10.obj
C:\testService>
This is how it runs:Code:Setting environment for using Microsoft Visual Studio .NET 2003 tools.
(If you have another version of Visual Studio or Visual C++ installed and wish
to use its tools from the command line, run vcvars32.bat for that version.)
C:\Documents and Settings\Igor>cd \testService
C:\testService>make
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
test.cpp
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test.exe
test.obj
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
10.cpp
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.
/out:10.exe
/out:mysvcx.exe
10.obj
LINK : warning LNK4089: all references to 'USER32.dll' discarded by /OPT:REF
C:\testService>
...and this is the log:Code:C:\testService>setup
C:\testService>if -u == goto UNINSTALL
C:\testService>sc create MyServiceX binPath= "C:\testService\mysvcx.exe"
[SC] CreateService SUCCESS
C:\testService>sc start MyServiceX
SERVICE_NAME: MyServiceX
TYPE : 10 WIN32_OWN_PROCESS
STATE : 2 START_PENDING
(NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x7d0
PID : 2656
FLAGS :
C:\testService>test.bat run
SERVICE_NAME: MyServiceX
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING
(STOPPABLE,NOT_PAUSABLE,ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
C:\testService>test.bat stop
SERVICE_NAME: MyServiceX
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING
(STOPPABLE,NOT_PAUSABLE,ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
C:\testService>setup -u
C:\testService>if -u == -u goto UNINSTALL
C:\testService>sc stop MyServiceX
SERVICE_NAME: MyServiceX
TYPE : 10 WIN32_OWN_PROCESS
STATE : 1 STOPPED
(NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
C:\testService>sc delete MyServiceX
[SC] DeleteService SUCCESS
C:\testService>
Of course you should remember about running your command prompt as administrator to be able to control your service states.Code:[05/02/13 22:19:11] ++ Start ++
[05/02/13 22:19:24] C:\testService\test.exe
[05/02/13 22:19:24] Waiting for test.exe stop...
[05/02/13 22:19:32] Detected test.exe stop.
[05/02/13 22:19:32] Quitting thread.
[05/02/13 22:19:39] -- Stop --
If you want to move any further from where you are, you should start with reproducing this behavior. Please note, the log file is the debugging tool itself, and so far it's very unlikely you need anything more sophisticated.
yes i had the express version of VS2012 but i uninstalled itQuote:
Did you install VS2010/VS2012 and then uninstall them?
so this is effecting my VS2008 now?
i don't know how it can be broken because other programs work fineQuote:
VS installation is broken
Quite possibly.
But you are having problems with the VS command prompt environment, aren't you? That's very different from the IDE, compiler and linker. So it's possible that the environment is messed up from installing/uninstalling 2010/2012, but the 2008 compiler still works. Reinstall 2008 to be sure (and the appropriate service packs).
Did you open a command prompt and type the set command in order to view the path settings like I mentioned?