일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- stream
- Android
- Read
- flutter
- compare
- Unity
- memory
- parameter
- java
- SERIAL
- Pointer
- sensor
- Binary
- Class
- preprocessing
- UNO
- aduino
- file access
- length
- Overloading
- Encapusulation
- Barcode
- atmega328
- digitalRead
- mfc
- APP
- wpf
- inheritance
- Contour
- public
- Today
- Total
폴크(FOLC)
C# 테크닉 - NetworkDrive 본문
# 네트워크에서 운영되는 HDD 드라이브
> 근거리 통신망으로 네트워크의 선택된 사용자에게 공유
> 표준 디스크 드라이브와 동일하게 액세스를 제공
# 소스 코드
using System;
using System.Text;
using System.Runtime.InteropServices;
// 연결 하기
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NetworkResource
{
public uint Scope;
public uint Type;
public uint DisplayType;
public uint Usage;
public string LocalName;
public string RemoteName;
public string Comment;
public string Provider;
}
[DllImport("mpr.dll", CharSet = CharSet.Auto)]
public static extern int WNetUseConnection
(
IntPtr ownerWindowHandle,
[MarshalAs(UnmanagedType.Struct)] ref NetworkResource networkResource,
string password,
string userID,
uint flag,
StringBuilder accessNameStringBuilder,
ref int bufferSize,
out uint result
);
public int ConnectDrive(string local_name, string remote_name, string userID, string password)
{
NetworkResource net_res = new NetworkResource();
net_res.Type = 1;
net_res.LocalName = local_name;
net_res.RemoteName = remote_name;
net_res.Provider = null;
uint flag = 0u;
int bufferSize = 64;
StringBuilder stringBuilder = new StringBuilder(bufferSize);
uint result = 0u;
return WNetUseConnection(IntPtr.Zero, ref net_res, password, userID, flag, stringBuilder, ref bufferSize, out result);
}
// 해제하기
[DllImport("mpr.dll", EntryPoint = "WNetCancelConnection2", CharSet = CharSet.Auto)]
public static extern int WNetCancelConnection2A
(
string localName,
int flag,
int force
);
public int DisconnectDrive(string local_name)
{
return WNetCancelConnection2A(local_name, 1, 0);
}
public partial class MainWindow : Window
{
NetworkDrive net = new NetworkDrive();
public MainWindow()
{
InitializeComponent();
net.ConnectDrive("z:", "\\remote_path\\remote_name", "userID", "password");
net.DisconnectDrive("z:");
}
}
'C#, WF, WPF(.NET) > C#, WF, WPF(.NET) 테크닉' 카테고리의 다른 글
C# 테크닉 - 시리얼 통신 ( RS232 ) (0) | 2021.12.10 |
---|---|
C# 테크닉 - 로그 기록하기 ( NLOG ) (0) | 2021.12.09 |
C# 테크닉 - TimeCheck ( QPC ) (0) | 2021.12.07 |
C# 테크닉 - UnZip 파일 복원 ( SharpZipLib ) (0) | 2021.12.06 |
C# 테크닉 - Zip 파일 생성( SharpZipLib ) (0) | 2021.12.06 |