By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,600 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,600 IT Pros & Developers. It's quick & easy.

can't use "NET USE" at windows services

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.