Click here to Skip to main content
15,909,652 members
Home / Discussions / C#
   

C#

 
GeneralRe: Windows Installer condtions problem Pin
lieperik7-Apr-04 18:55
lieperik7-Apr-04 18:55 
GeneralRe: Windows Installer condtions problem Pin
Heath Stewart7-Apr-04 19:05
protectorHeath Stewart7-Apr-04 19:05 
GeneralRe: Windows Installer condtions problem Pin
lieperik7-Apr-04 19:19
lieperik7-Apr-04 19:19 
GeneralComboBox container Pin
DougW487-Apr-04 17:14
DougW487-Apr-04 17:14 
GeneralRe: ComboBox container Pin
Heath Stewart7-Apr-04 18:20
protectorHeath Stewart7-Apr-04 18:20 
GeneralRe: ComboBox container Pin
DougW487-Apr-04 18:42
DougW487-Apr-04 18:42 
Generalmap network drive Pin
Gardar G7-Apr-04 16:05
professionalGardar G7-Apr-04 16:05 
GeneralRe: map network drive Pin
Roman Rodov7-Apr-04 17:54
Roman Rodov7-Apr-04 17:54 
Absolutely! Here is what you need to do.

Add these declarations inside your class:
   [StructLayout(LayoutKind.Sequential)]
   private class NETRESOURCE
   {
    public Int32 dwScope;
    public Int32 dwType;
    public Int32 dwDisplayType;
    public Int32 dwUsage;
    public string lpLocalName;
    public string lpRemoteName;
    public string lpComment;
    public string lpProvider;
   }

[DllImport("mpr.dll")]
private static extern Int32 WNetAddConnection2 (
                                NETRESOURCE lpNetResource, 
                                [MarshalAs(UnmanagedType.LPTStr)] string lpPassword, 
                                [MarshalAs(UnmanagedType.LPTStr)] string lpUsername, 
                                Int32 dwFlags);
[DllImport("mpr.dll")]
private static extern Int32 WNetCancelConnection2 (
                                [MarshalAs(UnmanagedType.LPTStr)] string lpResourceName, 
                                [MarshalAs(UnmanagedType.Bool)] bool bForce);


THen Write a function:
void MapShareToDrive(string share, string, localdrive, string username, string password);
{
// Prepare for network access
NETRESOURCE netResource = new NETRESOURCE();
netResource.dwScope = 1;
netResource.dwType = 1;
netResource.lpLocalName = localdrive;
netResource.lpRemoteName = share;
// Connect to network share
int iRetVal = WNetAddConnection2(netResource, password, username, 0);
// You can also do the following to make the system prompt for username/password
// int iRetVal = WNetAddConnection2(netResource, "", "", 24);
if (iRetVal != 0)
{
  throw new System.IO.IOException("Failed to gain access to network share. Error code: " + iRetVal);
}
} 


EDIT: Changed marshaling for string parameters to [MarshalAs(UnmanagedType.LPTStr)] .. but anyway my code would work fine on Windows NT and later
GeneralRe: map network drive Pin
Heath Stewart7-Apr-04 18:00
protectorHeath Stewart7-Apr-04 18:00 
GeneralRe: map network drive Pin
Gardar G8-Apr-04 15:37
professionalGardar G8-Apr-04 15:37 
GeneralRe: map network drive Pin
Heath Stewart7-Apr-04 18:06
protectorHeath Stewart7-Apr-04 18:06 
GeneralRe: map network drive Pin
Gardar G8-Apr-04 4:17
professionalGardar G8-Apr-04 4:17 
GeneralStrange question but I need some help. Pin
KevinMac7-Apr-04 15:34
KevinMac7-Apr-04 15:34 
GeneralRe: Strange question but I need some help. Pin
Heath Stewart7-Apr-04 17:57
protectorHeath Stewart7-Apr-04 17:57 
GeneralRe: Strange question but I need some help. Pin
Jeremy Kimball8-Apr-04 7:27
Jeremy Kimball8-Apr-04 7:27 
GeneralRe: Strange question but I need some help. Pin
Heath Stewart8-Apr-04 8:18
protectorHeath Stewart8-Apr-04 8:18 
GeneralRecommended C#/.NET Book Pin
valikac7-Apr-04 12:34
valikac7-Apr-04 12:34 
GeneralRe: Recommended C#/.NET Book Pin
Heath Stewart7-Apr-04 17:53
protectorHeath Stewart7-Apr-04 17:53 
GeneralRe: Recommended C#/.NET Book Pin
Nick Parker8-Apr-04 2:40
protectorNick Parker8-Apr-04 2:40 
General.NET adding things to ArrayList at random Pin
kayhustle7-Apr-04 10:54
kayhustle7-Apr-04 10:54 
GeneralDataSet between Forms Pin
hxxbin7-Apr-04 9:26
hxxbin7-Apr-04 9:26 
GeneralRe: DataSet between Forms Pin
Colin Angus Mackay7-Apr-04 9:53
Colin Angus Mackay7-Apr-04 9:53 
GeneralWebSvcs : Dynamic Pin
Kant7-Apr-04 6:40
Kant7-Apr-04 6:40 
GeneralRe: WebSvcs : Dynamic Pin
Daniel Turini7-Apr-04 6:49
Daniel Turini7-Apr-04 6:49 
GeneralRe: WebSvcs : Dynamic Pin
Kant7-Apr-04 7:06
Kant7-Apr-04 7:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.