执行后锁定VBScript文件

时间:2017-01-03 02:01:09

标签: vbscript

我的VBScript文件在执行后被锁定。我正在开发它,所以我正在写一些脚本,然后测试运行它。但是在它完成之后我尝试对脚本进行更多编辑,我不能因为Windows已将其锁定。我需要使用Process Explorer(sys internals app)来删除文件的句柄。

编辑:我正在我的基本机器中开发脚本并在VM(虚拟机)中运行脚本。 Process Explorer告诉我VMWare-vmx.exe(VM实例)正在锁定脚本,但运行PE并在VM中搜索脚本文件不会产生任何结果..

我找到了一个脚本来检查VBscripts正在运行什么,它似乎仍然没有运行,只是出于某种原因被锁定...

我的脚本正在连接ADODB对象,我正在关闭最后的连接。

这是我的脚本,如果它有帮助:

Const ForAppending = 8

Dim fso
Dim objShell

Dim IBM_Conn
Dim IBM_RS
Dim IBM_Field

Dim Loc_Conn

'create an instance of the ADO connection and recordset objects
Set IBM_Conn = CreateObject("ADODB.Connection")
Set IBM_RS = CreateObject("ADODB.Recordset")

Set Loc_Conn = CreateObject("ADODB.Connection")

'open the connection to the database
IBM_Conn.Open "DSN=IBMSeriesIData64"
Loc_Conn.Open "DSN=TanksDatabase64"

'Open the recordset object executing the SQL statement and return records 
IBM_RS.Open "SELECT STANK, SBREG, SBVIN, SBCAT, SBCLS, SBSPC, SBBCH, SBSTS, SLITRE, SFULL from BWSTK" ,IBM_Conn

'first of all determine whether there are any records 
If IBM_RS.EOF Then
    'Write to the log file
        Set fso = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("Wscript.Shell")
    strPath = Wscript.ScriptFullName
    Set objFile = fso.GetFile(strPath)
    strPath = fso.GetParentFolderName(objFile) 
    strPath = strPath & "\ErrLog.txt"
    MsgBox strPath
    If Not fso.FileExists(strPath) Then
        fso.CreateTextFile(strPath)
    End If
    Set LogFile = fso.OpenTextFile(strPath, ForAppending)
    LogFile.WriteLine Now & " - Error updating IBM Series i tank data; No records found for query: 'SELECT STANK, SBREG, SBVIN, SBCAT, SBCLS, SBSPC, SBBCH, SBSTS, SLITRE, SFULL from BWSTK'"
    LogFile.Close
Else
    'Ensure all records are deleted from the staging data table
    Loc_Conn.Execute "DELETE FROM datIBM_Series_i_RawData_Staging"

    'Loop through each row in the recordset and insert it into the staging  table
    Do While NOT IBM_RS.EOF
        sTank = IBM_RS("STANK").Value
        sRegion = IBM_RS("SBREG").Value
        sVintage = IBM_RS("SBVIN").Value
        sCategory = IBM_RS("SBCAT").Value
        sClass = IBM_RS("SBCLS").Value
        sSpec = IBM_RS("SBSPC").Value
        sBatch = IBM_RS("SBBCH").Value
        sStatus = IBM_RS("SBSTS").Value
        fVolCurrent = IBM_RS("SLITRE").Value
        fVolCapacity = IBM_RS("SFULL").Value

        'Create the insert statement
        Loc_SQL = "INSERT INTO datIBM_Series_i_RawData_Staging (Tank, Region, Vintage, Category, Class, Spec, Batch, Status, VolCurrent, VolCapacity) VALUES ("
        Loc_SQL = Loc_SQL + "'" + sTank + "'"
        Loc_SQL = Loc_SQL + ",'" + sRegion + "'"
        Loc_SQL = Loc_SQL + ",'" + sVintage + "'"
        Loc_SQL = Loc_SQL + ",'" + sCategory + "'"
        Loc_SQL = Loc_SQL + ",'" + sClass + "'"
        Loc_SQL = Loc_SQL + ",'" + sSpec + "'"
        Loc_SQL = Loc_SQL + ",'" + sBatch + "'"
        Loc_SQL = Loc_SQL + ",'" + sStatus + "'"
        Loc_SQL = Loc_SQL + "," + CStr(fVolCurrent)
        Loc_SQL = Loc_SQL + "," + CStr(fVolCapacity)
        Loc_SQL = Loc_SQL + ")"

        Loc_Conn.Execute Loc_SQL

        IBM_RS.MoveNext   
    Loop

    'Move the staging data into the production table
    Loc_Conn.BeginTrans
    Loc_Conn.Execute "DELETE FROM datIBM_Series_i_RawData"
    Loc_Conn.Execute "INSERT INTO datIBM_Series_i_RawData SELECT * FROM datIBM_Series_i_RawData_Staging"
    Loc_Conn.Execute "DELETE FROM datIBM_Series_i_RawData_Staging"
    Loc_Conn.CommitTrans
End If

'close the connection and recordset objects to free up resources
IBM_RS.Close
Set IBM_RS = Nothing
IBM_Conn.Close
Loc_Conn.Close
Set IBM_Conn = Nothing
Set Loc_Conn = Nothing
MsgBox "End"

0 个答案:

没有答案