Need to map network drive

  • hi, i am trying to map the network drive using c# script of ssis to l local machine. So please any one help me to figure it out.

  • well the commands to create and delete are like this:

    but that's done via a command line...i'm not sure wehterh you'd do that in a script.

    I've done it via xp_cmdshell before too.

    NET USE Z: \\UNCPath\d$ /user:domain\user password

    NET USE Z: /DELETE

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Actually i am trying to map the drive using script in ssis + c#

  • I would actually warn against mapping drives if there is any way to prevent it. It is far better to use UNC paths. In my experieince unless I am trying to use ancient EXEs which can't handle UNC paths I have never had to map a drive.

    So why don't you explain what you are trying to accomplish overall instead of just how do I solve problem X.

    CEWII

  • Elliott Whitlow (3/16/2012)


    I would actually warn against mapping drives if there is any way to prevent it. It is far better to use UNC paths. In my experieince unless I am trying to use ancient EXEs which can't handle UNC paths I have never had to map a drive.

    So why don't you explain what you are trying to accomplish overall instead of just how do I solve problem X.

    CEWII

    Agreed, but can you pass along credentials with a UNC path?

    (the only reason I ever used mapped drives. Only 1 person in the company had access to the folder, so I had to create a mapped drive using that person's credentials)

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • True, you can't pass alternate credentials. This is why I would often create a proxy and the process would run in that context.

    CEWII

  • You can pass credentials when attaching to a UNC

    --clear any ipc$ connections

    net use \\server\share /delete

    --map the drive

    net use \\server\share /user:domain\username password

    --do whatever you want

    --cleanup

    net use \\server\share /delete

    it can also be done in c# by using net.exe via System.Diagnostics.Process.Start or as a p/invoke via API

  • jason_selph (3/22/2012)


    You can pass credentials when attaching to a UNC

    --clear any ipc$ connections

    net use \\server\share /delete

    --map the drive

    net use \\server\share /user:domain\username password

    --do whatever you want

    --cleanup

    net use \\server\share /delete

    it can also be done in c# by using net.exe via System.Diagnostics.Process.Start or as a p/invoke via API

    Jason you are missing my point, I wasn't talking about using NET USE at all, but a direct reference. However, your reference above would provide the correct security context..

    CEWII

  • The other alternative along those lines is to impersonate the security context in c# before accessing the network drive, then disposing each time. This would be better if you had different accounts for different shares in the same package as that could not be resolved by a single proxy.

  • I generally agree, but what you are trying to do and what technology you are trying to do it from have a big effect here, as well as the availability of xp_cmdshell which is disabled on most of my servers.

    CEWII

  • True, however the C# route does not use the sql xp command shell (that I know of) so would not be as limiting.

  • True but depending on how you get that C# code called was my point.

    CEWII

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply