0

I need to connect to a network drive for which i have the username and password however its not playing ball.

I first of all tried things such as the following: Connect to network drive with user name and password

This wasnt working for me so i decided to just call Net USE to give myself permissions

Process process3 = new Process()
{
    StartInfo = 
    {
        FileName = "cmd.exe",
        Arguments = "/C NET USE " + Aurora03.path + " " + Aurora03.password + " /User:" + Aurora03.username
    }
};

process3.Start();
process3.WaitForExit();

My arguments look like this

Arguments = "/C NET USE \\phd-aurora03\Aurinput\Reports\ Password /User:aurora"

Its returning exit code 2 i believe.

After this runs im getting the error saying i cant connect to the unc path so its not working at all.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Ben Bodie
  • 75
  • 12
  • 2
    If something doesn't work, don't assume it's broken. The answers in the linked question work. On Windows, there's no folder username and password. Connections are made using the current user account. If your domain account has permission to read that folder, you don't need any other username or password, nor *should* you need one. `NET USE` doesn't change that, it tries to *impersonate* another account, just as the answers in the linked question do. – Panagiotis Kanavos Mar 19 '19 at 15:15
  • Well the issue is, i need to run this program as a scheduled task. If i run it as the user it works, but when it tries to run as a scheduled task as that user it doesnt, so i need to make it realise again that it does have connection – Ben Bodie Mar 19 '19 at 15:18
  • To run on a remote machine you need to have the same user in the same user group on both machines and the credentials need to be setup properly. First get it working i a cmd.exe window before trying in c#. You should be able to use following : \\computer\share – jdweng Mar 19 '19 at 15:19
  • I've fixed this by just doing it all in the bat file, rather than passing the command in as an argument, i just have a bat file with the command inside, and call that bat file instead – Ben Bodie Mar 20 '19 at 10:41

0 Answers0