The Grimoire of Nonsense

個人的なメモを残すブログ

論理ドライブからデバイスマッピング名を取得する

Windowsの論理ドライブ名*1からデバイスマッピング*2を取得するサンプル。
連想配列を使うとよさそうなので連想配列に格納したよっ。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <Windows.h>
using namespace std;

typedef map<string, string> StrMap;
typedef pair<string, string> StrPair;

void CollectDrives( StrMap &map );

int main()
{
	StrMap drives;

	CollectDrives( drives );

	for ( StrPair t : drives )
		printf( "%s -> %s\n", t.first.c_str(), t.second.c_str() );

	return 0;
}

void CollectDrives( StrMap &map )
{
	char drives[ 1024 ] = { 0 };
	char *lpDrives = drives;

	// 全論理ドライブを取得
	GetLogicalDriveStrings( _countof( drives ), drives );

	while ( *lpDrives != '\0' ) {
		string drive( lpDrives );
		char buffer[ 1024 ] = { 0 };

		// 末尾の'\'を削除
		for ( size_t i = drive.find_first_of( '\\' ); i != string::npos; i = drive.find_first_of( '\\' ) )
			drive.erase( i, 1 );

		// デバイスマッピング名を取得
		QueryDosDevice( drive.c_str(), buffer, _countof( buffer ) );

		map.insert( make_pair( drive, string( buffer ) ) );

		lpDrives += strlen( lpDrives ) + 1;
	}
}

以下、実行結果。あくまで環境依存。

C: -> \Device\HarddiskVolume4
D: -> \Device\HarddiskVolume6
T: -> \Device\HarddiskVolume11
V: -> \Device\HarddiskVolume8
W: -> \Device\HarddiskVolume9
X: -> \Device\CdRom0

*1:C:\とか

*2:\Device\HarddiskVolume1とか

Debian 8 (Jessie)でシャットダウンしてもSSHが切断されない

上記の構成でSSHからshutdownコマンドやrebootコマンドを実行してもSSHが切断されない問題の解決方法。
libpam-systemdをインストールしてsshdを再起動すればよいらしい。試して解決したのでメモ。

# apt-get install libpam-systemd

でインストールして

# service sshd restart

sshdを再起動。

Raspian Jessieでも同じ問題があったが上記の対処で解決。


この記事は下記のページを参考に執筆させて頂きました。
Debian 8(Jessie) ssh経由でシャットダウンするとコンソールが固まる - Symfoware

Visual Studio 2017の設定保存先は?

最近出たばっかりのVS2017だが通常、レジストリ

HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\(バージョン)

に設定が保存されているわけだが、どうもVS2017からはそこへ保存されていない。
ので調べて分かったことをメモ。
どうやら設定ファイルはレジストリのデータがファイル化されているらしく、

%USERPROFILE%\AppData\Local\Microsoft\VisualStudio\15.0_(ランダムな英数字)\privateregistry.bin

に保存されている。

編集したい場合は、レジストリディタでHKEY_LOCAL_MACHINEを選んで「ファイル > ハイブの読み込み」で上記ファイルを選んで適当な名前で読み込む。
すると通常通りに編集出来る。終わった後はアンロードした方がいいのかも?(この辺りはよく分からない)

2017/03/25追記
アンロードしないとVS起動時に不明なエラーで起動しなくなる模様。

f:id:sx1752:20170310183906p:plain
こんな感じに

「これらの送信者からの通知を取得する」を削除する

f:id:sx1752:20161003021123p:plain
これを削除する方法。

1.explorer.exeを終了させる

タスクマネージャー等から終了させる。

2.以下フォルダにあるファイルを削除

%UserProfile%\AppData\Local\Microsoft\Windows\Notifications

にある

wpndatabase.db*

を全て削除する。

3.explorer.exeを起動させる

起動し直して設定アプリで確認すると削除されている。

実行結果

f:id:sx1752:20161003022211p:plain


この記事は以下を丸パクり参考に執筆させて頂きました。
answers.microsoft.com

IEの「閲覧の履歴の削除」ダイアログを呼び出す

すっっっっっっっっっっっっごくどうでもいいけど、IEの履歴を削除するあのダイアログを呼び出す方法。
inetcpl.cplの中のShowDeleteBrowsingHistoryDialog()にウィンドウハンドルを渡して呼べばあのダイアログが出る。

以下サンプルプログラム

#include <cstdio>
#include <Windows.h>

typedef void( WINAPI *LPFUNC )( HWND );

int main()
{
	HMODULE hModule = LoadLibrary( R"(C:\Windows\System32\inetcpl.cpl)" );
	LPFUNC lpFunc = nullptr;

	if ( hModule == INVALID_HANDLE_VALUE || hModule == nullptr ) {
		printf( "LoadLibrary()に失敗\n" );
		return -1;
	}

	lpFunc = reinterpret_cast<LPFUNC>(GetProcAddress( hModule, "ShowDeleteBrowsingHistoryDialog" ));
	if ( lpFunc == nullptr ) {
		printf( "GetProcAddress()に失敗\n" );
		FreeLibrary( hModule );
		return -2;
	}

	lpFunc( GetDesktopWindow() );
	FreeLibrary( hModule );

	return 0;
}

Windows エラー報告を無効にする

2016年上半期ちゃん息してない……。

アプリが強制終了した時に表示されるダイアログでWindows 10からは勝手に解決策を確認しに行って*1気持ち悪い!! って人用の設定。
お馴染みgpedit.mscが使える人は「Windows エラー報告を無効にする」を有効にしてPCを再起動すれば有効になる。
f:id:sx1752:20160702130620p:plain

gpedit.mscが使えない人やレジストリに手動で追加したい人は下記を.regにして保存し、レジストリに結合してからPCを再起動するとよい。

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Error Reporting]
"Disabled"=dword:00000001

*1:もちろん解決はしないと思われるが……。

Windows 10にアップグレードしてからゲームが強制終了する問題

サービスTabletInputService(Touch Keyboard and Handwriting Panel Service)が悪さしているらしいので
これを停止 or 無効にすると強制終了しなくなる。
お陰でStranger of Sword Cityがプレイできるようになった。

※ただし停止するとタッチキーボードが使えなくなる。