Fix application tracking in api.asp for Phase 2 schema
Issues Fixed: 1. UpdateInstalledApps() was using wrong table name 'machineapplications' - Changed to correct table 'installedapps' 2. INSERT was missing 'isactive' column required by installedapps table 3. GetOrCreateApplication() was using wrong column names: - 'applicationid' → 'appid' (primary key) - 'applicationname' → 'appname' - Removed 'version' column (doesn't exist in applications table) - Now stores version info in 'appdescription' field How It Works Now: - PowerShell script collects installed apps from registry - Filters to tracked apps (UDC, PPDCS, Oracle, Tanium, eDNC, etc.) - Sends to api.asp with action=updateInstalledApps - API deletes old app mappings for PC: DELETE FROM installedapps - API creates/finds apps in 'applications' table - API inserts new mappings: INSERT INTO installedapps (machineid, appid, isactive) Tables Used: - applications (appid, appname, appdescription, isactive) - installedapps (machineid, appid, isactive) Impact: Application tracking now works correctly with Phase 2 schema 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
37
api.asp
37
api.asp
@@ -319,7 +319,7 @@ Sub UpdateInstalledApps()
|
|||||||
Dim cmdDelete
|
Dim cmdDelete
|
||||||
Set cmdDelete = Server.CreateObject("ADODB.Command")
|
Set cmdDelete = Server.CreateObject("ADODB.Command")
|
||||||
cmdDelete.ActiveConnection = objConn
|
cmdDelete.ActiveConnection = objConn
|
||||||
cmdDelete.CommandText = "DELETE FROM machineapplications WHERE machineid = ?"
|
cmdDelete.CommandText = "DELETE FROM installedapps WHERE machineid = ?"
|
||||||
cmdDelete.Parameters.Append cmdDelete.CreateParameter("@machineid", 3, 1, , CLng(machineid))
|
cmdDelete.Parameters.Append cmdDelete.CreateParameter("@machineid", 3, 1, , CLng(machineid))
|
||||||
cmdDelete.Execute
|
cmdDelete.Execute
|
||||||
|
|
||||||
@@ -343,13 +343,14 @@ Sub UpdateInstalledApps()
|
|||||||
LogToFile "GetOrCreateApplication returned appid: " & appid
|
LogToFile "GetOrCreateApplication returned appid: " & appid
|
||||||
|
|
||||||
If appid > 0 Then
|
If appid > 0 Then
|
||||||
' Insert mapping
|
' Insert mapping (installedapps table uses appid not applicationid)
|
||||||
Dim cmdInsert
|
Dim cmdInsert
|
||||||
Set cmdInsert = Server.CreateObject("ADODB.Command")
|
Set cmdInsert = Server.CreateObject("ADODB.Command")
|
||||||
cmdInsert.ActiveConnection = objConn
|
cmdInsert.ActiveConnection = objConn
|
||||||
cmdInsert.CommandText = "INSERT INTO machineapplications (machineid, applicationid) VALUES (?, ?)"
|
cmdInsert.CommandText = "INSERT INTO installedapps (machineid, appid, isactive) VALUES (?, ?, ?)"
|
||||||
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@machineid", 3, 1, , CLng(machineid))
|
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@machineid", 3, 1, , CLng(machineid))
|
||||||
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@appid", 3, 1, , CLng(appid))
|
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@appid", 3, 1, , CLng(appid))
|
||||||
|
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@isactive", 11, 1, , 1) ' 1 = active
|
||||||
cmdInsert.Execute
|
cmdInsert.Execute
|
||||||
|
|
||||||
If Err.Number = 0 Then
|
If Err.Number = 0 Then
|
||||||
@@ -1224,9 +1225,9 @@ Function GetOrCreateApplication(appName, appVersion)
|
|||||||
Exit Function
|
Exit Function
|
||||||
End If
|
End If
|
||||||
|
|
||||||
' Check if application exists
|
' Check if application exists (applications table has appid and appname columns)
|
||||||
Dim strSQL, rsResult
|
Dim strSQL, rsResult
|
||||||
strSQL = "SELECT applicationid FROM applications WHERE applicationname = ?"
|
strSQL = "SELECT appid FROM applications WHERE appname = ?"
|
||||||
Set rsResult = ExecuteParameterizedQuery(objConn, strSQL, Array(appName))
|
Set rsResult = ExecuteParameterizedQuery(objConn, strSQL, Array(appName))
|
||||||
|
|
||||||
If Err.Number <> 0 Then
|
If Err.Number <> 0 Then
|
||||||
@@ -1236,8 +1237,8 @@ Function GetOrCreateApplication(appName, appVersion)
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
If Not rsResult.EOF Then
|
If Not rsResult.EOF Then
|
||||||
GetOrCreateApplication = rsResult("applicationid")
|
GetOrCreateApplication = rsResult("appid")
|
||||||
LogToFile "Found existing applicationid: " & GetOrCreateApplication
|
LogToFile "Found existing appid: " & GetOrCreateApplication
|
||||||
rsResult.Close
|
rsResult.Close
|
||||||
Set rsResult = Nothing
|
Set rsResult = Nothing
|
||||||
Exit Function
|
Exit Function
|
||||||
@@ -1247,17 +1248,23 @@ Function GetOrCreateApplication(appName, appVersion)
|
|||||||
|
|
||||||
LogToFile "Application not found, creating new..."
|
LogToFile "Application not found, creating new..."
|
||||||
|
|
||||||
' Create new application
|
' Create new application (note: applications table doesn't have version column)
|
||||||
' Prepare parameter value (VBScript doesn't have IIf)
|
' Version info is tracked elsewhere or ignored for now
|
||||||
Dim pVersion
|
|
||||||
If appVersion <> "" Then pVersion = appVersion Else pVersion = Null
|
|
||||||
|
|
||||||
Dim cmdInsert
|
Dim cmdInsert
|
||||||
Set cmdInsert = Server.CreateObject("ADODB.Command")
|
Set cmdInsert = Server.CreateObject("ADODB.Command")
|
||||||
cmdInsert.ActiveConnection = objConn
|
cmdInsert.ActiveConnection = objConn
|
||||||
cmdInsert.CommandText = "INSERT INTO applications (applicationname, version) VALUES (?, ?)"
|
cmdInsert.CommandText = "INSERT INTO applications (appname, appdescription, isactive) VALUES (?, ?, ?)"
|
||||||
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@appname", 200, 1, 255, appName)
|
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@appname", 200, 1, 50, appName)
|
||||||
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@version", 200, 1, 50, pVersion)
|
|
||||||
|
' Use version as description if available
|
||||||
|
Dim pDescription
|
||||||
|
If appVersion <> "" Then
|
||||||
|
pDescription = "Version: " & appVersion
|
||||||
|
Else
|
||||||
|
pDescription = "Auto-detected application"
|
||||||
|
End If
|
||||||
|
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@description", 200, 1, 255, pDescription)
|
||||||
|
cmdInsert.Parameters.Append cmdInsert.CreateParameter("@isactive", 11, 1, , 1)
|
||||||
cmdInsert.Execute
|
cmdInsert.Execute
|
||||||
|
|
||||||
If Err.Number <> 0 Then
|
If Err.Number <> 0 Then
|
||||||
|
|||||||
Reference in New Issue
Block a user