Mapping a network share to a drive-letter at system-level

  • Thread starter Thread starter Leo R
  • Start date Start date
L

Leo R

Hi,

Is it possible to create a network-drive at the SYSTEM-level? E.g.: map X:
to \\server1\share so a windows service can reach X: without having to log
on? I want a Windows .NET service to collect files from a UNIX-share (mapped
to X:) that is exposed to windows using Hummingbird-software.

Leo.
 
Hi Leo,

As stated in another thread, you can use WNetAddConnection2() API whose
first parameter is NETRESOURCE structure. NETRESOURCE.lpLocalName field
points to a null-terminated string that specifies the name of a local
device to redirect, such as "X:".

WNetAddConnection2
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wnet/wnet/w
netaddconnection2.asp

Please feel free to let me know if you have any problems.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi HuangTM,

Thanks for your reply. I posted a similar question in another thread and I
got your answer, which was exactly what I wanted at the time. The problem
however seems to be a little different now:

I use Hummingbird software (NFS) to connect e.g: X: to a UNIX-share. I can
only do this while being logged on (administrator).

When I run a service (localsystem), I can of course not 'see' the X-drive,
that is only available in my administrator logon-session.

The question is: can I create a connection in a administrator logon-session
that is available to a windows-service that runs under that same
administrator-account?

I don't think I can create this network connection from code, because I also
need the Hummingbird software to create the network connection.

Thanks in advance, Leo.
 
Hello Leo,

Thanks for your reply. Now I'd like to share the following information with
you:

1. We are able to configure a service to log on as a specific account
instead of the default Local System account by the following steps:

a. Go to "Control Panel" -> "Administrative Tools" -> "Services".
b. Right click the service and choose "Properties".
c. Go to "Log On" panel, click "This account" and input corresponding user
name and password.

2. You can also call the API LogonUser() to log a user on to the local
computer:
LogonUser
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/security/se
curity/logonuser.asp

3. Since Hummingbird software (NFS) is a third-party tool, I suggest that
you can also contact the software vendor and see if there is any APIs
exposed for you to dynamically map a UNIX-share in your application/service.

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thanks Tim,

I created a seperate service for the file-handling, which is running under
an account that has access to mapped-drives that are linked to the
UNIX-shares. It works fine now. The solution was much easier than I thought.
Thanks for your help.

Leo.
 
Hi Tim,

I'm still having trouble here. After changing the windows .NET service-logon
from localsystem to administrator, my routine in the service could reach the
network-drives. So I was happy!

However, the next time I started the service, again I couldn't reach the
network drives. The service runs under the administrator account and I've
double checked this by writing the WindowsIdentity.name to the system-log.

When the routine tries to get the files from the network-directory
(IO.Directory.GetFiles(path)) [where path is X:\test - which is perfectly
accessible when logging on as an administrator - X: mapped to \\server\c],
the catched error-message is: 'Could not find part of the path: "X:\test".
Even when I map X to a path on the local machine, I get the same error.

When I run this EXACT same routine from a stand-alone application (logging
on as administrator of course) everything works fine. I'm really puzzled
here. Am I missing something? Security issue? The routine is in a seperate
DLL that is called by the service / stand alone windows application.

Leo.
 
Hello Leo,

Thanks for your informtion. I am not familiar with Hummingbird software
(NFS), still I believe the following issue you may take into consideration:

The timing of Hummingbird software (NFS) restore the connection. Generally
speaking, when we configure a service to log on as a specific account,
Windows only ensures the service run as the account's preveliges you
specified and will not restore the network connection. While we manually
log on the Windows system, it will create a visible Window Station and
initialize the Desktop that will map the corresponding network share. After
manually logging on as Administator account, you can stop/restart the
service and see if it can access the network share then.

To work around this problem, I strongly recommend you contact Hummingbird
Software and check if there is any APIs or command that you can call from
within your service to create a network connection to a UNIX-share.

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thanks Tim,

I'll follow your advice and contact Hummingbird. It seems to be the best
option for now.

Leo.
 
Back
Top