001.
' ***********************************************************
002.
' 処理開始
003.
' ***********************************************************
004.
Set
Fso = Wscript.CreateObject(
"Scripting.FileSystemObject"
)
005.
Set
Shell = Wscript.CreateObject(
"Shell.Application"
)
006.
007.
' ***********************************************************
008.
' 実行中ディレクトリの取得
009.
' ***********************************************************
010.
strPath = Wscript.ScriptFullName
011.
Set
objFile = Fso.GetFile( strPath )
012.
strBackupFolder = Fso.GetParentFolderName( objFile )
013.
014.
' ***********************************************************
015.
' バックアップ対象ディレクトリの取得
016.
' ***********************************************************
017.
' ① 省略すると、ルートはデスクトップ
018.
Set
objFolder = Shell.BrowseForFolder( 0,
"バックアップするフォルダを選択してください"
, &H4B )
019.
020.
' ② 文字列による直接指定
021.
' strRoot = "c:\"
022.
' Set objFolder = Shell.BrowseForFolder( 0, "バックアップするフォルダを選択してください", &H4B, strRoot )
023.
024.
' ③ ルートを番号で指定( この場合は C:\Users\username\AppData\Local )
025.
' ※ あまり現実的ではない特殊ディレクトリの選択
026.
' nRoot = &h1c
027.
' Set objFolder = Shell.BrowseForFolder( 0, "バックアップするフォルダを選択してください", &H4B, nRoot )
028.
029.
if objFolder is nothing then
030.
WScript.Quit
031.
end if
032.
if not objFolder.Self.IsFileSystem then
033.
WScript.Echo
"ファイルシステムではありません"
034.
WScript.Quit
035.
end if
036.
037.
strTargetFolder = objFolder.Self.Path
038.
strName = Replace( strTargetFolder,
":"
,
""
)
039.
strName = Replace( strName,
"\", "
_" )
040.
strName = Replace( strName,
" "
,
""
)
041.
strName =
"BK_"
& strName
042.
043.
' ***********************************************************
044.
' スクリプト作成
045.
' ***********************************************************
046.
Set
OutFile = Fso.OpenTextFile( strBackupFolder &
"\" & strName & "
.vbs", 2,
True
)
047.
048.
OutFile.WriteLine
"strName = "
""
& strName &
""
""
049.
OutFile.WriteLine
"strTarget = "
""
& strTargetFolder &
""
""
050.
OutFile.WriteLine
"strBackupFolder = "
""
& strBackupFolder &
""
""
051.
OutFile.Write
"if MsgBox( strTarget & vbCrLf & "
"のバックアップを開始します。よろしいですか? (保存先:"
" & strBackupFolder & "
"\""
& strName &
""
)
""
"
052.
OutFile.WriteLine
", 1 ) = 2 then"
053.
OutFile.WriteLine
" Wscript.Quit"
054.
OutFile.WriteLine
"end if"
055.
056.
OutFile.WriteLine
"Set WshShell = Wscript.CreateObject( "
"WScript.Shell"
" )"
057.
OutFile.Write
"ExecCommand = "
"cmd.exe /C "
""
"xcopy.exe "
""
""
" & strTarget & "
""
""
" "
""
""
" & strBackupFolder & "
"\""
& strName &
""
\
""
""
"
058.
OutFile.WriteLine
" /D /E /C /S /Y & PAUSE"
""
""
""
059.
OutFile.WriteLine
"Call WshShell.Run( ExecCommand )"
060.
061.
OutFile.Close
062.
063.
WScript.Echo
"バックアップスクリプト : "
& strName &
".vbs"
&
" を作成しました"
064.
065.
066.
' ***********************************************************
067.
' ディレクトリ指定用番号
068.
' https://docs.microsoft.com/ja-jp/windows/desktop/api/shldisp/ne-shldisp-shellspecialfolderconstants
069.
' typedef enum {
070.
' ssfALTSTARTUP = 0x1d,
071.
' ssfAPPDATA = 0x1a,
072.
' ssfBITBUCKET = 0x0a,
073.
' ssfCOMMONALTSTARTUP = 0x1e,
074.
' ssfCOMMONAPPDATA = 0x23,
075.
' ssfCOMMONDESKTOPDIR = 0x19,
076.
' ssfCOMMONFAVORITES = 0x1f,
077.
' ssfCOMMONPROGRAMS = 0x17,
078.
' ssfCOMMONSTARTMENU = 0x16,
079.
' ssfCOMMONSTARTUP = 0x18,
080.
' ssfCONTROLS = 0x03,
081.
' ssfCOOKIES = 0x21,
082.
' ssfDESKTOP = 0x00,
083.
' ssfDESKTOPDIRECTORY = 0x10,
084.
' ssfDRIVES = 0x11,
085.
' ssfFAVORITES = 0x06,
086.
' ssfFONTS = 0x14,
087.
' ssfHISTORY = 0x22,
088.
' ssfINTERNETCACHE = 0x20,
089.
' ssfLOCALAPPDATA = 0x1c,
090.
' ssfMYPICTURES = 0x27,
091.
' ssfNETHOOD = 0x13,
092.
' ssfNETWORK = 0x12,
093.
' ssfPERSONAL = 0x05,
094.
' ssfPRINTERS = 0x04,
095.
' ssfPRINTHOOD = 0x1b,
096.
' ssfPROFILE = 0x28,
097.
' ssfPROGRAMFILES = 0x26,
098.
' ssfPROGRAMFILESx86 = 0x30,
099.
' ssfPROGRAMS = 0x02,
100.
' ssfRECENT = 0x08,
101.
' ssfSENDTO = 0x09,
102.
' ssfSTARTMENU = 0x0b,
103.
' ssfSTARTUP = 0x07,
104.
' ssfSYSTEM = 0x25,
105.
' ssfSYSTEMx86 = 0x29,
106.
' ssfTEMPLATES = 0x15,
107.
' ssfWINDOWS = 0x24
108.
' } ShellSpecialFolderConstants;
109.
' ***********************************************************