473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

can't use "NET USE" at windows services

if i put the same code at the windows application or console, i can logon to
the computer. but, if i put the same code at the windows service and start
it, i still can't logon to the machine.

the return value is TRUE.

i tested it by going to windows explorer and then click that computer.

my coding at windows service:

protected override void OnStart(string[] args)

{

// TODO: Add code here to start your service.

// logon to a print server machine

try

{

Log("starting");

Process p = new Process();

p.StartInfo.RedirectStandardOutput = false;


p.StartInfo.FileName = "net";

p.StartInfo.Arguments = @"use \\solmis password123 /user:""sol\johnny yu""";

p.StartInfo.UseShellExecute = true;

bool rtn = p.Start();

Log("result: " + rtn.ToString());

}

catch(Exception ex)

{

Debug.WriteLine(ex.ToString());

Log(ex.ToString());

}

}
Nov 15 '05 #1
7 8629
one more info:
this.serviceProcessInstaller1.Account =
System.ServiceProcess.ServiceAccount.LocalSystem;

this.serviceProcessInstaller1.Password = null;

this.serviceProcessInstaller1.Username = null;

thanks!

"Mullin Yu" <mu*******@ctil.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
if i put the same code at the windows application or console, i can logon to the computer. but, if i put the same code at the windows service and start
it, i still can't logon to the machine.

the return value is TRUE.

i tested it by going to windows explorer and then click that computer.

my coding at windows service:

protected override void OnStart(string[] args)

{

// TODO: Add code here to start your service.

// logon to a print server machine

try

{

Log("starting");

Process p = new Process();

p.StartInfo.RedirectStandardOutput = false;


p.StartInfo.FileName = "net";

p.StartInfo.Arguments = @"use \\solmis password123 /user:""sol\johnny yu""";
p.StartInfo.UseShellExecute = true;

bool rtn = p.Start();

Log("result: " + rtn.ToString());

}

catch(Exception ex)

{

Debug.WriteLine(ex.ToString());

Log(ex.ToString());

}

}

Nov 15 '05 #2
Network logon sessions are tied to the windows logon session of the caller.
That means if you create a network session by calling 'NET USE' from a
service, this session is private to the windows logon session of the service
(running as localsystem). The interactive user can't use this network
session as he run's in another logon session.

What exactly are you trying to achieve?

Willy.

"Mullin Yu" <mu*******@ctil.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
if i put the same code at the windows application or console, i can logon
to
the computer. but, if i put the same code at the windows service and start
it, i still can't logon to the machine.

the return value is TRUE.

i tested it by going to windows explorer and then click that computer.

my coding at windows service:

protected override void OnStart(string[] args)

{

// TODO: Add code here to start your service.

// logon to a print server machine

try

{

Log("starting");

Process p = new Process();

p.StartInfo.RedirectStandardOutput = false;


p.StartInfo.FileName = "net";

p.StartInfo.Arguments = @"use \\solmis password123 /user:""sol\johnny
yu""";

p.StartInfo.UseShellExecute = true;

bool rtn = p.Start();

Log("result: " + rtn.ToString());

}

catch(Exception ex)

{

Debug.WriteLine(ex.ToString());

Log(ex.ToString());

}

}

Nov 15 '05 #3
In fact, I want to logon the the print server by using a domain account as a
window service so that everytime reboot the machine, the application can
print.

now, everytime after rebooting, i need to logon as a domain user to the
print server machine, and then my background application can then do the
printing. i have the limitation that even no one logs on to the computer,
the background application is still workable.

therefore, i want to change the manual work "running net use at command
line" to a windows service so that

1. can run even no one logs on
2. no need to afraid of forgetting logging on to the print server

thanks!

mullin

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:uH*************@tk2msftngp13.phx.gbl...
Network logon sessions are tied to the windows logon session of the caller. That means if you create a network session by calling 'NET USE' from a
service, this session is private to the windows logon session of the service (running as localsystem). The interactive user can't use this network
session as he run's in another logon session.

What exactly are you trying to achieve?

Willy.

"Mullin Yu" <mu*******@ctil.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
if i put the same code at the windows application or console, i can logon to
the computer. but, if i put the same code at the windows service and start it, i still can't logon to the machine.

the return value is TRUE.

i tested it by going to windows explorer and then click that computer.

my coding at windows service:

protected override void OnStart(string[] args)

{

// TODO: Add code here to start your service.

// logon to a print server machine

try

{

Log("starting");

Process p = new Process();

p.StartInfo.RedirectStandardOutput = false;


p.StartInfo.FileName = "net";

p.StartInfo.Arguments = @"use \\solmis password123 /user:""sol\johnny
yu""";

p.StartInfo.UseShellExecute = true;

bool rtn = p.Start();

Log("result: " + rtn.ToString());

}

catch(Exception ex)

{

Debug.WriteLine(ex.ToString());

Log(ex.ToString());

}

}


Nov 15 '05 #4
The background application needs to run with the same identity as the
service for this to work.
But creating a windows service for this is overkill, why don't you simply
start the background application from a batch/command file, in which you
issue a NET USE command to map the printer?

Willy.

"Mullin Yu" <mu*******@ctil.com> wrote in message
news:eN**************@TK2MSFTNGP12.phx.gbl...
In fact, I want to logon the the print server by using a domain account as
a
window service so that everytime reboot the machine, the application can
print.

now, everytime after rebooting, i need to logon as a domain user to the
print server machine, and then my background application can then do the
printing. i have the limitation that even no one logs on to the computer,
the background application is still workable.

therefore, i want to change the manual work "running net use at command
line" to a windows service so that

1. can run even no one logs on
2. no need to afraid of forgetting logging on to the print server

thanks!

mullin

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:uH*************@tk2msftngp13.phx.gbl...
Network logon sessions are tied to the windows logon session of the

caller.
That means if you create a network session by calling 'NET USE' from a
service, this session is private to the windows logon session of the

service
(running as localsystem). The interactive user can't use this network
session as he run's in another logon session.

What exactly are you trying to achieve?

Willy.

"Mullin Yu" <mu*******@ctil.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
> if i put the same code at the windows application or console, i can logon > to
> the computer. but, if i put the same code at the windows service and start > it, i still can't logon to the machine.
>
> the return value is TRUE.
>
> i tested it by going to windows explorer and then click that computer.
>
> my coding at windows service:
>
> protected override void OnStart(string[] args)
>
> {
>
> // TODO: Add code here to start your service.
>
> // logon to a print server machine
>
> try
>
> {
>
> Log("starting");
>
> Process p = new Process();
>
> p.StartInfo.RedirectStandardOutput = false;
>
>
>
>
> p.StartInfo.FileName = "net";
>
> p.StartInfo.Arguments = @"use \\solmis password123 /user:""sol\johnny
> yu""";
>
> p.StartInfo.UseShellExecute = true;
>
> bool rtn = p.Start();
>
> Log("result: " + rtn.ToString());
>
> }
>
> catch(Exception ex)
>
> {
>
> Debug.WriteLine(ex.ToString());
>
> Log(ex.ToString());
>
> }
>
> }
>
>



Nov 15 '05 #5
but, due to some security reasons, i can't permit to logon to the system
after reboot.

also, i've created several application specified printer drivers e.g.
postscript driver, print to file [file port], and so on, so that it's quite
different to use net use.

therefore, i want to have two windows services
1. logon to the printer server machine
2. start the printing application [get records from db and then print]

thanks!

regards,
mullin

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The background application needs to run with the same identity as the
service for this to work.
But creating a windows service for this is overkill, why don't you simply
start the background application from a batch/command file, in which you
issue a NET USE command to map the printer?

Willy.

"Mullin Yu" <mu*******@ctil.com> wrote in message
news:eN**************@TK2MSFTNGP12.phx.gbl...
In fact, I want to logon the the print server by using a domain account as a
window service so that everytime reboot the machine, the application can
print.

now, everytime after rebooting, i need to logon as a domain user to the
print server machine, and then my background application can then do the
printing. i have the limitation that even no one logs on to the computer, the background application is still workable.

therefore, i want to change the manual work "running net use at command
line" to a windows service so that

1. can run even no one logs on
2. no need to afraid of forgetting logging on to the print server

thanks!

mullin

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:uH*************@tk2msftngp13.phx.gbl...
Network logon sessions are tied to the windows logon session of the

caller.
That means if you create a network session by calling 'NET USE' from a
service, this session is private to the windows logon session of the

service
(running as localsystem). The interactive user can't use this network
session as he run's in another logon session.

What exactly are you trying to achieve?

Willy.

"Mullin Yu" <mu*******@ctil.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
> if i put the same code at the windows application or console, i can

logon
> to
> the computer. but, if i put the same code at the windows service and

start
> it, i still can't logon to the machine.
>
> the return value is TRUE.
>
> i tested it by going to windows explorer and then click that computer. >
> my coding at windows service:
>
> protected override void OnStart(string[] args)
>
> {
>
> // TODO: Add code here to start your service.
>
> // logon to a print server machine
>
> try
>
> {
>
> Log("starting");
>
> Process p = new Process();
>
> p.StartInfo.RedirectStandardOutput = false;
>
>
>
>
> p.StartInfo.FileName = "net";
>
> p.StartInfo.Arguments = @"use \\solmis password123 /user:""sol\johnny
> yu""";
>
> p.StartInfo.UseShellExecute = true;
>
> bool rtn = p.Start();
>
> Log("result: " + rtn.ToString());
>
> }
>
> catch(Exception ex)
>
> {
>
> Debug.WriteLine(ex.ToString());
>
> Log(ex.ToString());
>
> }
>
> }
>
>



Nov 15 '05 #6

"Mullin Yu" <mu*******@ctil.com> wrote in message
news:uP**************@TK2MSFTNGP11.phx.gbl...
but, due to some security reasons, i can't permit to logon to the system
after reboot.

also, i've created several application specified printer drivers e.g.
postscript driver, print to file [file port], and so on, so that it's
quite
different to use net use.

therefore, i want to have two windows services
1. logon to the printer server machine
2. start the printing application [get records from db and then print]

thanks!

regards,
mullin

As I said before, it's important to understand that network logon sessions
are tied to their "windows" logon session.

Let me explain, if you logon interactively, you create a logon session for
the duration of the session, that is until you logoff. All network sessions
created (use records) are tied to that windows logon session and cannot be
shared with other windows logon sessions, all programs launched during that
session can access to the network resources belonging to these network
sessions.

The same thing happens when the SCM starts a windows service, a logon
session is created for the service. Each service has his own logon session
and network sessions cannot be shared between them. So in your case network
sessions set-up by service 1 are not visible to service2, they are only
visible by programs running in the same windows logon session as service1,
or in other words, only the programs started from service1 can share the
same network resources.

What you could do is set-up the use records from service2, but there are a
few things you should keep in mind here.

- "Net use" is meant to be used from interactive sessions (they are end user
utilities right?).

- printjobs are meant to run in an interactive session, ever wondered what
happens if an error occurs?

- Services should not access network resources, if you really care about
security.

Willy.


Nov 15 '05 #7
i use the win32api to spool multiple files to the printers.

if i don't logon to the printer server machine, nothing will be printed out.
it's ok if i send the printout directly to the printer server machine
directly.

thanks!
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:ef**************@TK2MSFTNGP12.phx.gbl...

"Mullin Yu" <mu*******@ctil.com> wrote in message
news:uP**************@TK2MSFTNGP11.phx.gbl...
but, due to some security reasons, i can't permit to logon to the system
after reboot.

also, i've created several application specified printer drivers e.g.
postscript driver, print to file [file port], and so on, so that it's
quite
different to use net use.

therefore, i want to have two windows services
1. logon to the printer server machine
2. start the printing application [get records from db and then print]

thanks!

regards,
mullin

As I said before, it's important to understand that network logon sessions
are tied to their "windows" logon session.

Let me explain, if you logon interactively, you create a logon session for
the duration of the session, that is until you logoff. All network

sessions created (use records) are tied to that windows logon session and cannot be
shared with other windows logon sessions, all programs launched during that session can access to the network resources belonging to these network
sessions.

The same thing happens when the SCM starts a windows service, a logon
session is created for the service. Each service has his own logon session
and network sessions cannot be shared between them. So in your case network sessions set-up by service 1 are not visible to service2, they are only
visible by programs running in the same windows logon session as service1, or in other words, only the programs started from service1 can share the
same network resources.

What you could do is set-up the use records from service2, but there are a
few things you should keep in mind here.

- "Net use" is meant to be used from interactive sessions (they are end user utilities right?).

- printjobs are meant to run in an interactive session, ever wondered what
happens if an error occurs?

- Services should not access network resources, if you really care about
security.

Willy.



Nov 15 '05 #8

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

Similar topics

11
by: Codemonkey | last post by:
Hi, I am writing an App in .Net that involves some scheduling of tasks. I was wondering if anybody has come accross any components or examples of how to implement a schedule manager like the one...
12
by: Assaf | last post by:
Hi all, My client is using an online service provider that processes survey responses. After a user fills survey.aspx and presses the OK button, 2 things need to happen: 1. the data has to...
4
by: Joe | last post by:
I am using a 3rd party app that is constantly writing to a text log file. I would like to monitor that file with another app, but I keep getting the dreaded "in use" error when I try to read the...
2
by: Terry | last post by:
When using XMLDocument.Save(strFileName) in .NET 2005, is there a way to check (or trap) and see if the file is in use by another. I am using VB.NET. Currently it just bombs and says the filename...
3
by: SF | last post by:
How can I call a "net use" command from within my application? I need to dynamically connect to some remote shares. Thanks, Matt
2
by: amievil | last post by:
wow... I think I'm in a trouble now. My boss is a web programmer. She said, the client asked her to develop a " dot net C" application. So, she bought Microsoft visualstudio .NET 2003 and...
4
by: Adam Benson | last post by:
Hi, We have an app which, every now and then, has very high CPU usage. Profiling under perfmon shows it to be thread #3 which is running at >=95%. I took a process dump and looked at thread #3...
1
by: test63 | last post by:
hey, how i can use "net send" command to send a message using ip address? I use windows vista home premium.
4
by: ShadowLocke | last post by:
Hi, Im not very experienced with XSL, this is my first run in with it. I found an XSL file that converts a dataset to an excel readable format. The problem I have is when the dataset has a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.