Solved

Connect to Network Folder on Application Start from Workgroup Configuration

Posted on 2009-07-16
1
443 Views
Last Modified: 2012-06-21
I have a customer who has a wireless network set up in workgroup configuration such each laptop on the network does not automatically connect to folders outside that computer when the laptop is powered up.  She is using an appiclation (developed by me) that connects to a database located on a PC or server located other than the one that contains the application that needs to connect to the database, like so:

Laptop application >>>>>>>> PC (containing database)<<<<<<<<<<<<<Laptop (application)

The PC is not automatically accessible to the laptops on startup, so right now she either needs to use a tool in the application itself to reconnect to the PC or use Windows Explorer to find the folder and then open the application.  It would be preferred if somehow the application could just automatically open the relevant networked folder without requiring a user to "manually" connect to it.  How can I do that?

Incidentally, I know that the method System.Diagnostics.Process.Start("net", @"use \\folder\name password /user:user") will work, but it flashes the DOS screen on the page when executed, which might be alarming to users, so I was hoping there's another way.  

Thanks.  Please let me know if you need additional information.  

0
Comment
Question by:l2Bravo
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
Comment Utility
Network driver mapping, using the Windows Script Host Object Model:
// Add a COM reference to Windows Script Host Object Model.
 

using IWshRuntimeLibrary;

using System;

using System.Runtime.InteropServices;

using System.IO;
 

public class NetworkDriveMapper : IDisposable

{
 

    // Create a new shell object.

    private WshNetwork _networkShell = new WshNetwork();
 

    public void MapDrive(string driveLetter, string networkPath, bool isPersistent, string userName, string password)

    {

        // Disconnect the drive first, forcing a permanent change.

        DisconnectDrive(driveLetter, true, true);
 

        // Map the drive to the path.

        object persistent = isPersistent;

        object user = userName;

        object pwd = password;
 

        _networkShell.MapNetworkDrive(driveLetter, networkPath, ref persistent, ref user, ref pwd);

    }
 

    public void DisconnectDrive(string driveLetter, bool willForce, bool isPersistent)

    {
 

        if (Directory.Exists(driveLetter))

        {

            object force = willForce;

            object updateProfile = isPersistent;
 

            _networkShell.RemoveNetworkDrive(driveLetter, ref force, ref updateProfile);

        }
 

    }
 

    void IDisposable.Dispose()

    {

        if ((_networkShell != null))

        {

            Marshal.ReleaseComObject(_networkShell);

            _networkShell = null;

        }

    }

}

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

If your business is like most, chances are you still need to maintain a fax infrastructure for your staff. It’s hard to believe that a communication technology that was thriving in the mid-80s could still be an essential part of your team’s modern I…
PRTG Network Monitor lets you monitor your bandwidth usage, so you know who is using up your bandwidth, and what they're using it for.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now