
WNetAddConnection2 in a service
I'm using the standard WNetAddConnection2 API call in my code. If I run it
in the load event of a windows form, then everything works fine. If,
however, I try to use it in the OnStart event of a windows service then the
first time I run it it works fine, but when I restart the service, it fails
with error 85 - ERROR_ALREADY_ASSIGNED. If I restart the machine then it
again works fine the first time the service runs, but again fails when the
service restarts.
I've tried adding a call to WNetCancelConnection2 before the connect
attempt. That is failing with error 2250 - ERROR_LOCAL_DRIVE
To keep this post manageable, I haven't included my own code as I don't
think it's necessary. If someone does want to see it the then let me know
and I can post it. The basic connection code is available here
http://www.*-*-*.com/
If anyone else has come across this problem in a service, then I'd love to
hear any ideas.
Thanks.
--
Rob Oldfield
www.realuk.co.uk