473,789 Members | 2,544 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 #1
17 2573
AFAIK, threre is a problem with .NET apps to work from mapped drive, because
system can't work (use metadata) from that drive.

I reckon u need to write unmanaged service (C++/VB), and it should work

"djmob" wrote:
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???


--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

Mar 1 '06 #2
The cause of this is you have to remember that the Service has to be
running under a certain context.
Whenever any process is run on windows it is run within a Context. (A
context being things like user credentials, current working directory
etc)

When the service starts the CWD will be system32 since it was invoked
by the SCM eg c:\windows\syst em32

You must change the working directory to the directory of where your
executable in your OnStart or in your Main() of your service
implementation you can do this by doing the following:

protected override void OnStart(string[] args)
{

//EventLog.WriteE ntry("Current working Directory Before
Assignment:"+En vironment.Curre ntDirectory);

Environment.Cur rentDirectory =
System.AppDomai n.CurrentDomain .BaseDirectory;

//EventLog.WriteE ntry("Current working Directory
is:"+Environmen t.CurrentDirect ory);

//rest of OnStart Code here...
}


djmob wrote:
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 #3
Are mapped drives not only mapped when a user logs in? Thus how would the
service start when the computer was restarted and the mapped drives does not
exist?
"djmob" <u19229@uwe> wrote in message news:5c9b5a53c8 9d9@uwe...
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 #4
Thanks alot for the help. I will give it a shot and see what happens.

Amir_Hasan wrote:
The cause of this is you have to remember that the Service has to be
running under a certain context.
Whenever any process is run on windows it is run within a Context. (A
context being things like user credentials, current working directory
etc)

When the service starts the CWD will be system32 since it was invoked
by the SCM eg c:\windows\syst em32

You must change the working directory to the directory of where your
executable in your OnStart or in your Main() of your service
implementati on you can do this by doing the following:

protected override void OnStart(string[] args)
{

//EventLog.WriteE ntry("Current working Directory Before
Assignment:"+E nvironment.Curr entDirectory);

Environment.Cu rrentDirectory =
System.AppDoma in.CurrentDomai n.BaseDirectory ;

//EventLog.WriteE ntry("Current working Directory
is:"+Environme nt.CurrentDirec tory);

//rest of OnStart Code here...

}
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???

Mar 1 '06 #5


"djmob" <u19229@uwe> wrote in message news:5c9b5a53c8 9d9@uwe...
|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???
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 #6
Drive mappings are associated with a User who is logged in. a user maps
drives in Explorer. Services are run in general under a system account.
You can change a service user to use a specific account but I believe
that this is so that the Context the service is running in can get
specific priviliges.
I don't think this will work altough you can try it

1) using explorer Create a permenant drive mapping to a network
Location
2) using explorer create a txt file with some test data on that network
drive
3) Write a .NET service that will read that file using the drive
mapping file path and write the context it to a local folder
c:\documents and settings\user\m y documents\testf ile.txt
4) Register the service account details to be that user
5) Set the service to be automatic startup
6) Restart the machine
Logon to the machine as someone else eg local administrator etc who
does not have the drive mapping to see if the file created. (ie was it
able to read the drive mapping)

I believe you won't be able to do it. You can try.

Mar 1 '06 #7

"Amir_Hasan " <ah****@gmail.c om> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
| The cause of this is you have to remember that the Service has to be
| running under a certain context.
| Whenever any process is run on windows it is run within a Context. (A
| context being things like user credentials, current working directory
| etc)
|
| When the service starts the CWD will be system32 since it was invoked
| by the SCM eg c:\windows\syst em32
|
| You must change the working directory to the directory of where your
| executable in your OnStart or in your Main() of your service
| implementation you can do this by doing the following:
|
| protected override void OnStart(string[] args)
| {
|
| //EventLog.WriteE ntry("Current working Directory Before
| Assignment:"+En vironment.Curre ntDirectory);
|
| Environment.Cur rentDirectory =
| System.AppDomai n.CurrentDomain .BaseDirectory;
|
| //EventLog.WriteE ntry("Current working Directory
| is:"+Environmen t.CurrentDirect ory);
|
| //rest of OnStart Code here...
|
|
| }
|
|
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 #8
No, drives can be mapped as long as the 'Workstation' service runs, and they
can be mapped in any logon session.

Willy.

"Arran Pearce" <ar*********@ce llhire.com> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
| Are mapped drives not only mapped when a user logs in? Thus how would the
| service start when the computer was restarted and the mapped drives does
not
| exist?
|
|
| "djmob" <u19229@uwe> wrote in message news:5c9b5a53c8 9d9@uwe...
| >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 #9
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 #10

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

Similar topics

3
5221
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
3432
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
19600
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
2863
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
2901
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
2295
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
9511
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,...
1
10136
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,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
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
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.