vb ad i脚本

获取ip

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration ")
DIP = ""
dim x
dim IPAddr(255)
x = 0
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
If Not (IPConfig.IPAddress(i)="0.0.0.0") Then
IPAddr(x) = IPConfig.IPAddress(i)
x = x + 1
End if
Next
end if
next
' msgbox "First IP is: " & IPAddr(0)
' if more IP's exist, they will be in IPAddr(1), IPAddr(2) and so on
'Session.Property("EDIT_WCFIP")=IPAddr(0)
Session.Property("ODBC_RES_PROP")=IPAddr(0)

验证连接:

Session.Property("validate_sqlconn") = "1" '先让验证通过
Session.Property("TXT_SQL_ERR") = "" '清空验证信息

Dim objConnection
Set objConnection = CreateObject("ADODB.CONNECTION")

dim connStrParam
connStrParam = Session.Property("EDIT_CONNSTR")

Dim connStr
connStr = "provider=sqloledb;Initial Catalog=master;" & connStrParam

on error resume next
objConnection.Open connStr
If Err.Number <> 0 Then
Session.Property("validate_sqlconn") = "0"
Session.Property("TXT_SQL_ERR") = "连接失败!"& Err.Description
Err.Clear
ELSE
If (objConnection.State <> 1) Then
Session.Property("validate_sqlconn") = "0"
Session.Property("TXT_SQL_ERR") = "连接失败!未知错误。"
else
dim overwrite
if (Session.Property("CHK_DB_OVERWRITE") = "CheckBox") then
Session.Property("CHK_Exist_Exam") = "100"
Session.Property("CHK_Exist_Training") = "100"
Session.Property("CHK_Exist_Structure") = "100"
Session.Property("CHK_Exist_Resource") = "100"
'msgbox "123"
else
'msgbox "1234"
Dim objRecordSet
Set objRecordSet = CreateObject("ADODB.RECORDSET")

Dim objCommand
Set objCommand = CreateObject("ADODB.COMMAND")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = "select * from sysdatabases where name='" & Session.Property("DB_Name_Exam") & "'"
objRecordSet.CursorLocation = 3
objRecordSet.Open objCommand
dim count1
count1 = objRecordSet.RecordCount
if (count1 > 0) then
Session.Property("CHK_Exist_Exam") = "1"
else
Session.Property("CHK_Exist_Exam") = "100"
END IF
objRecordSet.close


Set objCommand = Nothing
Set objRecordSet = Nothing
end if
End If
set objConnection = Nothing
end if
'msgbox Session.Property("EDIT_Server")

 检测端口:

Session.Property("validate_webport") = "1" '先让验证通过
Session.Property("TXT_WEBPORT_ERR") = "" '清空验证信息

dim port
port = Session.Property("EDIT_WEBPORT")
'msgbox port
if(port = "") THEN
Session.Property("validate_webport") = "0"
Session.Property("TXT_WEBPORT_ERR") = "端口号不能为空!"
elseif(port <= 0) THEN
Session.Property("validate_webport") = "0"
Session.Property("TXT_WEBPORT_ERR") = "无效的端口号!"
else
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("netstat -an")
Set oStdOut = oExec.StdOut
Do Until oStdOut.AtEndOfStream
strLine = oStdOut.ReadLine
If InStr(strLine, ":" & port) > 0 And InStrRev(strLine, "ESTABLISHED") > 0 Then
Session.Property("validate_webport") = "0"
Session.Property("TXT_WEBPORT_ERR") = "端口已被占用!"
Exit Do
End If
Loop
End If

删除目录:

set fso=createobject("scripting.filesystemobject")
on error resume next
dim tar
tar = Session.Property("APPDIR")
msgbox tar
set sfold = fso.getfolder(tar)
sfold.attributes=0
sfold.delete

posted @ 2017-11-01 17:20  南瓜瓜  阅读(256)  评论(0编辑  收藏  举报