Accessing an NFS share from a Windows service - c#

I have a Windows service that can't access an NFS share on a UNIX box. I can't access the share with the UNC path, so I have to have it mounted.
I have a console application that can see the drive and runs fine, but when I deploy my Windows service, it can't see the drive.
I have the drive mounted as my local user as well as the administrator.
I've tried mounting a drive from my application by using "Process.Start(mBatchFilePath);", but that didn't work either.
I'm running as the local user (set as administrator).
Tried using a symbolic link
Going to try to set up an FTP to transfer the files
Does anyone have any suggestions on how I can make this work?
SOLVED: I used SSH.Net and transfer files with an SFTP server

I don't think that mapping the drive to a symbolic link is a real solution. The Problem is, that the service runs under a certain user account and thus it accesses all resources with the privileges of this account. Of course your IT admin is right, it's not a good idea to let the service run under the local administrator account.
You should create a new user account that is allowed to access the shared folder. Then set up the service that it runs under this account and the service should be able to access the network share. But remember, a network share that is mapped to a drive letter is only mapped for the current user. So the service (that runs under a different user account) simply doesn't have any drive with this letter, it is not mapped under its account.
So in your service you should always access the share with its full UNC path and not with a mapped drive letter.

Since we were connecting to a Solaris server from a windows box I needed to use SFTP to send files to the server.
I contemplated some sort of a folder sync, but it wasn't a route I wanted to go down.
I used the SSH.Net libraries.

Related

Windows Service failing to access mapped network drive

My C# based Wcf application hosted as windows service is unable to access mapped network drive even though it works with UNC path. I have come across the below article which states that it is not possible to use mapped drives with windows service.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms685143(v=vs.85).aspx
In my scenario I am logging into the service with a domain account & the same account is used to create the mapped network drive in the machine.
My company has all clients running the projects in mapped drives and they would want the service also to run and access the mapped drive configurations for pulling data.
In this scenario I am wondering if there could be a possible workaround given the situation that network drive would be created with the same account that the service is logged in with.
Any possible workaround or code fixes would be highly appreciated. Thanks .

not able to open a file from share drive

I was trying to browse a file(S:\Scalable Development\DRD_ToolPointManagement.doc) from shared location trough web browser using application. when I run my application in local, it is working where as if I push the code to dev and QA environment, not able to open a file
There are two different problems, firstly using a mapped drive and secondly access rights to the folder. Both of these depend upon which account the application is running under. Have a look at http://www.iis.net/learn/get-started/planning-for-security/understanding-built-in-user-and-group-accounts-in-iis
You need the built in group IIS_WPG which covers the application pool to have access to the network drive. If the S: drive is not mapped on the web server, you will also need to use the UNC path. If you look in Windows Explorer, your S: drive will appear something like
myshare (\\myserver) (S:) which should be translated to \\myserver\myshare\Scalable Development\DRD_ToolPointManagement.doc
Your domain administrator may need to allow access to the network share, and you may need to consider impersonation
When using the Web browser control, you're using the Internet Explorer. Thus, security settings may apply.
You need to change these in the Control Panel's internet settings of every machine you want to deploy to.
For example you may have to add the location to the trusted zone. Also, the target IE may not be configured to open Office documents in-place.

Check if file exists on remote server and various drive

We have an aspx page that needs to check if video files exist on our video server and display a link if the file does exist. However, our videos are not stored on the C drive, but on the D drive instead.
I have tried
System.IO.File.Exists(#"http://ourvideoserver/pcode/videofile_name.mp4") and
System.IO.File.Exists(#"\\ourvideoserver\\D:\\pcode\\videofile_name.mp4")
the last one was just taking a wild guess
And I cannot figure out how to check the files on a remote server on a different drive than C.
Could someone point me in the right direction on how to check in the D drive of the remote server
In UNC paths, drives are represented by a $. That is, D$. Try this:
System.IO.File.Exists(#"\\ourvideoserver\D$\pcode\videofile_name.mp4")
So, something like this should work (it does when I run it as a unit test with a change in the server name).
[TestMethod]
public void CheckUNCFileExists()
{
Assert.AreEqual(true, File.Exists("\\\\fileserver\\documents\\file.txt"));
Assert.AreEqual(true, File.Exists(#"\\fileserver\documents\file.txt"));
}
One thing that you might want to check is the name of the actual share, using an administrative command prompt on the file server (in my case it is the "documents" share):
C:\Windows\system32>net share
Share name Resource Remark
-------------------------------------------------------------------------------
C$ C:\ Default share
IPC$ Remote IPC
ADMIN$ C:\Windows Remote Admin
documents C:\documents
The command completed successfully.
If the path seems ok (and you can get to it with Windows Explorer), another thing to investigate is whether the application pool identity of your web application (probably you if you are debugging on your desktop using something like Visual Studio, or whatever your IIS admin configures on the web server side) has read access to the share (for windows sharing permissions) and read access (via NTFS permissions) on the folder/file (also, depending on how paranoid your admins are, you might also need "traverse" permissions on higher folders).
If you can't get to it with Windows Explorer, and you are using an administrative share (ex c$, d$, etc), you should re-share the folder with a different share name (since this will allow you to change permissions to make it readable by you/and the IIS application pool identity). If you are really bent on using the administrative share name, you'll have to modify permissions of the administrative share and may need to undertake something like this:
http://support.microsoft.com/kb/971277

Why does DriveInfo.GetDrives() not get network mapped drive in windows service

I have a windows service developed in .NET C# using VS 2010, I'm calling the DriveInfo.GetDrives() but it is not getting the Z: drive (a mapped network drive),
I did some googling and found some results pointing to windows account privileges, so I have tried all account types of service installer such as LocalSystem, User, LocalService, NetworkService but none worked and I still can't get the drive Z:.
I did another test, debugging the windows service (as a console application) and I can get drive Z: that way.
Is there a solution to my problem?
You need to run the windows service with an account that has the network drive mapped, for example, the same account that you used to run as a console application. As Hans advised you should not be using mapped drives in windows services because they are a concept associated to a real user.
However if you really want to continue to use mapped drives see this related question for pitfalls and workarounds related to this specific situation:
How to map a network drive to be used by a service
Drive mappings are associated with LUID and you could have multiple Authentication ID under the same user (e.g. service, normal integrity level, high integrity level etc).
You can have a normal integrity level process running in the user's session to provide the mapped drive list created by the user. This is how Windows Explorer copies mapped drives for elevated setup programs.

Can a Windows service running under Local System create new files on the computer it is running on?

I have created a Windows Service that has a function that creates a new file.
It is running under "Local System account" with "Allow service to interact with desktop" set to true.
When running under this account can files be created locally?
I can't debug this to get the exact error as it is running in a Lab Manager environment that has no suitable debugger installed.
It looks to me to be a permissions problem based on when the service crashes so the simple answer I need before trying anything else is can this account create files on the Local System?
I can't seem to find a site with the answer...?
Any help would be greatly appreciated.
"Allow service to interact with desktop" is only needed to be able to display messages for a logged in user.
Local System should have write access to local hard drives. You can not access mapped network drives or any other network resources for that matter.

Categories