# PCMonitor Agent - Quick Reference Card

## 🔧 Common Commands (Command Prompt)

```batch
REM ===== SERVICE COMMANDS =====

REM Check if service is installed
sc query PCMonitorAgent

REM Start service
net start PCMonitorAgent

REM Stop service
net stop PCMonitorAgent

REM Check if running
tasklist | findstr PCMonitorAgent.exe

REM Delete service (if needed)
sc delete PCMonitorAgent


REM ===== CONFIGURATION =====

REM View config
type C:\ProgramData\PCMonitor\config.json

REM Edit config
notepad C:\ProgramData\PCMonitor\config.json

REM Check if config exists
if exist "C:\ProgramData\PCMonitor\config.json" (
    echo Config found
) else (
    echo Config not found
)


REM ===== LOGS =====

REM List log files
dir C:\ProgramData\PCMonitor\Logs\

REM View latest log (last 50 lines)
powershell Get-Content C:\ProgramData\PCMonitor\Logs\Agent_*.log -Tail 50

REM Search for errors in logs
findstr /R "error|Error|ERROR" C:\ProgramData\PCMonitor\Logs\*.log


REM ===== NETWORK TESTS =====

REM Ping webhost
ping tracker.lppmunud.id

REM Test port 80 (requires telnet)
telnet tracker.lppmunud.id 80

REM Get IP of webhost
nslookup tracker.lppmunud.id


REM ===== EXECUTABLE =====

REM Check if exe exists
if exist "E:\xampp\htdocs\tracker\agent-csharp\bin\Release\net6.0-windows\PCMonitorAgent.exe" (
    echo Exe found - ready to run
) else (
    echo Exe not found - need to rebuild
)

REM Run exe directly (debug mode)
E:\xampp\htdocs\tracker\agent-csharp\bin\Release\net6.0-windows\PCMonitorAgent.exe debug


REM ===== INSTALLATION =====

REM Install service (run as Admin)
cd E:\xampp\htdocs\tracker\agent-csharp
INSTALL_SIMPLE.bat

REM Rebuild project
BUILD_CLEAN.bat

REM Run diagnostic
DIAGNOSTIC-CMD.bat
```

---

## 🎯 Troubleshooting Flowchart

```
Is service running?
├─ YES → Check config.json correct?
│        ├─ YES → Check logs for errors
│        │        ├─ ERROR found → Fix error
│        │        └─ No error → Check database
│        └─ NO  → Edit config.json + Restart service
└─ NO  → Run: net start PCMonitorAgent
         ├─ Started OK? → Check logs
         └─ Error? → Reinstall: INSTALL_SIMPLE.bat
```

---

## ❌ Common Problems & Fixes

### Problem 1: "Service not found"
```batch
C:\> net start PCMonitorAgent
The PCMonitorAgent service is not found

SOLUTION:
- Run INSTALL_SIMPLE.bat to install
- Make sure you're running as Administrator
```

### Problem 2: "Cannot start service"
```batch
C:\> net start PCMonitorAgent
System error 5 has occurred: Access is denied

SOLUTION:
- Right-click cmd.exe
- Select "Run as administrator"
```

### Problem 3: "Cannot reach webhost"
```batch
C:\> ping tracker.lppmunud.id
Ping request could not find host

SOLUTION:
- Check internet connection
- Check DNS settings
- Check firewall
- Try: ipconfig /flushdns
```

### Problem 4: "Config file not found"
```
ERROR: config.json NOT found
Expected: C:\ProgramData\PCMonitor\config.json

SOLUTION:
- Run INSTALL_SIMPLE.bat to generate config
- Check service status: sc query PCMonitorAgent
- Check logs: C:\ProgramData\PCMonitor\Logs\
```

### Problem 5: "Data in database but not in dashboard"
```
SOLUTION:
1. Refresh browser: Ctrl+F5
2. Clear cache: Ctrl+Shift+Delete
3. Check if filter applied
4. Check logs: http://localhost/tracker/debug.php
5. Check database: SELECT COUNT(*) FROM pc_activities
```

---

## 📊 Check Status Step-by-Step

### Step 1: Service Status
```batch
sc query PCMonitorAgent
```
Expected: `STATE : 4 RUNNING`

### Step 2: Config Correct
```batch
type C:\ProgramData\PCMonitor\config.json
```
Expected: `api_url: http://tracker.lppmunud.id/tracker/api`

### Step 3: Network OK
```batch
ping tracker.lppmunud.id
```
Expected: Replies received

### Step 4: Logs Clean
```batch
findstr "ERROR" C:\ProgramData\PCMonitor\Logs\*.log
```
Expected: No results (no errors)

### Step 5: Database Has Data
Check: http://localhost/tracker/debug.php
Expected: Agents > 0, Activities > 0

### Step 6: Dashboard Shows Data
Check: http://localhost/tracker/dashboard
Expected: See agents and activities

---

## 🚀 Quick Setup (First Time)

```batch
REM 1. Build the project
cd E:\xampp\htdocs\tracker\agent-csharp
BUILD_CLEAN.bat

REM 2. Install as service (Run as Admin!)
INSTALL_SIMPLE.bat

REM 3. Check if running
sc query PCMonitorAgent

REM 4. Check config
type C:\ProgramData\PCMonitor\config.json

REM 5. Run diagnostic
DIAGNOSTIC-CMD.bat

REM 6. View logs
notepad C:\ProgramData\PCMonitor\Logs\Agent_*.log

REM 7. Check database
REM Open: http://localhost/tracker/debug.php

REM 8. View dashboard
REM Open: http://localhost/tracker/dashboard
```

---

## 📞 When Asking for Help

Please provide:

1. Service status:
```batch
sc query PCMonitorAgent > service_status.txt
```

2. Config file:
```batch
type C:\ProgramData\PCMonitor\config.json > config_backup.txt
```

3. Recent logs (last 50 lines):
```batch
powershell "Get-Content C:\ProgramData\PCMonitor\Logs\Agent_*.log -Tail 50" > recent_logs.txt
```

4. Diagnostic output:
```batch
DIAGNOSTIC-CMD.bat > diagnostic_output.txt
```

5. Network test:
```batch
ping tracker.lppmunud.id > ping_test.txt
nslookup tracker.lppmunud.id > nslookup_test.txt
```

Then share all these .txt files!

---

**Version:** 1.0  
**Last Updated:** 2026-03-27  
**For:** PCMonitor Agent v1.0
