18,356
社区成员
发帖
与我相关
我的任务
分享
// WL006Dlg.h : header file
//
#if !defined(AFX_WL006DLG_H__23B4BD6F_06B1_4F90_A8FD_FE97EEC2F0E5__INCLUDED_)
#define AFX_WL006DLG_H__23B4BD6F_06B1_4F90_A8FD_FE97EEC2F0E5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/////////////////////////////////////////////////////////////////////////////
// CWL006Dlg dialog
class CWL006Dlg : public CDialog
{
// Construction
public:
CWL006Dlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CWL006Dlg)
enum { IDD = IDD_WL006_DIALOG };
CListCtrl m_FileList;
CString m_strAddr;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CWL006Dlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
void GetShareDir(LPCTSTR lpszAddr);
// Generated message map functions
//{{AFX_MSG(CWL006Dlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnButtonFind();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_WL006DLG_H__23B4BD6F_06B1_4F90_A8FD_FE97EEC2F0E5__INCLUDED_)
// WL006Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "WL006.h"
#include "WL006Dlg.h"
#include "ConnectDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWL006Dlg dialog
CWL006Dlg::CWL006Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CWL006Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWL006Dlg)
m_strAddr = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CWL006Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWL006Dlg)
DDX_Control(pDX, IDC_LIST_FILE, m_FileList);
DDX_Text(pDX, IDC_EDIT_ADDR, m_strAddr);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWL006Dlg, CDialog)
//{{AFX_MSG_MAP(CWL006Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_FIND, OnButtonFind)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWL006Dlg message handlers
BOOL CWL006Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
DWORD dwExStyle = m_FileList.GetExtendedStyle();
dwExStyle |= LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT;
m_FileList.SetExtendedStyle(dwExStyle);
m_FileList.InsertColumn(0, _T("共享文件名"), LVCFMT_LEFT, 120);
m_FileList.InsertColumn(1, _T("共享文件路径"), LVCFMT_LEFT, 240);
return TRUE; // return TRUE unless you set the focus to a control
}
void CWL006Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CWL006Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CWL006Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CWL006Dlg::OnButtonFind()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
GetShareDir(m_strAddr);
}
void CWL006Dlg::GetShareDir(LPCTSTR lpszAddr)
{
PSHARE_INFO_502 pBufPtr, p;
NET_API_STATUS res;
TCHAR szText[MAX_PATH];
_stprintf(szText, L"\\\\%s", lpszAddr);
WCHAR *lpszServer = (LPTSTR)szText;
DWORD dwEnriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwResume = 0;
m_FileList.DeleteAllItems();
do
{
res = NetShareEnum(lpszServer, 502, (LPBYTE*)&pBufPtr, -1, &dwEnriesRead,
&dwTotalEntries, &dwResume);
if(res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
{
p = pBufPtr;
for(DWORD i = 0; i < dwEnriesRead; i++)
{
int nCount = m_FileList.GetItemCount();
m_FileList.InsertItem(nCount, p->shi502_netname, 0);
m_FileList.SetItemText(nCount, 1, p->shi502_path);
p++;
}
NetApiBufferFree(pBufPtr);
}
else
{
AfxMessageBox(L"未读取到共享文件夹");
}
}while(res == ERROR_MORE_DATA);
}
ServerShare = "\\192.168.3.56\d$"
UserName = "somedomain\someuser"
Password = "somepassword"
Set NetworkObject = CreateObject("WScript.Network")
NetworkObject.MapNetworkDrive "", ServerShare, False, UserName, Password
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Directory = FSO.GetFolder(ServerShare)
For Each FileName In Directory.Files
WScript.Echo FileName.Name
Next
Set FileName = Nothing
Set Directory = Nothing
Set FSO = Nothing
NetworkObject.RemoveNetworkDrive ServerShare, True, False
Set NetworkObject = Nothing
WinExec("cmd /c net view VIRTUAL>netviewoutput.txt",SW_HIDE);
//然后读文件netviewoutput.txt的内容
BOOL EnumLanRes(PACK_HANDLE *hPack, NETRESOURCE *pNetContainer, DWORD dwScope, char *svSpacer)
{
DWORD OpenRet;
// Open network resource list
HANDLE hNet;
OpenRet=WNetOpenEnum(dwScope,RESOURCETYPE_ANY,0,pNetContainer,&hNet);
if (OpenRet!=NO_ERROR)
{
pfReply(hPack,CMD_ERROR,0,"LAN net open failed");
sprintf(g_szError,"WNetOpenEnum failed,[%d]",OpenRet);
return FALSE;
}
// Enumerate resources
int ret;
DWORD dwCount,dwBufSize;
NETRESOURCE *pNetRes;
pNetRes=(NETRESOURCE *)malloc(16384);
if(pNetRes==NULL)
{
WNetCloseEnum(hNet);
pfReply(hPack,CMD_ERROR,0,"ヤカウフヨ愷レエ豐サラ・);
return FALSE;
}
dwCount=1;
dwBufSize=8192;
ret=WNetEnumResource(hNet,&dwCount,pNetRes,&dwBufSize);
while(ret!=ERROR_NO_MORE_ITEMS)
{
char *svType,*svLocalName,*svRemoteName,*svComment;
char svURLHead[MAX_PATH+1];
char svURLFoot[MAX_PATH+1];
svURLHead[0]='\0';
svURLFoot[0]='\0';
int iNetType;
switch(pNetRes->dwDisplayType)
{
case RESOURCEDISPLAYTYPE_DOMAIN:
svType="DOMAIN";
iNetType = RESOURCE_DOMAIN;
break;
case RESOURCEDISPLAYTYPE_GENERIC:
svType="GENERIC";
iNetType = RESOURCE_GENERIC;
break;
case RESOURCEDISPLAYTYPE_SERVER:
svType="SERVER";
iNetType = RESOURCE_SERVER;
break;
case RESOURCEDISPLAYTYPE_SHARE:
switch(pNetRes->dwType)
{
case RESOURCETYPE_DISK:
svType="FOLDER";
iNetType = RESOURCE_FOLDER;
break;
case RESOURCETYPE_PRINT:
svType="PRINTER";
iNetType = RESOURCE_PRINTER;
break;
default:
svType="UNKNOWN";
iNetType = RESOURCE_UNKNOWN;
break;
}
break;
default:
svType="NETWORK";
iNetType = RESOURCE_NETWORK;
break;
}
if(pNetRes->lpLocalName==NULL) svLocalName="";
else svLocalName=pNetRes->lpLocalName;
if(pNetRes->lpRemoteName==NULL) svRemoteName="";
else svRemoteName=pNetRes->lpRemoteName;
if(pNetRes->lpComment==NULL) svComment="";
else svComment=pNetRes->lpComment;
_network_resource res;
memset(&res,0,sizeof(res));
if(!pNetRes->lpLocalName && !pNetRes->lpRemoteName)
{
res.iType = iNetType;
wsprintf(res.Comment,"%.99s",svComment);
}
else
{
res.iType = iNetType;
wsprintf(res.Comment,"%.99s",svComment);
wsprintf(res.RemoteName,"%.99s",svRemoteName);
wsprintf(res.LocalName,"%.99s",svLocalName);
}
pfReply(hPack,CMD_NETWORK,SUBCMD_RESOURCE,&res);
// Recurse if necessary
if (pNetRes->dwUsage & RESOURCEUSAGE_CONTAINER && dwScope == RESOURCE_GLOBALNET)
{
char svSpacer2[100];
lstrcpyn(svSpacer2,svSpacer,100);
if(lstrlen(svSpacer2)<98) lstrcat(svSpacer2," ");
EnumLanRes(hPack,pNetRes,dwScope,svSpacer2);
}
dwCount=1;
dwBufSize=16384;
ret=WNetEnumResource(hNet,&dwCount,pNetRes,&dwBufSize);
}
free(pNetRes);
WNetCloseEnum(hNet);
return TRUE;
}