# Benefits of Using APIs

WinApis are generally better than using commands to execute code or to gather info. The Pros of using APIs are:&#x20;

1. Bypass command line logging(Defender may look specifically at LOLBins)
2. Confuse our activity with regular applications
3. May have additional functionality or for compatibility reasons

Here are some code snippets of using APIs for persistence:

### Service Creation

```
SC_HANDLE hManager = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
SC_HANDLE service = CreateService(
    hManager,
    "ServiceName",
    "Display Name",
    GENERIC_READ | GENERIC_EXECUTE,
    SERVICE_WIN32_OWN_PROCESS,
    SERVICE_AUTO_START,
    SERVICE_ERROR_IGNORE,
    "C:\\Windows\\System32\\cmd.exe",
    NULL, NULL, NULL, NULL, NULL
);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kwcsec.gitbook.io/the-red-team-handbook/techniques/defense-evasion/minimization/benefits-of-using-apis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
