473,802 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with services

I am very new to .NET and Windows programming in general so please bare with
me...

I created a Windows service by deriving a class from ServiceBase and
installing it via the 'sc create' commands as follows:

sc create <name> binPath= <path>

Where path is the fully qualified path name. The new service appeared in the
Services GUI and I was able to start and stop it without problems. Next I
recreated the service via the 'sc create' command where binPath used a mapped
drive letter via the subst command i.e. 'subst x: c:\actual\path\ name' The
service is created but it does not start and I get the following error
message:

Could not start the <name> service on Local Computer. Error 3: The system
cannot find the path specified.

Unfortunately it is a requirement of my project to be able to used a mapped
driver letter. It appears that when the service is started it has no
knowledge of the drive mappings in my environment. After some research it
also appears that using the subst command is discouraged in later versions of
Windows and the preferred method is to use net commands. I have not been
entirely successful with the net commands and hope there is another approach
to solving this problem. Any suggestions???
Mar 1 '06
17 2575
When you say the "The SCM can not start a service that is located on
a remote server" you mean even if it is mapped to the local drive i.e. 'subst x: c:\path'.
The reason this is a requirement is that I am turning an existing application
into a service and it is important for us to preserve this drive mapping to
support our current development environment (the exact details of why this is
important is a little sketchy to me too). The only reason I brought up the
net commands is that I thought there was something inherent in the subst
command for it not to work with a service.

As I said before this is very new to me so I hope I am making some sense.

Willy Denoyette [MVP] wrote:|I am very new to .NET and Windows programming in general so please bare with
| me...
[quoted text clipped - 21 lines]
| entirely successful with the net commands and hope there is another approach
| to solving this problem. Any suggestions???

Service executables should be stored on local drives, what you are trying is
not a supported scenario. The SCM can not start a service that is located on
a remote server, the reason is that SCM (Service.exe) runs as SYSTEM
(localsystem ) which is a local security account that has no network access
token. Note that it's possible for SYSTEM to access remote resources from
domain members running in a W2K Active Directory domain, provided that the
"server" starting the service is granted access to the remote share (the
server name is used to authenticate over the network in this case), but even
then there is in guarantee that the service will get loaded, for instance
what if the remote server is not up?
Honestly, I don't see any reason why you need to load a service from a
remote share, I'm I missing something?.

Willy.

Mar 1 '06 #11
Your right I was assuming the Service Implementation is within the same
assembly as the executable (the exe assembly with the Main.) If it is
not you have to make sure that Appdomain Private Path contains the
path of the assembly that is implementing the service (and any of its
dependencies) so that the CLR can find it. You will then have to use
Reflection to load it using Activator.Creat eInstance

This can be done by appending private path to the appdomain in the
static Main e.g.
static void Main(string [] args)
{
AppDomain.Curre ntDomain.Append PrivatePath("se rviceimp"); //note this
assumes the assembly with YourServiceAsse mbly.dll is in a subfolder
(with its private dependencies ) called serviceimp
System.ServiceP rocess.ServiceB ase[] ServicesToRun;
System.ServiceP rocess.ServiceB ase impl =
Activator.Creat eInstance("Your ServiceAssembly ,ServiceImpl.My Service");
// note the fully qualified class name is ServiceImpl.MyS ervice where
ServiceImpl is the namespace
ServicesToRun = new System.ServiceP rocess.ServiceB ase[] { impl };
System.ServiceP rocess.ServiceB ase.Run(Service sToRun);
}

I hope this makes sense.

..

Mar 1 '06 #12
Sorry I am not addressing the underlying issue. Your basically stuffed.
Mapped and substited drives are in terms of a user who has logged in.
the SCM that is running up your service is running under the system
account and so does not know anything about the substituted X:. This is
even before the CLR has loaded or kicked in there is basically nothing
you can do. Please ignore my previous posts

Mar 1 '06 #13
The SCM knows x: is not a real local drive, so it asks the 'Workstation'
service (also called the redirector)to resolve the path, which is not
possible as per my previous explaination, and it's not what you are after
anyway.

What you need to do is:
1. Load your service from a local drive (loading from a remote drive would
not give access to that drive from within your service anyway) and run it as
a user account with access privileges to the remote share, that is as:
- a domain account or
- a shadow account, that is a local account with the same credentials (user
name and password) that exists on both servers.

2. Don't use drive letters to access the remote share, use UNC paths instead
(like : \\server\shared \filename ).

If you can't use UNC paths (I see no reason why not), you need to map the
drive from withing your service.
This can be done using:
1 - PInvoke "NetUserAdd " or "WNetAddConnect ion2, or
2 - a by invoking the utility "net.exe" using Process.Start from within your
service.
complete command looks something like:
net use x: \\servername\sh are /user:remoteserv ername\userName pwd
where: remoteservernam e is the name of the remote machine
userName is the name o a user on above with valid access privileges
to the share
pwd is it's password.

Willy.
"djmob" <u19229@uwe> wrote in message news:5c9c092af5 3d7@uwe...
| Yes that is correct. The problem is with the service being loaded from a
| locally mapped drive. Currently the drive is mapped using the subst
command
| i.e. 'subst x: c:\pathToServic e'.
|
| Willy Denoyette [MVP] wrote:
| >| The cause of this is you have to remember that the Service has to be
| >| running under a certain context.
| >[quoted text clipped - 24 lines]
| >|
| >| }
| >
| >This makes no sense, sorry, the problem is that the service cannot be
loaded
| >so certainly not be started, how would this solve the problem?
| >
| >Willy.
Mar 1 '06 #14
I think your right. Thanks for the help.

Amir_Hasan wrote:
Sorry I am not addressing the underlying issue. Your basically stuffed.
Mapped and substited drives are in terms of a user who has logged in.
the SCM that is running up your service is running under the system
account and so does not know anything about the substituted X:. This is
even before the CLR has loaded or kicked in there is basically nothing
you can do. Please ignore my previous posts

Mar 1 '06 #15
Sorry but, you got it wrong again, the problem can not be solved in the
service code, the problem is that the Service Control Manager (the SCM)
cannot load the exeutable from the path as defined by the configuration
utility.
The service path is configured like : x:\myservice.ex e, but the SCM does not
know what x: is all about so he asks the Workstation service to resolve the
mapping, which is not possible either, because it's the result of "subst"
command done in the interactive users logon context. So, it's not a network
share redirection either, which is finaly what the OP is trying to sumulate
(wrongly).

Willy.

"Amir_Hasan " <ah****@gmail.c om> wrote in message
news:11******** *************@v 46g2000cwv.goog legroups.com...
| Your right I was assuming the Service Implementation is within the same
| assembly as the executable (the exe assembly with the Main.) If it is
| not you have to make sure that Appdomain Private Path contains the
| path of the assembly that is implementing the service (and any of its
| dependencies) so that the CLR can find it. You will then have to use
| Reflection to load it using Activator.Creat eInstance
|
| This can be done by appending private path to the appdomain in the
| static Main e.g.
| static void Main(string [] args)
| {
| AppDomain.Curre ntDomain.Append PrivatePath("se rviceimp"); //note this
| assumes the assembly with YourServiceAsse mbly.dll is in a subfolder
| (with its private dependencies ) called serviceimp
| System.ServiceP rocess.ServiceB ase[] ServicesToRun;
| System.ServiceP rocess.ServiceB ase impl =
| Activator.Creat eInstance("Your ServiceAssembly ,ServiceImpl.My Service");
| // note the fully qualified class name is ServiceImpl.MyS ervice where
| ServiceImpl is the namespace
| ServicesToRun = new System.ServiceP rocess.ServiceB ase[] { impl };
| System.ServiceP rocess.ServiceB ase.Run(Service sToRun);
| }
|
| I hope this makes sense.
|
| .
|
Mar 1 '06 #16

"djmob" <u19229@uwe> wrote in message news:5c9c1a1dd1 373@uwe...
| When you say the "The SCM can not start a service that is located on
| >a remote server" you mean even if it is mapped to the local drive i.e.
'subst x: c:\path'.
|
| The reason this is a requirement is that I am turning an existing
application
| into a service and it is important for us to preserve this drive mapping
to
| support our current development environment (the exact details of why this
is
| important is a little sketchy to me too). The only reason I brought up
the
| net commands is that I thought there was something inherent in the subst
| command for it not to work with a service.
|

Service are not regular application, this is something you need to consider
when turning regular applications into Services, something that is common
place since the introduction of .NET.
Everyone seems to need services these day's, which IMO, is terribly wrong in
most circumstances.

I have explained what you have to do in an other reply, but before you do,
make sure you know what services are all about, what they are meant to solve
and what their restrictions are. Failing to do your homework will bite you
sooner that later.
What you need to know to begin with is (non exhaustive!):
- Services are meant to run in a restricted security context, they need
(preferably) to run under service users credentials (localsystem, local
service or network service). Running them under domain credentials is a
security threat.
- The run in a secured desktop (in the background as the sage goes) that has
no access to the active (visible) desktop, the active desktop has no access
to the service(s) desktop(s) either. That means they should not have a UI,
nor should they assume they can access, the UI of a running programs, by
whatever means.
- They don't have access to the profile data of the currently logged on user
(interactive), nor should the assume the presence of such a user.
- They have access to the services hives for their private profile storage,
these are mapped as:
- HKU\.Default or S-1-5-18 for localsystem and all other accounts
running the service (local or domain)
- HKU \S-1-5-19 for Local Service
- HKU \S-1-5-20 for Network Service

None of these hives contain configuration data like printers and persistent
mapped network shares, application paths like MyDocuments, MyPictures etc;
paths to document folders etc...

They run their threads in an MTA, so, be sure your COM objects can live
safely in this context, inspect your COM servers requirements first.
They should not use any library that requires a UI to be present even not a
hidden window (think System.Drawing and managed/unmanaged DirectX).
Willy.


Mar 1 '06 #17
Thanks for the advice and help. Greatly appreciated.

Willy Denoyette [MVP] wrote:
I have explained what you have to do in an other reply, but before you do,
make sure you know what services are all about, what they are meant to solve
and what their restrictions are. Failing to do your homework will bite you
sooner that later.

Mar 1 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5223
by: David Fraser | last post by:
Hi We are trying to debug a problem with services created using py2exe. It seems that these problems have arisen after services were installed and removed a few times. OK, first the actual problem we're seeing. After compiling a service with py2exe, running "service -install" and attempting to start it from the Services dialog, it pops up the message "Windows could not start the Service on Local Computer. For more information,...
2
2233
by: DB | last post by:
Hi All Having stared at this all morning and altered various things with no effect other then to exasperate the problem i'm wondering if anyone could take a look at the code below and see why on earth it's failing - I'm getting a "Object doesn't suppport this property or method" Line 32 char 5 when i attempt to change the location, have looked all over for answers and not found anything on the net or in the js ref docs i have - any...
2
1769
by: Greg | last post by:
Please note: I have cross posted this from Newsgroup: microsoft.public.dotnet.framework.aspnet.webservices with a few minor changes... I am having a simple problem setting up the security on my test web service... My Web service code is: Imports System.Web.Services
2
2759
by: yqlu | last post by:
I hava developed a client in C# that is connected to a 3-party XML Web Services developed in Java based on the AXIS 1.1. Most methods call are successful except for one method named "findObjects" and return a complex type "FieldSearchResult". The error message as following : "Cannot assign object of type System.String to an object of type System.String. There is an error in XML document (23, 97)." By the way,I hava written a client in Java...
0
1338
by: graciezzzzz | last post by:
Hi all, I create a Web Service project called 'eSelectService' and another Class Library project called 'MonerisVO', and a Windows Form project called 'maps' as well. The reason why I need the Class Library project is because I don't want to pass more than 30 parameters when I try to invoke the Web Method. I used the class in Class Library as a value object to contain all the information I need.
1
3434
by: leslie_tighe | last post by:
Hello, I have webservice created with Axis 1.2.1 and that I am trying to consuming in .NET (VB) using the Microsoft provided tools. While I am able to consume methods on the service that return simple type, I cannot consume methods that return complex objects. I have tried experimenting, with this, but am at a bit of loss on where the problem lies. When I call the services from a browser, I do get back the response that contains valid...
5
19602
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was having a problem in the calling program. I searched online and found suggestions that I return an Array instead so I modified my code (below) to return an Array instead of an ArrayList. Now I get the message when I try to run just my webservice...
1
2864
by: louis_la_brocante | last post by:
Dear all, I am having trouble generating a client proxy for a webservice whose methods return a "complex" type. The type is complex in that it is a class whose members are a mix of primitive types and of more elaborate classes implementing IXmlSerializable. The resulting WSDL file for the webservice has two separate schemas in its <types> sections, and the client proxy (generated with wsdl.exe) is missing the definitions of the...
3
2903
by: Blasting Cap | last post by:
I'm using VS 2005, SQL 2005 reporting services. SQL reporting services is working, and I have it both on my local computer, as well as on a server. I've created a report in the SQL Business Intelligence development studio that works in that environment. I've uploaded the same report to both the Reporting services on my local computer as well as the server, and can log in to them and run the
5
2296
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
This code works fine in Windows Application. In Windows Application, I am able to zip the image files properly and it totally contains 900MB My problem is the same code which I used in my Windows Application, does not work while I run it with Windows services. In my Windows application I am able to zip the whole 900Mb without any problems, but in my windows services I am not able to zip the whole 900Mb. In Windows Services it throws an...
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10538
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.