473,326 Members | 2,090 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,326 software developers and data experts.

Network Share\Mapped Drive Access from a windows service

I am attempting to write a vb.net windows service that will automate various
file movements on my network. When I attempt to access files on a mapped
drive or UNC file share, I get exceptions claiming that the file is not
there. However if I copy the file path directly in to explorer it pops right
up.
I know that my service is running as local system and this must be causing
the problems. When I write the windowsidentity.getcurrent().name to the event
log, it reads as NT AUTHORITY\SYSTEM. I have tried impersonation with no
success. The service stops immediatley when attempting to run this line:

Private Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal
lpszUsername As [String], _
ByVal lpszDomain As [String], ByVal lpszPassword As [String], _
ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer, _
ByRef phToken As IntPtr) As Boolean

**As an added bonus, the file share I am trying to access is on an AS400. I
have mapped the drive and am attempting to use the pre-mapped drive. It would
be nice to authenticate directly to the AS400 from my code, and the use the
UNC share name for the directory on the 400.
Nov 21 '05 #1
2 9508
Hi,

http://www.dotnet247.com/247referenc...28/144136.aspx

Ken
--------------------
"Dave Stewart" <Da*********@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
I am attempting to write a vb.net windows service that will automate various
file movements on my network. When I attempt to access files on a mapped
drive or UNC file share, I get exceptions claiming that the file is not
there. However if I copy the file path directly in to explorer it pops right
up.
I know that my service is running as local system and this must be causing
the problems. When I write the windowsidentity.getcurrent().name to the
event
log, it reads as NT AUTHORITY\SYSTEM. I have tried impersonation with no
success. The service stops immediatley when attempting to run this line:

Private Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal
lpszUsername As [String], _
ByVal lpszDomain As [String], ByVal lpszPassword As [String], _
ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer,
_
ByRef phToken As IntPtr) As Boolean

**As an added bonus, the file share I am trying to access is on an AS400. I
have mapped the drive and am attempting to use the pre-mapped drive. It
would
be nice to authenticate directly to the AS400 from my code, and the use the
UNC share name for the directory on the 400.
Nov 21 '05 #2

"Dave Stewart" <Da*********@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
I know that my service is running as local system and this must be causing
the problems. When I write the windowsidentity.getcurrent().name to the
event
log, it reads as NT AUTHORITY\SYSTEM. I have tried impersonation with no
success.


Is there a specific reason you can't run the service under a domain account?
Nov 21 '05 #3

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

Similar topics

3
by: Robert Tarantino | last post by:
Hello, I am trying to find a way to create a scheduled task or service that will copy my local profile folders under "Documents and settings" to a network drive. This would allow me to restore...
6
by: moonriver | last post by:
I write a program accessing files in network drive o:. It is doable as a standalone application. However, if it is running under windows service, the following exception will appear: 13/07/2004...
5
by: Niloday | last post by:
Hi All, I am trying to access a mapped network drive from a service that I have created. The service needs to create/delete folders/files on a network drive. When I tried to connect to a...
3
by: Daniel Xiao | last post by:
I write a program accessing files in network drive o:. It is doable as a standalone application. However, if it is running under windows service, the following exception will appear: 13/07/2004...
3
by: Bonj | last post by:
I need to write a windows service, and the only way it can access a shared drive on a file server on the network is if the installer is put in "User" mode - "LocalService", "LocalSystem" and...
1
by: mbah Sumani via .NET 247 | last post by:
(Type your message here) I Think it's the stupidness of Windows. Why the service can't access network drive but console apps or windows application can do it? So my suggestion is make the program...
8
by: Lam | last post by:
HI anyone knows how can I open a mapped network file in C#? I try string file = @"T:\file.txt"; it shows me the error: "Could not find a part of the path" but if I copy the file to my C dirve,...
3
by: Miriam | last post by:
Hello, I created a Windows Service in VB.NET, which is to purge files periodically in the local system and also in the shared network drive. Here is my problem: 1. If I set the “Account”...
17
by: ayush patel | last post by:
Hi all, I have created a windows service that has a file watcher and does some operation after it reads that file. i developed it in my local machine and installed the service on server. i have...
5
by: Phil | last post by:
A file used by my application may be stored on a shared network drive, so that it can be accessed by different people using the same application. I have written some code that uses an...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.