Solved

Windows service doesn't start

Posted on 2014-09-16
14
263 Views
Last Modified: 2014-09-23
Hi Experts,
I am having a C++ windows service (my own custom service), the installation of service (-i) works fine, however when I try to start the service using -s option, it gives me an error "Error 2: The system cannot find the file specified".
The GETLASTERROR API and its text does not tell me which file is it not able to find.
The same service works fine in debug mode (-d) option from visual studio.

On 3 other machines with the same set up, this service starts and works properly from service manager.
Can anyone of you help me identify because of which file is my service not starting? Also I have tried searching on Google (some site says it could VC re-distributable issues however I have verified them on other machines), also I have tried using dependency walker, even that has not helped.

Thanks in advance,
Karrtik
0
Comment
Question by:Karrtik Iyer
  • 8
  • 4
  • 2
14 Comments
 
LVL 2

Expert Comment

by:wackym
ID: 40325212
Hello Karrtik,

Which build have you run? Debug or release? Debug build uses "debug" runtime libraries which aren't present in any re-distributables.
Another issue might be PATH environment variable which could be different for services (depending on which user account is used to run the service).

Best regards,
Mike
0
 
LVL 15

Author Comment

by:Karrtik Iyer
ID: 40325235
Hi Mike,
I run Release Win32 build to install the service using -i option and then start using -s option.
While running from visual studio using -d option I use Debug Win32 option.
I am using Local system user to run the service.
I went and checked the dependencies (linker->input) of my service and all of them are present in PATH of the current logged in user.
Thanks,
Karrtik
0
 
LVL 2

Expert Comment

by:wackym
ID: 40325292
Hmm, if you check the registry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\<your_service_name>\ do you have an entry ServiceDll or ImagePath? Do you also have a subkey "Parameters"? Does it have another ServiceDll or ImagePath value? (these take precedence over those in <your_service_name>)

Best regards,
Mike
0
 
LVL 15

Author Comment

by:Karrtik Iyer
ID: 40325318
Thanks Mike for this suggestion.
Well, I checked this and verified that :
1. It does not have a subkey "Parameters".
2. It does not have entry for ServiceDLL.
3. Yes it does have entry for ImagePath, and it is pointing to:
X:\ct\KBProj\develop\bin\rupscan\Tool\LMRemoteStatus.exe
which is the correct path and the exe is present at that path.

Regards,
Karrtik
0
 
LVL 2

Expert Comment

by:wackym
ID: 40325402
Hmm, you could try using procmon and recording the start of service...it should tell you which files the service tried to load and were unavailable or access was denied for them.

Best regards,
Mike
0
 
LVL 86

Expert Comment

by:jkr
ID: 40325408
Try Mark's Process Monitor (http://technet.microsoft.com/en-us/sysinternals/bb896645) with the filter set to your service's name to find out which file exactly cannot be located as a first step. Once you know which one can't be found, it should be easier to deduce the reason.
0
 
LVL 15

Author Comment

by:Karrtik Iyer
ID: 40325469
Thanks JKR and Mike, I downloaded the process monitor .
Just to understand if I am doing the right thing as per your suggestion.
1> I start the process monitor. In the search or Find option I set name of my service to find.
2> Start my service from windows service manager.
3> And see if anything gets listed in process monitor for that search.
Is this correct?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 86

Expert Comment

by:jkr
ID: 40325491
Yes, pretty much like that.
0
 
LVL 15

Author Comment

by:Karrtik Iyer
ID: 40325556
Hi JKR, I just did that, and all the entries for my service in Proc Mon either shows SUCCESS or Name not found result. None of them had failures or access denied results, any help?
Thanks,
karrtik
0
 
LVL 2

Expert Comment

by:wackym
ID: 40325565
That's exactly it. "Name not found" means it tried to open/load a file which wasn't found. ...and in the same line it says which application tried to access the file and what's the files path.

Best regards,
Mike
0
 
LVL 15

Author Comment

by:Karrtik Iyer
ID: 40325929
Thanks Mike, I shall look into it tomorrow, however whatever little I saw of the name not found entries, they for the parameters that were passed as blank or null for the createservice, openservice, and startservice apis.
0
 
LVL 15

Author Comment

by:Karrtik Iyer
ID: 40328733
Hi Mike and JRK, None of the entries in Proc Mon suggested that something was missing or file was not been read or access denied. however i compared the proc man entries for the service on the machine where it runs fine as compared to the machine where it is giving error (System could not find the file specified). When I compared those entries, the below entries are present for my service where it runs successfully, however it is not present in the machine that errors out. All these DLL's are present in both the machines. I have pasted the information below. Anything that strikes either of you? I compared the system services running on both machines and both seem to be the same. Please advise and help. Thanks in advance.

apphelp.dll         Application Compatibility Client Library  Microsoft Corporation C:\Windows\SysWOW64\apphelp.dll
C_1252.NLS                                        C:\Windows\System32\C_1252.NLS
cryptsp.dll           Cryptographic Service Provider API          Microsoft Corporation   C:\Windows\SysWOW64\cryptsp.dll
dnsapi.dll             DNS Client API DLL           Microsoft Corporation   C:\Windows\SysWOW64\dnsapi.dll
mswsock.dll       Microsoft Windows Sockets 2.0 Service Provider               Microsoft Corporation                C:\Windows\SysWOW64\mswsock.dll
rsaenh.dll            Microsoft Enhanced Cryptographic Provider        Microsoft Corporation                C:\Windows\SysWOW64\rsaenh.dll
SortDefault.nls                                  C:\Windows\Globalization\Sorting\SortDefault.nls
wintrust.dll         Microsoft Trust Verification APIs               Microsoft Corporation   C:\Windows\SysWOW64\wintrust.dll
WSHTCPIP.DLL  Winsock2 Helper DLL (TL/IPv4)   Microsoft Corporation   C:\Windows\SysWOW64\WSHTCPIP.DLL
0
 
LVL 15

Accepted Solution

by:
Karrtik Iyer earned 0 total points
ID: 40330016
Hi Mike and JKR, I resolved this issue. Proc Mon could not help much.
The problem was that the service that I was running was on a virtual drive (mapped using VSUBST software http://www.ntwind.com/software/utilities/visual-subst.html).
Hence it was not starting. Once I moved it to a permanent drive (volume) it worked.

Thanks a lot for your inputs and suggestions.

Regards,
Karrtik
0
 
LVL 15

Author Closing Comment

by:Karrtik Iyer
ID: 40338643
No file access was denied nor registry entries were the issue. The issue was because of service being run from a virtual drive.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now