QSC Post Quantum Cryptographic Library 1.0.0.6c (A6)
A post quantum secure library written in Ansi C
 
Loading...
Searching...
No Matches
winutils.h File Reference

Windows utility functions. More...

#include "common.h"

Go to the source code of this file.

Macros

#define QSC_WINTOOLS_ATTRIBUTES_BUFFER_SIZE   256ULL
 The file attributes buffer size.
 
#define QSC_WINTOOLS_NETSTAT_BUFFER_SIZE   1024ULL
 The network statistics buffer size.
 
#define QSC_WINTOOLS_NETSTAT_NAME_SIZE   256ULL
 The network statistics name size.
 
#define QSC_WINTOOLS_PROCESS_LIST_SIZE   16384ULL
 The process list buffer size.
 
#define QSC_WINTOOLS_REGISTRY_BUFFER_SIZE   1024ULL
 The registry buffer size.
 
#define QSC_WINTOOLS_REGISTRY_LIST_SIZE   8192ULL
 The registry list buffer size.
 
#define QSC_WINTOOLS_RUNAS_BUFFER_SIZE   260ULL
 The runas buffer size.
 
#define QSC_WINTOOLS_SERVICE_LIST_SIZE   16384ULL
 The service list size.
 
#define QSC_WINTOOLS_SERVICE_BUFFER_SIZE   512ULL
 The service list buffer size.
 
#define QSC_WINTOOLS_SERVICE_LIST_DESCRIPTION
 Include the service descriptions in the service list output.
 

Enumerations

enum  qsc_winutils_registry_value_types { REG_SZ_TYPE = 0x00U , REG_DWORD_TYPE = 0x01U , REG_QWORD_TYPE = 0x02U , REG_BINARY_TYPE = 0x03U }
 The registry value option types. More...
 
enum  qsc_winutils_service_states { QSC_WINUTILS_SERVICE_START = 0x00U , QSC_WINUTILS_SERVICE_STOP = 0x01U , QSC_WINUTILS_SERVICE_PAUSE = 0x02U , QSC_WINUTILS_SERVICE_RESUME = 0x03U }
 The service states enumeration. More...
 

Functions

QSC_EXPORT_API size_t qsc_winutils_file_get_attributes (char *result, size_t reslen, const char *path)
 Get a list of file attributes.
 
QSC_EXPORT_API bool qsc_winutils_file_set_attribute (const char *path, const char *attr)
 Set a file attribute. Valid attributes are readonly, hidden, system, archive, normal, temporary, offline, noindex, encrypted.
 
QSC_EXPORT_API size_t qsc_winutils_network_statistics (char *result, size_t reslen)
 Get a list of network statistics seperated by newline characters.
 
QSC_EXPORT_API size_t qsc_winutils_process_list (char *result, size_t reslen)
 Create a list of processes and their descriptions.
 
QSC_EXPORT_API bool qsc_winutils_process_token_elevate (void)
 Elevate the token access.
 
QSC_EXPORT_API bool qsc_winutils_process_terminate (const char *name)
 Terminate a process.
 
QSC_EXPORT_API bool qsc_winutils_registry_key_add (const char *keypath, const char *value, qsc_winutils_registry_value_types vtype)
 Create a registry key and add a value.
 
QSC_EXPORT_API bool qsc_winutils_registry_key_delete (const char *keypath)
 Delete a registry key.
 
QSC_EXPORT_API size_t qsc_winutils_registry_key_list (char *result, size_t reslen, const char *keypath)
 Create a list of registry keys under a starting key, ex. 'HKEY_CURRENT_USER\Software'.
 
QSC_EXPORT_API bool qsc_winutils_run_executable (const char *path)
 Run an application using the executable path.
 
QSC_EXPORT_API bool qsc_winutils_run_as_user (const char *user, const char *password, const char *expath)
 Run an application using the executable name and login credentials.
 
QSC_EXPORT_API size_t qsc_winutils_service_list (char *result, size_t reslen)
 Create a list of running services.
 
QSC_EXPORT_API size_t qsc_winutils_service_list_size (void)
 Get the size of the services list string.
 
QSC_EXPORT_API bool qsc_winutils_service_state (const char *name, qsc_winutils_service_states state)
 Change the running state of a system service.
 
QSC_EXPORT_API size_t qsc_winutils_user_list (char *result, size_t reslen)
 Create a list of system user accounts and their descriptions.
 
QSC_EXPORT_API size_t qsc_winutils_current_user (char *result, size_t reslen)
 Get the logged in user account name.
 
QSC_EXPORT_API void qsc_winutils_test (void)
 Test the winutils functions.
 

Detailed Description

Windows utility functions.

This header defines utility functions for various Windows-specific operations, including file attribute management, process management, registry operations, service management, and executing applications with elevated privileges. The functions provide an abstraction layer over the Windows API, enabling applications to perform common system-level tasks.

// Example: Retrieve file attributes for a given file path.
size_t attr_len = qsc_winutils_file_get_attributes(attributes, QSC_WINTOOLS_ATTRIBUTES_BUFFER_SIZE, "C:\\example.txt");
printf("File attributes: %s\n", attributes);
QSC_EXPORT_API size_t qsc_winutils_file_get_attributes(char *result, size_t reslen, const char *path)
Get a list of file attributes.
#define QSC_WINTOOLS_ATTRIBUTES_BUFFER_SIZE
The file attributes buffer size.
Definition winutils.h:68

Enumeration Type Documentation

◆ qsc_winutils_registry_value_types

The registry value option types.

Enumerator
REG_SZ_TYPE 

String type value

REG_DWORD_TYPE 

Dword type value

REG_QWORD_TYPE 

Qword type value

REG_BINARY_TYPE 

Binary type value

◆ qsc_winutils_service_states

The service states enumeration.

Enumerator
QSC_WINUTILS_SERVICE_START 

Start the service

QSC_WINUTILS_SERVICE_STOP 

Stop the service

QSC_WINUTILS_SERVICE_PAUSE 

Pause the service

QSC_WINUTILS_SERVICE_RESUME 

Resume the service

Function Documentation

◆ qsc_winutils_current_user()

QSC_EXPORT_API size_t qsc_winutils_current_user ( char * result,
size_t reslen )

Get the logged in user account name.

Parameters
result[char*] The result output string
reslen[size_t] The length of the result string
Returns
[size_t] Returns The length of the user string

◆ qsc_winutils_file_get_attributes()

QSC_EXPORT_API size_t qsc_winutils_file_get_attributes ( char * result,
size_t reslen,
const char * path )

Get a list of file attributes.

Parameters
result[char*] The result output string
reslen[size_t] The length of the result string
path[const char*] The file path
Returns
[size_t] Returns The length of the attribute string

◆ qsc_winutils_file_set_attribute()

QSC_EXPORT_API bool qsc_winutils_file_set_attribute ( const char * path,
const char * attr )

Set a file attribute. Valid attributes are readonly, hidden, system, archive, normal, temporary, offline, noindex, encrypted.

Parameters
path[const char*] The file path
attr[const char*] The file attribute
Returns
[bool] Returns true if the attribute was applied

◆ qsc_winutils_network_statistics()

QSC_EXPORT_API size_t qsc_winutils_network_statistics ( char * result,
size_t reslen )

Get a list of network statistics seperated by newline characters.

Parameters
result[char*] The result output string
reslen[size_t] The length of the result string
Returns
[size_t] Returns the size of the result string

◆ qsc_winutils_process_list()

QSC_EXPORT_API size_t qsc_winutils_process_list ( char * result,
size_t reslen )

Create a list of processes and their descriptions.

Parameters
result[char*] The result output string
reslen[size_t] The length of the result string
Returns
[size_t] Returns the length of the process list string

◆ qsc_winutils_process_terminate()

QSC_EXPORT_API bool qsc_winutils_process_terminate ( const char * name)

Terminate a process.

Parameters
name[const char*] The process name
Returns
[bool] Returns true if the process is terminated

◆ qsc_winutils_process_token_elevate()

QSC_EXPORT_API bool qsc_winutils_process_token_elevate ( void )

Elevate the token access.

Returns
[bool] Returns true if successful

◆ qsc_winutils_registry_key_add()

QSC_EXPORT_API bool qsc_winutils_registry_key_add ( const char * keypath,
const char * value,
qsc_winutils_registry_value_types vtype )

Create a registry key and add a value.

Parameters
keypath[const char*] The fully qualified path; root\subkey
value[const char*] The value to add
vtype[qsc_winutils_registry_value_types] The value type
Returns
[bool] Returns true if the key was created

◆ qsc_winutils_registry_key_delete()

QSC_EXPORT_API bool qsc_winutils_registry_key_delete ( const char * keypath)

Delete a registry key.

Parameters
keypath[const char*] The fully qualified path; root\subkey
Returns
[bool] Returns true if the key was deleted

◆ qsc_winutils_registry_key_list()

QSC_EXPORT_API size_t qsc_winutils_registry_key_list ( char * result,
size_t reslen,
const char * keypath )

Create a list of registry keys under a starting key, ex. 'HKEY_CURRENT_USER\Software'.

Parameters
result[char*] The result output string
reslen[size_t] The length of the result string
keypath[const char*] The path of the starting key
Returns
[size_t] Returns the size of the result string

◆ qsc_winutils_run_as_user()

QSC_EXPORT_API bool qsc_winutils_run_as_user ( const char * user,
const char * password,
const char * expath )

Run an application using the executable name and login credentials.

Parameters
user[const char*] The user name
password[const char*] The users password
expath[const char*] The full path to the executable
Returns
[bool] Returns true if the application is started

◆ qsc_winutils_run_executable()

QSC_EXPORT_API bool qsc_winutils_run_executable ( const char * path)

Run an application using the executable path.

Parameters
path[const char*] The executable path and name
Returns
[bool] Returns true if the application is started

◆ qsc_winutils_service_list()

QSC_EXPORT_API size_t qsc_winutils_service_list ( char * result,
size_t reslen )

Create a list of running services.

Parameters
result[char*] The result output string
reslen[size_t] The length of the result string
Returns
[size_t] Returns The length of the services list string

◆ qsc_winutils_service_list_size()

QSC_EXPORT_API size_t qsc_winutils_service_list_size ( void )

Get the size of the services list string.

Returns
[size_t] Returns The length of the services list string

◆ qsc_winutils_service_state()

QSC_EXPORT_API bool qsc_winutils_service_state ( const char * name,
qsc_winutils_service_states state )

Change the running state of a system service.

Parameters
name[const char*] The service name
state[qsc_winutils_service_states] The state enumeration
Returns
[bool] Returns true if the action succeeded

◆ qsc_winutils_user_list()

QSC_EXPORT_API size_t qsc_winutils_user_list ( char * result,
size_t reslen )

Create a list of system user accounts and their descriptions.

Parameters
result[char*] The result output string
reslen[size_t] The length of the result string
Returns
[size_t] Returns The length of the user list string