Set WshShell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

' Create a log file to help with troubleshooting
LogPath = FSO.BuildPath(FSO.GetSpecialFolder(2), "user_tracking_launcher.log") ' Temp folder
Set LogFile = FSO.OpenTextFile(LogPath, 8, True) ' 8 = ForAppending
LogFile.WriteLine(Now & " - VBS Launcher started")

' Get the current script directory
ScriptDir = FSO.GetParentFolderName(WScript.ScriptFullName)
LogFile.WriteLine(Now & " - Script directory: " & ScriptDir)

' Get the path to the PowerShell script
PowerShellScript = FSO.BuildPath(ScriptDir, "report.ps1")
LogFile.WriteLine(Now & " - PowerShell script path: " & PowerShellScript)

' Check if the PowerShell script exists
If FSO.FileExists(PowerShellScript) Then
    LogFile.WriteLine(Now & " - PowerShell script exists")
Else
    LogFile.WriteLine(Now & " - ERROR: PowerShell script does not exist!")
End If

' Build the command
PowerShellPath = "powershell.exe"
ScriptPath = """" & PowerShellScript & """"
Cmd = PowerShellPath & " -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File " & ScriptPath
LogFile.WriteLine(Now & " - Command: " & Cmd)

' Run the command
On Error Resume Next
WshShell.Run Cmd, 0, False
If Err.Number <> 0 Then
    LogFile.WriteLine(Now & " - ERROR: " & Err.Description)
Else
    LogFile.WriteLine(Now & " - Command executed successfully")
End If
On Error Goto 0

LogFile.Close
Set LogFile = Nothing
Set FSO = Nothing
Set WshShell = Nothing 