|
メッセージ表示
|
|
|
■Hello.vbs
WScript.Echo "Hello World"
|
↓
|
コマンドプロンプトからの起動
|
|
|
- メッセージ表示
↓
- コマンドプロンプト内にメッセージ表示(バージョン表示あり)
C:\> cscript Hello.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
Hello World
|
- コマンドプロンプト内にメッセージ表示(バージョン表示なし)
C:\> cscript //nologo Hello.vbs
Hello World
|
|
アプリケーションの起動
|
|
|
Set ws = WScript.CreateObject("WScripg.Shell")
'アプリケーションの起動
ws.Run "Notepad"
|
|
引数の使用
|
|
|
Set arg = WScript.Arguments
'arg配列にVBS起動時の引数が格納される
wscript.echo arg(0) '第1引数を出力
wscript.echo arg(1) '第2引数を出力
wscript.echo arg(2) '第3引数を出力
wscript.echo arg(3) '第4引数を出力
|
|
プロセスの戻り値を指定し終了
|
|
|
'戻り値を指定できる 例では戻り値 0
WScript.Quit(0)
|
|
テキストファイル読込
|
|
|
Set fso = WScript.CreateObject("Scripting.filesystemObject")
'テキストファイルの読込 引数1は読込専用 2は書込専用 8は追加書込専用
Set textFile = fso.OpneTextFile("C:\Input.txt",1)
Do While Not textFile.AtEndOfStream
'1行づつ読込(書込の場合は textFile.WriteLine(tmpStr))
tmpStr = textFile.ReadLine
Loop
|
|
ネットワークドライブに接続
|
|
|
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
Call objShell.Run("%COMSPEC% /c net use ・・・(←ここにnet useコマンド)", 0, True)
set objshell=nothing
|
|
|