'
' イベントログを出力
'
Option Explicit
Const cEventSuccess = 0
Const cEventError = 1
Const cEventWarning = 2
Dim oShell
Set oShell = WScript.CreateObject("WScript.Shell")
Call oShell.LogEvent(cEventSuccess, "成功")
Call oShell.LogEvent(cEventError, "失敗")
Call oShell.LogEvent(cEventWarning, "警告")
Set oShell = Nothing
2008年1月31日木曜日
[VBScript]HTTPのPOSTリクエスト
'
' HTTPのPOSTリクエスト
'
Option Explicit
Dim oHttpRequest
Dim sURL
Dim sPostData
sURL = "URL"
sPostData = "POSTデータ"
Set oHttpRequest = WScript.CreateObject("MSXML2.XMLHTTP.3.0")
Call oHttpRequest.Open("POST", sURL, False)
Call oHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
Call oHttpRequest.Send(sPostData)
WScript.Echo(oHttpRequest.responseText)
Set oHttpRequest = Nothing
' HTTPのPOSTリクエスト
'
Option Explicit
Dim oHttpRequest
Dim sURL
Dim sPostData
sURL = "URL"
sPostData = "POSTデータ"
Set oHttpRequest = WScript.CreateObject("MSXML2.XMLHTTP.3.0")
Call oHttpRequest.Open("POST", sURL, False)
Call oHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
Call oHttpRequest.Send(sPostData)
WScript.Echo(oHttpRequest.responseText)
Set oHttpRequest = Nothing
[VBScript]encodeURI
'
' VBScriptでencodeURI
'
Option Explicit
Function encodeURI(ByVal sBuff)
Dim oScriptControl
Dim oJavaScript
Set oScriptControl = WScript.CreateObject("ScriptControl")
oScriptControl.Language = "JavaScript"
Set oJavaScript = oScriptControl.CodeObject
encodeURI = oJavaScript.encodeURI(sBuff)
Set oJavaScript = Nothing
Set oScriptControl = Nothing
End Function
WScript.Echo encodeURI("文字列")
' VBScriptでencodeURI
'
Option Explicit
Function encodeURI(ByVal sBuff)
Dim oScriptControl
Dim oJavaScript
Set oScriptControl = WScript.CreateObject("ScriptControl")
oScriptControl.Language = "JavaScript"
Set oJavaScript = oScriptControl.CodeObject
encodeURI = oJavaScript.encodeURI(sBuff)
Set oJavaScript = Nothing
Set oScriptControl = Nothing
End Function
WScript.Echo encodeURI("文字列")
2008年1月30日水曜日
[VBScript]テキストファイルの書き込み
'
' テキストファイルの書き込み
'
Option Explicit
Dim oFSO
Dim oTextStream
Dim sPath
Dim aLines()
Dim sLine
ReDim Preserve aLines(0): aLines(0) = "AAA"
ReDim Preserve aLInes(1): aLines(1) = "BBB"
ReDim Preserve aLInes(2): aLines(2) = "CCC"
sPath = ".\sample.txt"
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set oTextStream = oFSO.CreateTextFile(sPath)
For Each sLine In aLines
oTextStream.WriteLine(sLine)
Next
oTextStream.Close: Set oTextStream = Nothing
Set oFSO = Nothing
' テキストファイルの書き込み
'
Option Explicit
Dim oFSO
Dim oTextStream
Dim sPath
Dim aLines()
Dim sLine
ReDim Preserve aLines(0): aLines(0) = "AAA"
ReDim Preserve aLInes(1): aLines(1) = "BBB"
ReDim Preserve aLInes(2): aLines(2) = "CCC"
sPath = ".\sample.txt"
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set oTextStream = oFSO.CreateTextFile(sPath)
For Each sLine In aLines
oTextStream.WriteLine(sLine)
Next
oTextStream.Close: Set oTextStream = Nothing
Set oFSO = Nothing
[VBScript]テキストファイルの読み込み
'
' テキストファイルの読み込み
'
Option Explicit
Const cForReading = 1
Dim oFSO
Dim oTextStream
Dim sPath
sPath = ".\sample.txt"
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set oTextStream = oFSO.OpenTextFile(sPath, cForReading)
Do While oTextStream.AtEndOfStream <> True
WScript.Echo oTextStream.ReadLine
Loop
oTextStream.Close: Set oTextStream = Nothing
Set oFSO = Nothing
' テキストファイルの読み込み
'
Option Explicit
Const cForReading = 1
Dim oFSO
Dim oTextStream
Dim sPath
sPath = ".\sample.txt"
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set oTextStream = oFSO.OpenTextFile(sPath, cForReading)
Do While oTextStream.AtEndOfStream <> True
WScript.Echo oTextStream.ReadLine
Loop
oTextStream.Close: Set oTextStream = Nothing
Set oFSO = Nothing
[VBScript]FQDNを取得
'
' FQDNを取得
'
Option Explicit
Dim oWMIService
Dim oItems
Dim oItem
Dim sComputer
sComputer = "."
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
Set oItems = oWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each oItem in oItems
If (oItem.DNSHostName <> "") Then
WScript.Echo oItem.DNSHostName & "." & oItem.DNSDomain
End If
Next
Set oItem = Nothing
Set oItems = Nothing
Set oWMIService = Nothing
' FQDNを取得
'
Option Explicit
Dim oWMIService
Dim oItems
Dim oItem
Dim sComputer
sComputer = "."
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
Set oItems = oWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each oItem in oItems
If (oItem.DNSHostName <> "") Then
WScript.Echo oItem.DNSHostName & "." & oItem.DNSDomain
End If
Next
Set oItem = Nothing
Set oItems = Nothing
Set oWMIService = Nothing
[VBScript]コンピュータ名を取得
'
' コンピュータ名を取得
'
Option Explicit
Dim oWMIService
Dim oItems
Dim oItem
Dim sComputer
sComputer = "."
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
Set oItems = oWMIService.ExecQuery("Select * From Win32_OperatingSystem")
For Each oItem in oItems
WScript.Echo oItem.CSName
Next
Set oItem = Nothing
Set oItems = Nothing
Set oWMIService = Nothing
' コンピュータ名を取得
'
Option Explicit
Dim oWMIService
Dim oItems
Dim oItem
Dim sComputer
sComputer = "."
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
Set oItems = oWMIService.ExecQuery("Select * From Win32_OperatingSystem")
For Each oItem in oItems
WScript.Echo oItem.CSName
Next
Set oItem = Nothing
Set oItems = Nothing
Set oWMIService = Nothing
[VBScript]IPアドレスの取得
'
' IPアドレスの取得
'
Option Explicit
Dim oWMIService, oIPConfigSet, oIPConfig
Dim sComputer, sAddress
sComputer = "."
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
Set oIPConfigSet = oWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each oIPConfig in oIPConfigSet
For Each sAddress In oIPConfig.IPAddress
WScript.Echo sAddress
Next
Next
Set oIPConfig = Nothing
Set oIPConfigSet = Nothing
Set oWMIService = Nothing
' IPアドレスの取得
'
Option Explicit
Dim oWMIService, oIPConfigSet, oIPConfig
Dim sComputer, sAddress
sComputer = "."
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
Set oIPConfigSet = oWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each oIPConfig in oIPConfigSet
For Each sAddress In oIPConfig.IPAddress
WScript.Echo sAddress
Next
Next
Set oIPConfig = Nothing
Set oIPConfigSet = Nothing
Set oWMIService = Nothing
登録:
投稿 (Atom)