ホーム » VC » ドライブ名からリモート名に

2020年11月
1234567
891011121314
15161718192021
22232425262728
2930  

カテゴリー

アーカイブ

ブログ統計情報

  • 79,963 アクセス



ドライブ名からリモート名に

ネットワークドライブ名から UNC での表現に変換するコード.

#include	<clocale>
#include	"i_trace.hxx"

//#include	<winnetwk.h>
#pragma		comment	(lib,"mpr.lib")

tstring	W_get_remote_name	(LPCTSTR path_)
{
	tstring	dpath = path_ ;
	if (dpath.size() < 2)		{	return	dpath ;		}
	tstring	drive = dpath.substr(0,2) ;
	tstring	_path = dpath.substr(2) ;
	tstring	remote_path ;
	if (drive.length() == 2) {
		if (drive[1] == _T(':')) {
			u_16	d_t  = ::GetDriveType(drive.c_str()) ;
			if (d_t == DRIVE_REMOTE) {
				DWORD	buf_size = MAX_PATH ;
				tstring	remote_name ;
				remote_name.resize(buf_size+1) ;
				::WNetGetConnection(drive.c_str(),&remote_name[0],&buf_size) ;
				if (!remote_name.empty()) {
					remote_path = remote_name.c_str() + _path ;
					}
				}
			}
		}
	if (remote_path.empty())	{	return	dpath ;		}
	return	remote_path ;
	}

bool	Test	(void)
{
	for (long index=0 ; index<26 ; index++)	{
		tstring	drv  ;
				drv += TCHAR(_T('A')+index) ;
				drv += _T(":\\") ;
	//	if (index%2 == 0)
		{
			u_16	d_t  = ::GetDriveType(drv.c_str()) ;
			if (d_t == DRIVE_REMOTE) {
				drv += _T("*.*") ;
				v_tstring	files = ::EnumFiles(drv.c_str()) ;
				if (files.size() > 0) {
					drv = files[0] ;
					}
				}
			}
		drv += _T("                                      ") ;
		tstring	info = drv.substr(0,20) + _T("\t") + W_get_remote_name(drv.c_str()) ;
		{
			std::tout << info << std::endl ;
			}
		}
	return	true ;
	}

int	_tmain	(int argc,TCHAR* argv[])
{
	_tsetlocale(LC_ALL,_T("")) ;
	{
		::Test() ;
		}
	return	0 ;
	}

WNetGetConnection と net use
net use 」とコマンド入力することで似た様なことを確認できる.


管理者で起動した PowerShell の Get-SmbConnection で SMB のバージョンを確認できる.
ファイル共有で使われている SMB のバージョンを見る
Get-SmbConnection

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

コメントする

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

%d人のブロガーが「いいね」をつけました。