2022年5月
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
無料ブログはココログ

« 2011年12月 | トップページ | 2012年2月 »

2012年1月30日 (月)

固定サイトショートカット(.website)のコンテキストメニューに「編集」、プロパティシートに「Webドキュメント」タブを追加する。

固定サイトショートカットのプロパティシートにはインターネットショートカットにあるような「Webドキュメント」タブがありません。それを追加します。
ついでに、コンテキストメニューにメモ帳による「編集」も追加します。

website.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Microsoft.Website\Shell\Edit\Command]
@="C:\\Windows\\notepad.exe %1"

[HKEY_CLASSES_ROOT\Microsoft.Website\ShellEx\PropertySheetHandlers\{FBF23B40-E3F0-101B-8488-00AA003E56F8}]

2012年1月29日 (日)

ファイルやフォルダを「送る」ことでリネームする。

エクスプローラのインライン編集ボックスでのリネームでは、ショートカットの拡張子などが変更できません。
そこで、「名前の変更.vbs」に送ることでリネームします。

名前の変更.vbs ファイルやフォルダ...

Set fso=CreateObject("Scripting.FileSystemObject")
For Each path In WScript.Arguments
  If fso.FileExists(path) Then
    Set file=fso.GetFile(path)
  Else
    Set file=fso.GetFolder(path)
  End If
  name=InputBox(file.Path,"Rename ?",file.Name)
  If name<>"" Then file.Name=name
Next

sendtoフォルダに入れて使います。

2012年1月21日 (土)

IEウィンドウを擬似最大化に設定する。

IEのウィンドウを最大化と同じ位置とサイズに設定します。

ie_set_max.vbs

Set doc=CreateObject("htmlfile")
arr=Array(44,0,0,0,0,0,0,0,1,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,5,0,4,0,3,0)
Call i2b(doc.parentWindow.screen.availWidth,arr,36)
Call i2b(doc.parentWindow.screen.availHeight,arr,40)
Const HKEY_CURRENT_USER=&H80000001
Call GetObject("Winmgmts:root\default:StdRegProv").SetBinaryValue(HKEY_CURRENT_USER,"Software\Microsoft\Internet Explorer\Main","Window_Placement",arr)

Sub i2b(ByVal n,byref arr,ind)
For k=ind To ind+3
  arr(k)=n Mod 256
  n=n\256
Next
End Sub

2012年1月20日 (金)

IEのウィンドウの位置とサイズを設定する。

このスクリプトを実行すると、IEウィンドウが開きます。その位置とサイズを変更して終了するとそれらがレジストリに設定されます。

ie_set_window.vbs

Set ie=CreateObject("InternetExplorer.Application")
ie.Visible=True
ie.Navigate "about:blank"
Do While ie.Busy Or ie.ReadyState<>4
  WScript.Sleep 100
Loop
Set ie.Document.body.OnBeforeUnload=GetRef("OnUnload")
Do While TypeName(ie)="IWebBrowser2"
  WScript.Sleep 100
Loop

Sub OnUnload
arr=Array(44,0,0,0,0,0,0,0,1,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
Call i2b(ie.Left,arr,28)
Call i2b(ie.Top,arr,32)
Call i2b(ie.Left+ie.Width,arr,36)
Call i2b(ie.Top+ie.Height,arr,40)
Const HKEY_CURRENT_USER=&H80000001
Call GetObject("Winmgmts:root\default:StdRegProv").SetBinaryValue(HKEY_CURRENT_USER,"Software\Microsoft\Internet Explorer\Main","Window_Placement",arr)
End Sub

Sub i2b(ByVal n,byref arr,ind)
For k=ind To ind+3
  arr(k)=n Mod 256
  n=n\256
Next
End Sub

2012年1月18日 (水)

timeoutコマンドがタイムアウトしたか否かを判定する。

バックスペース文字を区切り文字にして、秒数+1番目のトークンがあればタイムアウト。なければ中断。

for /f  %%i in ('"cmd /k prompt $h <nul"') do set bs=%%i
for /f "delims=%bs% tokens=6" %%i in ('timeout /t 5') do echo %%i - timeouted

または

for /f "delims= tokens=6" %%i in ('timeout /t 5') do echo %%i - timeouted

2012年1月15日 (日)

バッチファイルでプロセスを開始、終了する。

バッチファイルではプロセスIDを得ることが難しいため、プロセスを特定して終了させるのが大変です。

ここではユニークなウィンドウタイトルを指定して、それを目印に終了させます。

set title=title%random%
start /min "%title%" cmd.exe /c notepad.exe
pause
taskkill /t /fi "windowtitle eq %title%"

2012年1月14日 (土)

バックスペース文字をバッチファイルで使う。

メモ帳でキーボードからBS文字(^h,0x08)を入れるのは困難ですが、貼り付けや他の方法では可能です。

cmd /k prompt $h<nul >aaa.txt

入れたものをそのまま使ってもいいし、環境変数に入れて使ってもよいでしょう。

set bs=

バッチファイル内で生成するには、

for /f  %%i in ('"cmd /k prompt $h <nul"') do set bs=%%i

2012年1月 9日 (月)

フォルダの「総ファイルサイズ」と「ファイル数」カラムに値を設定、表示する。(その3)

親ディレクトリをドロップすると、子孫ディレクトリのすべてに設定します。ただし、アクセス許可のないものはスキップします。

FolderSize.vbs 親フォルダパス

Option Explicit
Dim fso
Set fso=CreateObject("Scripting.FileSystemObject")
Call TreeFolderSize(fso.GetFolder(WScript.Arguments.Item(0)))

Sub TreeFolderSize(Folder)
Dim SubFolder
On Error Resume Next
For Each SubFolder In Folder.SubFolders
  Call TreeFolderSize(SubFolder)
  Call FolderSize(SubFolder)
Next
End Sub

Sub FolderSize(Folder)
Call UpdateIniFile(Folder.Path & "\desktop.ini","[{28636AA6-953D-11D2-B5D6-00C04FD918D0}]","Prop14=","21," & Folder.Size)
Call UpdateIniFile(Folder.Path & "\desktop.ini","[{28636AA6-953D-11D2-B5D6-00C04FD918D0}]","Prop12=","21," & FileCount(Folder))
If Not (Folder.Attributes And 1) Then Folder.Attributes=Folder.Attributes Or 1
End Sub

Sub UpdateIniFile(Path,Section,Name,Value)
Dim fso
Dim File
Dim Lines
Dim Line
Dim State
Set fso=CreateObject("Scripting.FileSystemObject")
Set Lines=CreateObject("Scripting.Dictionary")
Set File=fso.OpenTextFile(Path,1,True)
State=0
Do While Not File.AtEndOfStream
  Line=File.ReadLine()
  Select Case State
  Case 0
    If Line=Section Then State=1
    Lines.Add Lines.Count,Line
  Case 1
    If Left(Line,1)="[" Then
      State=2
      Lines.Add Lines.Count,Name & Value
      Lines.Add Lines.Count,Line
    Else
      If InStr(Line,Name)=1 Then
        State=2
        Lines.Add Lines.Count,Name & Value
      Else
        Lines.Add Lines.Count,Line
      End If
    End If
  Case 2
    Lines.Add Lines.Count,Line
  End Select
Loop
If State=0 Then
  Lines.Add Lines.Count,Section
  Lines.Add Lines.Count,Name & Value
ElseIf State=1 Then
  Lines.Add Lines.Count,Name & Value
End If
File.Close
Set File=fso.OpenTextFile(Path,2,True)
File.WriteLine Join(Lines.Items,vbCrLf)
File.Close
End Sub

Function FileCount(Folder)
Dim SubFolder
FileCount=Folder.Files.Count
For Each SubFolder In Folder.SubFolders
  FileCount=FileCount+FileCount(SubFolder)
Next
End Function

2012年1月 8日 (日)

フォルダの「総ファイルサイズ」と「ファイル数」カラムに値を設定、表示する。(その2)

親フォルダをドロップすると、サブフォルダのdesktop.iniに「総ファイルサイズ」と「ファイル数」を設定します。
これでエクスプローラに表示されます。
この情報はエクスプローラプロセスにキャッシュされるため、設定し直しても表示に即反映されません。
フォルダ名を変えるか、エクスプローラを別プロセスで起動すれば、表示に反映されます。
explorer.exe /separate,フォルダ

FolderSize.vbs 親フォルダパス

Option Explicit
Dim fso
Dim Folder
Set fso=CreateObject("Scripting.FileSystemObject")
For Each Folder In fso.GetFolder(WScript.Arguments.Item(0)).SubFolders
  Call UpdateIniFile(Folder.Path & "\desktop.ini","[{28636AA6-953D-11D2-B5D6-00C04FD918D0}]","Prop14=","21," & Folder.Size)
  Call UpdateIniFile(Folder.Path & "\desktop.ini","[{28636AA6-953D-11D2-B5D6-00C04FD918D0}]","Prop12=","21," & FileCount(Folder))
  If Not (Folder.Attributes And 1) Then Folder.Attributes=Folder.Attributes Or 1
Next

Sub UpdateIniFile(Path,Section,Name,Value)
Dim fso
Dim File
Dim Lines
Dim Line
Dim State
Set fso=CreateObject("Scripting.FileSystemObject")
Set Lines=CreateObject("Scripting.Dictionary")
Set File=fso.OpenTextFile(Path,1,True)
State=0
Do While Not File.AtEndOfStream
  Line=File.ReadLine()
  Select Case State
  Case 0
    If Line=Section Then State=1
    Lines.Add Lines.Count,Line
  Case 1
    If Left(Line,1)="[" Then
      State=2
      Lines.Add Lines.Count,Name & Value
      Lines.Add Lines.Count,Line
    Else
      If InStr(Line,Name)=1 Then
        State=2
        Lines.Add Lines.Count,Name & Value
      Else
        Lines.Add Lines.Count,Line
      End If
    End If
  Case 2
    Lines.Add Lines.Count,Line
  End Select
Loop
If State=0 Then
  Lines.Add Lines.Count,Section
  Lines.Add Lines.Count,Name & Value
ElseIf State=1 Then
  Lines.Add Lines.Count,Name & Value
End If
File.Close
Set File=fso.OpenTextFile(Path,2,True)
File.WriteLine Join(Lines.Items,vbCrLf)
File.Close
End Sub

Function FileCount(Folder)
Dim SubFolder
FileCount=Folder.Files.Count
For Each SubFolder In Folder.SubFolders
  FileCount=FileCount+FileCount(SubFolder)
Next
End Function

« 2011年12月 | トップページ | 2012年2月 »