469,327 Members | 1,226 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

Connecting to a network share not working in a Windows Service

I am using the Win23 API WNetCancelConnection2 and can sucessfully make a
connection to a share within my class. The class is called from a Windows
Form based test harness.

When I instantiate exactly the samce class from a Windows Wervice, I get "A
specified logon session does not exist. It may already have been terminated"
.. The error number is 1312.

I know the code to be good, so I suspect something around security / windows
accounts etc.

Any pointers?
(FYI I am using VB.Net and am an Admin on the machine)
Jul 21 '05 #1
5 8571
You'll probably need to set the service to login under a specified user that
has access to the network share, and also has rights to login as service.
(The default is to login as the "System" user which is a local account, and
will not have access to network resources.)

Lance
"JohnFol" <Ou************@WibbleObbble.Com> wrote in message
news:T6*****************@newsfe3-win.ntli.net...
I am using the Win23 API WNetCancelConnection2 and can sucessfully make a
connection to a share within my class. The class is called from a Windows
Form based test harness.

When I instantiate exactly the samce class from a Windows Wervice, I get "A
specified logon session does not exist. It may already have been terminated"
.. The error number is 1312.

I know the code to be good, so I suspect something around security / windows
accounts etc.

Any pointers?
(FYI I am using VB.Net and am an Admin on the machine)

Jul 21 '05 #2
Thanks for the ideas. Just to be clear, in "test" I validate my account
against a domain controller. My API call specifies a completely different
username / password.

I think the key point you are making is a Windows Service may not have
access to any network resources if started up as "LocalSystem"

I'll give it a bash,.
Many thanks

"Lance Wynn" <la********@N.O.S.P.A.M.hotmail.com> wrote in message
news:ek**************@TK2MSFTNGP15.phx.gbl...
You'll probably need to set the service to login under a specified user
that
has access to the network share, and also has rights to login as service.
(The default is to login as the "System" user which is a local account,
and
will not have access to network resources.)

Lance
"JohnFol" <Ou************@WibbleObbble.Com> wrote in message
news:T6*****************@newsfe3-win.ntli.net...
I am using the Win23 API WNetCancelConnection2 and can sucessfully make a
connection to a share within my class. The class is called from a Windows
Form based test harness.

When I instantiate exactly the samce class from a Windows Wervice, I get
"A
specified logon session does not exist. It may already have been
terminated"
. The error number is 1312.

I know the code to be good, so I suspect something around security /
windows
accounts etc.

Any pointers?
(FYI I am using VB.Net and am an Admin on the machine)

Jul 21 '05 #3

"JohnFol" <Ou************@WibbleObbble.Com> wrote in message
news:T6*****************@newsfe3-win.ntli.net...
I am using the Win23 API WNetCancelConnection2 and can sucessfully make a
connection to a share within my class. The class is called from a Windows
Form based test harness.

When I instantiate exactly the samce class from a Windows Wervice, I get
"A specified logon session does not exist. It may already have been
terminated" . The error number is 1312.

I know the code to be good, so I suspect something around security /
windows accounts etc.

Any pointers?
(FYI I am using VB.Net and am an Admin on the machine)


Not sure what you intend to do with this "WNetCancelConnection2" call, you
can only cancel connections running in the same logon session as the current
session. Did you establish a network connection from within the service?

Willy.

Jul 21 '05 #4
Good grief, not only did I write Windiows Wervice, but I cut'n'paste the
wrong API!

Appologies to all.

The Correct API is "WNetAddConnection2"

FYI I tried one of the other suggestions and set the project installer to
use NetworkService. On my PC this is great, but on a.n.other server (where I
log on as Admin to install) I get

"The account name is invalid or does not exist, or the password is invalid
for the account name specified."

Unless I can install it I cannot set the account under which it runs, soI'm
a bit stumped.

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...

"JohnFol" <Ou************@WibbleObbble.Com> wrote in message
news:T6*****************@newsfe3-win.ntli.net...
I am using the Win23 API WNetCancelConnection2 and can sucessfully make a
connection to a share within my class. The class is called from a Windows
Form based test harness.

When I instantiate exactly the samce class from a Windows Wervice, I get
"A specified logon session does not exist. It may already have been
terminated" . The error number is 1312.

I know the code to be good, so I suspect something around security /
windows accounts etc.

Any pointers?
(FYI I am using VB.Net and am an Admin on the machine)


Not sure what you intend to do with this "WNetCancelConnection2" call, you
can only cancel connections running in the same logon session as the
current session. Did you establish a network connection from within the
service?

Willy.

Jul 21 '05 #5

"JohnFol" <Ou************@WibbleObbble.Com> wrote in message
news:71***************@newsfe6-win.ntli.net...
Good grief, not only did I write Windiows Wervice, but I cut'n'paste the
wrong API!

Appologies to all.

The Correct API is "WNetAddConnection2"

FYI I tried one of the other suggestions and set the project installer to
use NetworkService. On my PC this is great, but on a.n.other server (where
I log on as Admin to install) I get

"The account name is invalid or does not exist, or the password is invalid
for the account name specified."

Unless I can install it I cannot set the account under which it runs,
soI'm a bit stumped.


Note that the "NetworkService" account is only available on XP and W2K3.
On W2K or NT you should run your service using domain account credentials.

Willy.
Jul 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Tommy.Vincent | last post: by
1 post views Thread by Jim Bayers | last post: by
2 posts views Thread by JohnFol | last post: by
2 posts views Thread by Michael | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.