VBScript
VBScript: | Microsoft Visual Basic Scripting Edition |
実行環境: | IE(html),IIS(aps),PWS(aps),WSH(vbs) |
ダウンロー後、.txtを外す |
ファイル | 内 容 |
MsAgent.vbs.txt | マーリン起動で時刻表示(C:\WINDOWS\MSAGENT\CHARS\MERLIN.ACS要) |
ShortCut.vbs.txt | ディスクトップにメモ帳のショートカット作成 |
ShowVar.vbs.txt | OS環境変数の一覧表示 |
WSH_CDONTS.txt | [IIS]スケジュールされた電子メール メッセージの作成方法 |
SMTPWSH_SMTP.txt | [IIS]SMTP を利用してコマンド プロンプトで電子メールを送る |
WSCRIPT_Ver for Excel.vbs.txt | Excel に Windows スクリプティング ホストのプロパティを表示 |
テキスト作成 | Set fs =
CreateObject("Scripting.FileSystemObject") Set fl = fs.CreateTextFile("d:\down\_chk\test\aaa.txt",True) fl.WriteLine("aaaa") fl.close Msgbox("作成完了") |
ファイルの削除 | Set fs =
WScript.CreateObject("Scripting.FileSystemObject") fs.DeleteFile("d:\down\_chk\test\*.*") Msgbox("削除完了") |
ファイルの存在確認 | Set fs =
WScript.CreateObject("Scripting.FileSystemObject") If fs.FileExists("C:\xx\xxx\xxx.txt") Then fs.DeleteFile("C:\xx\xxx\xxx.txt") MsgBox "削除", 64, "○○システム" End If |
フォルダーの存在確認 | Dim Path Path = "d:\ak\down" Set Fs = WScript.CreateObject("Scripting.FileSystemObject") If Fs.FolderExists(Path) Then Set fol=Fs.GetFolder(Path) MsgBox Path & " は実在します。", 64, "○○システム" Else MsgBox Path & " は実在しません。", 16, "○○システム" End If |
ie起動 | Dim objie Dim varRet Set objie = CreateObject("InternetExplorer.Application") varRet = InputBox("URLを入力して下さい","タイトル","http://www.eonet.ne.jp/~aki/") If varRet <> "" Then objie.Navigate varRet objie.Visible = True End If 'objie.Quit Set objie = Nothing |
フォルダー内のファイルを エクセルへ |
On Error Resume Next strPath = "C:\ak\down" Set objFS = CreateObject("Scripting.FileSystemObject") Set objFolder = objFS.GetFolder(strPath) if Err.Number <> 0 then MsgBox("ERRNO=" & Err.Number & vbCR & Err.Description) WScript.Quit end if set objExcel = CreateObject("Excel.Application") Set objBook = objExcel.WorkBooks.Add objExcel.Visible = true For i = 1 to 4 if i = 4 Then objExcel.Cells(1,i).ColumnWidth = 35 else objExcel.Cells(1,i).ColumnWidth = 15 End if Next objExcel.Cells(1,1).Value = "ファイル名" objExcel.Cells(1,2).Value = "作成日" objExcel.Cells(1,3).Value = "最終更新日" objExcel.Cells(1,4).Value = "ファイルのパス" inRow = 2 Call Fileinfo(objFolder) MsgBox "END" Sub Fileinfo(objFolder) For Each objFile In objFolder.Files objExcel.Cells(inRow,1).Value = objFile.Name objExcel.Cells(inRow,2).Value = objFile.DateCreated objExcel.Cells(inRow,3).Value = objFile.DateLastModified objExcel.Cells(inRow,4).Value = objFile.Path inRow = inRow + 1 Next For Each objSubFolder In objFolder.SubFolders call Fileinfo(objSubFolder) Next end Sub |
小文字から大文字へ 大文字から小文字へ UCase -> LCase |
Set objFS = CreateObject("Scripting.FileSystemObject") Set objText = objFS.OpenTextFile("C:\ak\down\i.txt") myText = objText.ReadAll objText.Close Set objText = objFS.CreateTextFile("C:\ak\down\o.txt") objText.Write(UCase(myText)) objText.Close Set objShell = WScript.CreateObject("WScript.Shell") objShell.Run "C:\ak\down\o.txt",, True Set objFS = Nothing Set objText = Nothing Set objShell = Nothing |
OpenAsTextStream 文字追加 |
Set objFS =
CreateObject("Scripting.FileSystemObject") Set objFile = objFS.GetFile("C:\ak\down\i.txt") Set objText = objFile.OpenAsTextStream(8,0) objText.WriteLine("end") objText.Close Set objFS = Nothing Set objFile = Nothing Set objText = Nothing |
ファイル開く | Set objShell =
WScript.CreateObject("WScript.Shell") 'objShell.Run "C:\Windows\notepad.exe C:\ak\down\i.txt" 'objShell.Run "C:\WINDOWS\system32\notepad.exe", 3, True 'objShell.Run "%windir%\notepad.exe C:\ak\down\i.txt", 2, True 'objShell.Run "notepad C:\ak\down\i.txt",, True objShell.Run "C:\ak\down\i.txt",, True Set objShell = Nothing |
デスクトップの制御 | 'デスクトップの表示 ' CreateObject("Shell.Application").ToggleDesktop 'すべて最小化 ' CreateObject("Shell.Application").MinimizeAll '元に戻す ' CreateObject("Shell.Application").UndoMinimizeAll |
行数カウント | 'On Error Resume Next strPath = "C:\ak\down\test" strPathC = "C:\ak\down\cnt.txt" Set fs = CreateObject("Scripting.FileSystemObject") fs.DeleteFile(strPathC) Set fl = fs.GetFolder(strPath) For Each objFile In fl.Files lCnt = 0 Set f = fs.OpenTextFile(objFile.Path) With f Do Until (.AtEndOfLine) .SkipLine lCnt = lCnt + 1 Loop .Close End With Set f = Nothing Set ot = fs.OpenTextFile(strPathC,8,True) MsgBox objFile.Name & "=" & lCnt & "件" ot.WriteLine objFile.Name & "=" & lCnt & "件" ot.Close Set ot = Nothing Next Set fs = Nothing Set fl = Nothing |
コンピュータ名 | Dim objNetWork Set objNetWork = WScript.CreateObject("WScript.Network") WScript.echo "UserName = " & objNetWork.UserName WScript.echo "UserDomain = " & objNetWork.UserDomain WScript.echo "ComputerName= " & objNetWork.ComputerName Set objNetWork = Nothing |
レジストリに登録 | 'レジストリに登録します。 Set objArgs = WScript.Arguments Set objWS = CreateObject("WScript.Shell") FileName = objArgs(0) msgbox FileName If FileName <> "" Then objWS.Run "regsvr32.exe " & Chr(34) & FileName & Chr(34) End If Set objWS = Nothing Set objArgs = Nothing |
レジストリ情報を削除 | 'レジストリ情報を削除します。 Set objArgs = WScript.Arguments Set objWS = CreateObject("WScript.Shell") FileName = objArgs(0) If FileName <> "" Then objWS.Run "regsvr32.exe /u " & Chr(34) & FileName & Chr(34) End If Set objWS = Nothing Set objArgs = Nothing |
DSN の一覧を取得 | 'http://www.microsoft.com/japan/technet/scriptcenter/resources/qanda/jul05/hey0725.mspx Const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC DATA SOURCES" objRegistry.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes strWk = "" CRLF = Chr(13) & Chr(10) For i = 0 to Ubound(arrValueNames) strValueName = arrValueNames(i) objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue strWk = strWk & strValueName & " -- " & strValue & CRLF 'Wscript.Echo strValueName & " -- " & strValue Next Wscript.Echo strWk |
バージョンを表示 | Option Explicit On Error Resume Next WScript.Echo WScript.Name, "Version", WScript.Version |
フォルダ内ファイル消し込み |
On Error Resume Next
dim wdate dim fdate strPath = "D:\down\check" Set objFS = CreateObject("Scripting.FileSystemObject") Set objFolder = objFS.GetFolder(strPath) wdate = dateadd("d",-10,date()) fdate = left(wdate,4) & mid(wdate,6,2) & right(wdate,2) Set fs = CreateObject("Scripting.FileSystemObject") Set fl = fs.CreateTextFile(strPath & "\xxxxxxxxx_backup_999999999999.log",True) For Each objFile In objFolder.Files if mid(objFile.Name,18,8) <= fdate then fl.WriteLine(objFile.Name) fs.DeleteFile(strPath & "\" & objFile.Name) end if Next fl.close |
プログラム起動 | Set WSHShell = WScript.CreateObject("WScript.Shell") WSHShell.Run """C:\Program Files\Internet Explorer\iexplore.exe""" WScript.Sleep 5000 '5秒ウェイト WSHShell.Run """C:\Documents and Settings\xxx\デスクトップ\aaaa.exe""" WScript.Sleep 5000 '5秒ウェイト WSHShell.AppActivate "ログイン画面" WScript.Sleep 5000 WSHShell.SendKeys "xxxx" WSHShell.SendKeys "~" 'ENTER WSHShell.Run "C:\Notes\notes.exe" WScript.Sleep 10000 '10秒ウェイト WSHShell.AppActivate "Lotus Notes" 'タイトル"Notes"を前面に表示させる WScript.Sleep 10000 WSHShell.SendKeys "xxxx" WSHShell.SendKeys "~" 'ENTER Set WSHShell = Nothing 'SendKeys メソッド 'http://msdn.microsoft.com/library/ja/default.asp?url=/library/ja/script56/html/wsMthSendKeys.asp 'WSHShell.Run "C:\Progra~1\EmEditor\EmEditor.exe" 'ロングファイル名のファイルを実行 """C:\Program Files\Internet Explorer\iexplore.exe""" |