Public Class clsFolderCamouflage '特殊フォルダのCLASSID一覧 Friend Class SpecialFolderCLASSID Public Const MyComputer As String = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}" Public Const NetworkComputer As String = "{208D2C60-3AEA-1069-A2D7-08002B30309D}" Public Const TrashCan As String = "{645FF040-5081-101B-9F08-00AA002F954E}" Public Const Internet As String = "{871C5380-42A0-1069-A2EA-08002B30309D}" Public Const MyDocument As String = "{450D8FBA-AD25-11D0-98A8-0800361B1103}" Public Const ControlPanel As String = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::" & _ "{21EC2020-3AEA-1069-A2DD-08002B30309D}" Public Const Printer As String = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::" & _ "{2227A280-3AEA-1069-A2DE-08002B30309D}" Public Const WebFolder As String = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::" & _ "{BDEADF00-C265-11d0-BCED-00A0C90AB50F}" Public Const DialupNetwork As String = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::" & _ "{992CFFA0-F557-101A-88EC-00DD010CCC48}" Public Const Task As String = "{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::" & _ "{D6277990-4C6A-11CF-8D87-00AA0060F5BF}" End Class Private FolderPath As String '偽装元フォルダ Private strCamouflage As String '偽装先 '偽装元フォルダの設定 Public WriteOnly Property Folder() As String Set(ByVal value As String) FolderPath = value End Set End Property '偽装先の設定 Public WriteOnly Property CamouflageFolder() As String Set(ByVal value As String) strCamouflage = value End Set End Property '偽装する Public Function Camouflage() As Boolean Try System.IO.Directory.Move(FolderPath, FolderPath & "." & strCamouflage) Catch ex As Exception Return False Exit Function End Try Return True End Function End Class |
Public Class Form1 Private Class CamouflageItem Private myText As String Private myCLASSID As String Public Sub New(ByVal strText As String, ByVal strCLASSID As String) Me.myText = strText Me.myCLASSID = strCLASSID End Sub Public ReadOnly Property Text() As String Get Return myText End Get End Property Public ReadOnly Property CLASSID() As String Get Return myCLASSID End Get End Property End Class Public Sub New() ' この呼び出しは、Windows フォーム デザイナで必要です。 InitializeComponent() ' InitializeComponent() 呼び出しの後で初期化を追加します。 ' 偽装先一覧の作成 Dim NewItem As New Collections.ArrayList NewItem.Add(New CamouflageItem("マイコンピュータ", _ clsFolderCamouflage.SpecialFolderCLASSID.MyComputer)) NewItem.Add(New CamouflageItem("ネットワークコンピュータ", _ clsFolderCamouflage.SpecialFolderCLASSID.NetworkComputer)) NewItem.Add(New CamouflageItem("ごみ箱", _ clsFolderCamouflage.SpecialFolderCLASSID.TrashCan)) NewItem.Add(New CamouflageItem("インターネット", _ clsFolderCamouflage.SpecialFolderCLASSID.Internet)) NewItem.Add(New CamouflageItem("マイドキュメント", _ clsFolderCamouflage.SpecialFolderCLASSID.MyDocument)) NewItem.Add(New CamouflageItem("コントロールパネル", _ clsFolderCamouflage.SpecialFolderCLASSID.ControlPanel)) NewItem.Add(New CamouflageItem("プリンタ", _ clsFolderCamouflage.SpecialFolderCLASSID.Printer)) NewItem.Add(New CamouflageItem("Web フォルダ", _ clsFolderCamouflage.SpecialFolderCLASSID.WebFolder)) NewItem.Add(New CamouflageItem("ダイアルアップネットワーク", _ clsFolderCamouflage.SpecialFolderCLASSID.DialupNetwork)) NewItem.Add(New CamouflageItem("タスク", _ clsFolderCamouflage.SpecialFolderCLASSID.Task)) cmbCamouflage.DisplayMember = "Text" cmbCamouflage.ValueMember = "CLASSID" cmbCamouflage.DataSource = NewItem 'デフォルトの設定 cmbCamouflage.SelectedIndex = 3 End Sub '参照ボタン押下時にフォルダ選択ダイアログを表示する Private Sub btnRef_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRef.Click fbdRef.RootFolder = Environment.SpecialFolder.MyComputer fbdRef.ShowDialog() If fbdRef.SelectedPath <> String.Empty Then txtFolder.Text = fbdRef.SelectedPath End If End Sub '実行ボタン押下時にフォルダの偽装化を行う Private Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click Dim cfc As New clsFolderCamouflage cfc.Folder = txtFolder.Text cfc.CamouflageFolder = cmbCamouflage.SelectedValue.ToString If cfc.Camouflage Then Windows.Forms.MessageBox.Show("フォルダを偽装しました") Else Windows.Forms.MessageBox.Show("フォルダの偽装に失敗しました", _ Me.Text, _ Windows.Forms.MessageBoxButtons.OK, _ Windows.Forms.MessageBoxIcon.Error) End If End Sub End Class |