Solved

Connect to Network Folder on Application Start from Workgroup Configuration

Posted on 2009-07-16
1
449 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
ID: 24878409
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Video Player 11 23
Problem!!! 8 33
Dns issues 4 37
Can you change the internal IP address on a Windows 2012 R2 server once it is deployed as DC and AD 8 38
Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
I had an issue with InstallShield not being able to use Computer Browser service on Windows Server 2012. Here is the solution I found.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

773 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