can't use "NET USE" at windows services

M

Mullin Yu

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());

}

}
 
M

Mullin Yu

one more info:
this.serviceProcessInstaller1.Account =
System.ServiceProcess.ServiceAccount.LocalSystem;

this.serviceProcessInstaller1.Password = null;

this.serviceProcessInstaller1.Username = null;

thanks!
 
W

Willy Denoyette [MVP]

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.
 
M

Mullin Yu

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 said:
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 said:
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());

}

}
 
W

Willy Denoyette [MVP]

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 said:
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 said:
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 said:
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());

}

}
 
M

Mullin Yu

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 said:
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 said:
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 said:
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.

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());

}

}
 
W

Willy Denoyette [MVP]

Mullin Yu said:
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.
 
M

Mullin Yu

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 said:
Mullin Yu said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top