공유폴더 찾아주기

31437 
Created at 2006-09-29 06:41:09 
306   0   0   0  
Good day.
I need to know how to list shared folders on a computer that I am connected over LAN to, given its IP or machine name.

Thanks ahead.


========================================================================================================
Accepted Answer from Workshop_Alex
Date: 10/31/2003 03:21AM PST
========================================================================================================

program GetNetShares;

{$APPTYPE CONSOLE}

uses
Windows, SysUtils;

const
NERR_Success = 0; // Success

type
NET_API_STATUS = DWORD;
PShare_Info_0 = ^TShare_Info_0;
TShare_Info_0 = record
   shi0_netname: PWideChar;
end;
PShare_Info_0_Arr = ^TShare_Info_0_Arr;
TShare_Info_0_Arr = array[0..MaxInt div SizeOf(TShare_Info_0) - 1] of TShare_Info_0;
PShare_Info_1 = ^TShare_Info_1;
TShare_Info_1 = record
   shi1_netname: PWideChar;
   shi1_type: DWORD;
   shi1_remark: PWideChar;
end;
PShare_Info_1_Arr = ^TShare_Info_1_Arr;
TShare_Info_1_Arr = array[0..MaxInt div SizeOf(TShare_Info_1) - 1] of TShare_Info_1;
PShare_Info_2 = ^TShare_Info_2;
TShare_Info_2 = record
   shi2_netname: PWideChar;
   shi2_type: DWORD;
   shi2_remark: PWideChar;
   shi2_permissions: DWORD;
   shi2_max_uses: DWORD;
   shi2_current_uses: DWORD;
   shi2_path: PWideChar;
   shi2_passwd: PWideChar;
end;
PShare_Info_2_Arr = ^TShare_Info_2_Arr;
TShare_Info_2_Arr = array[0..MaxInt div SizeOf(TShare_Info_2) - 1] of TShare_Info_2;
PShare_Info_502 = ^TShare_Info_502;
TShare_Info_502 = record
   shi502_netname: PWideChar;
   shi502_type: DWORD;
   shi502_remark: PWideChar;
   shi502_permissions: DWORD;
   shi502_max_uses: DWORD;
   shi502_current_uses: DWORD;
 &.bsp; shi502_path: PWideChar;
   shi502_passwd: PWideChar;
   shi502_reserved: DWORD;
   shi502_security_descriptor: PSECURITY_DESCRIPTOR;
end;
PShare_Info_1004 = ^TShare_Info_1004;
TShare_Info_1004 = record
   shi1004_remark: PWideChar;
end;
PShare_Info_1006 = ^TShare_Info_1006;
TShare_Info_1006 = record
   shi1006_max_uses: DWORD;
end;
PShare_Info_1501 = ^TShare_Info_1501;
TShare_Info_1501 = record
   shi1501_reserved: DWORD;
   shi1501_security_descriptor: PSECURITY_DESCRIPTOR;
end;

function NetShareEnum(servername: PWideChar; level: DWORD; var buf: Pointer; prefmaxlen: DWORD; var entriesread: DWORD; var totalentries: DWORD; var resume_handle: DWORD): NET_API_STATUS; stdcall; external 'netapi32.dll';

function NetShareGetInfo(servername: PWideChar; netname: PWideChar; level: DWORD; var buf: Pointer): NET_API_STATUS; stdcall; external 'netapi32.dll';

function NetApiBufferFree(P: Pointer): NET_API_STATUS; stdcall; external 'netapi32.dll';

var
Server: PWideChar;
Buffer, Loop: PShare_Info_0;
Buf502: PShare_Info_502;
NetResult: DWORD;
entriesread: DWORD;
totalentries: DWORD;
resume_handle: DWORD;
I: Integer;
begin
if (ParamCount = 0) then begin
   Server := nil;
end
else begin
   Server := PWideChar(WideString(ParamStr(1)));
end;
entriesread := 0;
totalentries := 0;
resume_handle := 0;
NetResult := NetShareEnum(Server, 0, Pointer(Buffer), DWORD(-1), entriesread, totalentries, resume_handle);
if (NetResult = NERR_Success) then begin
   Loop := Buffer;
   WriteLn('Entries read: ', entriesread);
   for I := 1 to entriesread do begin
     WriteLn('Name: ', string(Loop.shi0_netname));
     try
       NetResult := NetShareGetInfo(Server, Loop.shi0_netname, 502, Pointer(Buf502));
       if (NetResult = NERR_Success) then begin
         WriteLn('* Net name: ', string(Buf502.shi502_netname));
         WriteLn('* Type: ', Buf502.shi502_type);
         WriteLn('* Remark: ', string(Buf502.shi502_remark));
         WriteLn('* Permissions: ', Buf502.shi502_permissions);
         WriteLn('* Max uses: ', Buf502.shi502_max_uses);
         WriteLn('* Current uses: ', Buf502.shi502_current_uses);
         WriteLn('* Path: ', string(Buf502.shi502_path));
         WriteLn('* Password: ', string(Buf502.shi502_passwd));
         WriteLn('* Reserved: ', Buf502.shi502_reserved);
       end
       else begin
         WriteLn('* Error: ', SysErrorMessage(NetResult));
       end;
       NetApiBufferFree(Buf502);
     except on E: Exception do WriteLn('* Error: ', E.Message);
     end;
     WriteLn;
     Inc(Loop);
   end;
   NetApiBufferFree(Buffer);
end;
end.

One single DLL executing what you want. ParamStr(1) should contain the name of the server. Use
GetNetShares <Server>
to execute, replacing <Server> with the server name.


========================================================================================================
Comment from duke_n
Date: 10/31/2003 08:28AM PST
========================================================================================================
This is great.
Thanks a lot.

Tags: 공유폴더 윈도우즈 Share on Facebook Share on X

◀ PREVIOUS
ShellExecute 실행 끝날때 까지 기다리기
▶ NEXT
스크린세이버 동작 못하게 막아주기
  Comments 0
Login for comment
SIMILAR POSTS

DirectShow에서 비디오 출력 크기 조정해주기 (created at 2006-09-29)

로컬 IP 알아내기 (created at 2006-09-29)

스크린세이버 동작 못하게 막아주기 (created at 2006-09-29)

PC 셧다운 (shutdown) (created at 2006-09-29)

ShellExecute 실행 끝날때 까지 기다리기 (created at 2006-09-29)

how to record keyboard & mouse event (created at 2006-09-29)

Starting an application as an icon in the system tray (created at 2006-09-29)

Extracting a Program's Version Information (created at 2006-09-29)

디렉토리 복사 루틴 (하부디렉토리까지 몽땅) (created at 2006-09-29)

디렉토리와 그 안에 있는 모든 파일 지우기 (created at 2006-09-29)

Create a standard windows shortcut file (created at 2006-09-29)

웹브라우져에 붙이기 위한 ActiveX 프로그래밍 방법 (created at 2006-09-29)

File Attribute 바꾸는 방법 (created at 2006-09-29)

투명 윈도우 구현 방법 (created at 2006-09-29)

ActiveX를 Safe한 Component로 등록하는 방법 (created at 2006-09-29)

ActiveX의 등록 - Safe Code 넣어주기 (updated at 2023-12-17)

윈도우 찾아서 Top Most로 올려주기 (updated at 2023-12-17)

Application defined window call procedure (created at 2006-09-29)

Application Event써서 Keyboard 받아내기 (created at 2006-09-29)

Web Browser Control에서 Enter키 먹게 하기 (created at 2006-09-29)

String Find 알고리즘 (created at 2006-09-29)

HTTP Downloading Reference Source Code (created at 2006-09-29)

File Search Sample Code (created at 2006-09-29)

모니터 끄는 API (created at 2006-09-29)

wave 파일 mixing 하기. (웨이브 믹싱) (created at 2006-09-29)

ATL/ActiveX 에서 자바스크립트로 데이터(문자열) 보내기 (created at 2006-09-29)

System Log-Off, Suspend, Reboot, Shutdown 시키기 (created at 2006-09-29)

GDI+ 에서 이미지 반투명 처리하기.. (created at 2006-09-29)

자기자신 IP알아내기(로칼컴퓨터) (created at 2006-09-29)

프로세스명으로 프로세스 죽이는 함수 (created at 2006-09-29)

OTHER POSTS IN THE SAME CATEGORY

Simple Socket Server based on C (created at 2006-09-29)

HTTP Downloading Reference Source Code (created at 2006-09-29)

String Find 알고리즘 (created at 2006-09-29)

UNIX에서 LOCALTIME 구하는 방법 & GetTicketCount() (created at 2006-09-29)

Web Browser Control에서 Enter키 먹게 하기 (created at 2006-09-29)

Application Event써서 Keyboard 받아내기 (created at 2006-09-29)

Application defined window call procedure (created at 2006-09-29)

윈도우 찾아서 Top Most로 올려주기 (updated at 2023-12-17)

ActiveX의 등록 - Safe Code 넣어주기 (updated at 2023-12-17)

ActiveX를 Safe한 Component로 등록하는 방법 (created at 2006-09-29)

투명 윈도우 구현 방법 (created at 2006-09-29)

웹브라우져에 붙이기 위한 ActiveX 프로그래밍 방법 (created at 2006-09-29)

how to record keyboard & mouse event (created at 2006-09-29)

PC 셧다운 (shutdown) (created at 2006-09-29)

스크린세이버 동작 못하게 막아주기 (created at 2006-09-29)

ShellExecute 실행 끝날때 까지 기다리기 (created at 2006-09-29)

Starting an application as an icon in the system tray (created at 2006-09-29)

Extracting a Program's Version Information (created at 2006-09-29)

디렉토리 복사 루틴 (하부디렉토리까지 몽땅) (created at 2006-09-29)

디렉토리와 그 안에 있는 모든 파일 지우기 (created at 2006-09-29)

Create a standard windows shortcut file (created at 2006-09-29)

File Attribute 바꾸는 방법 (created at 2006-09-29)

wave 파일 mixing 하기. (웨이브 믹싱) (created at 2006-09-29)

ATL/ActiveX 에서 자바스크립트로 데이터(문자열) 보내기 (created at 2006-09-29)

System Log-Off, Suspend, Reboot, Shutdown 시키기 (created at 2006-09-29)

GDI+ 에서 이미지 반투명 처리하기.. (created at 2006-09-29)

자기자신 IP알아내기(로칼컴퓨터) (created at 2006-09-29)

프로세스명으로 프로세스 죽이는 함수 (created at 2006-09-29)

빈폴더 찾아내기 (created at 2006-09-29)

IE 패치에 따른 object, embed, applet 대처 방안 (created at 2006-09-28)

UPDATES

글루코사민 vs. 콘드로이친: 무엇이 더 나은 관절 건강 보조제일까? (created at 2024-04-22)

광주 5·18 민주화운동 알린 테리 앤더슨 前 AP 기자 (created at 2024-04-22)

햄과 소세지가 우리 몸에 일으키는 부작용 (updated at 2024-04-22)

콘드로이친의 염증 감소효과 (updated at 2024-04-22)

코사민 DS - 글루코사민+콘드로이친 복합물이 함유된 퇴행성 관절 건강보조제 (updated at 2024-04-22)

삼겹살 먹을때 환상조합 (created at 2024-04-22)

일본 여중생의 특이한 취향 (created at 2024-04-22)

우리가 먹는 약물이 바꿔버린 생태계 (created at 2024-04-21)

일본에서 그린 상상속의 사무직과 현실속의 사무직 (updated at 2024-04-21)

북한 미대생들이 그린 북한 최고존엄 김정은 (created at 2024-04-21)

입사 후 1년도 되지 않은 회사에서 구조조정에 의한 퇴직 불응에 따른 해고 처리시 대응 가능한 방법 (updated at 2024-04-20)

한고은님의 옛날 사진 (updated at 2024-04-20)

소녀대 - Bye Bye Girl (updated at 2024-04-13)

대한민국 날씨 근황 (created at 2024-04-13)

성일종 인재육성 강조하며 이토 히로부미 언급 - 인재 키운 선례? (updated at 2024-04-13)

일제강점기가 더 살기 좋았을지도 모른다는 조수연 국민의힘 후보 - 친일파? (updated at 2024-04-13)

Marshall Ha님의 샤오미 SU7 시승기 - 테슬라의 일론 머스크님이 긴장할만한 느낌 (updated at 2024-04-09)

윙크하는 귀염둥이 반려견들 (created at 2024-04-08)

달콤 살벌한 고백 (created at 2024-04-08)

북한 최정예 공수부대 훈련 모습 (updated at 2024-04-02)

맛있었던 친구 어머니의 주먹밥이 먹고 싶어요 (created at 2024-04-02)

자리 마음에 안든다고 6급 공무원 패는 농협 조합장 (created at 2024-03-26)

85세 딸 짜장면 사주는 102세 어머니 (created at 2024-03-26)

1990년대 감각파 도둑 (created at 2024-03-26)

치매에 걸린 69살의 브루스 윌리스가 전부인 데미무어를 보고 한 말 (updated at 2024-03-22)

경제는 대통령이 살리는 것이 아닙니다 라던 윤석열대통령 - 상황 안좋아지자 여러 전략을 펼쳤지만, 부작용 속출했던 2024년의 봄 (updated at 2024-03-13)

극빈의 생활을 하고 배운것이 없는 사람은 자유가 뭔지도 모를 뿐 아니라 왜 개인에게 필요한지에 대한 필요성을 못느낀다는 윤석열 대통령 (updated at 2024-03-08)

조선일보를 안본다는 사람들이 말하는 그 이유 - 천황폐하, 전두환 각하, 김일성 장군 만세? (created at 2024-03-07)

광폭타이어를 장착하면 성능이 좋아질거라는 착각 (updated at 2024-03-03)

면허시험장에서 면허갱신하면 하루만에 끝나나? (updated at 2024-03-03)