Función GetApplicationRestartSettings (winbase.h)
Recupera la información de reinicio registrada para el proceso especificado.
Sintaxis
HRESULT GetApplicationRestartSettings(
[in] HANDLE hProcess,
[out, optional] PWSTR pwzCommandline,
[in, out] PDWORD pcchSize,
[out, optional] PDWORD pdwFlags
);
Parámetros
[in] hProcess
Identificador del proceso. Este identificador debe tener el derecho de acceso PROCESS_VM_READ.
[out, optional] pwzCommandline
Puntero a un búfer que recibe la línea de comandos de reinicio especificada por la aplicación cuando llamó a la función RegisterApplicationRestart . El tamaño máximo de la línea de comandos, en caracteres, es RESTART_MAX_CMD_LINE. Puede ser NULL si pcchSize es cero.
[in, out] pcchSize
En la entrada, especifica el tamaño del búfer pwzCommandLine , en caracteres.
Si el búfer no es lo suficientemente grande como para recibir la línea de comandos, se produce un error en la función con HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) y establece este parámetro en el tamaño de búfer necesario, en caracteres.
En la salida, especifica el tamaño del búfer que se usó.
Para determinar el tamaño de búfer necesario, establezca pwzCommandLine en NULL y este parámetro en cero. El tamaño incluye uno para el carácter de terminador null. Tenga en cuenta que la función devuelve S_OK, no HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) en este caso.
[out, optional] pdwFlags
Puntero a una variable que recibe las marcas especificadas por la aplicación cuando llamó a la función RegisterApplicationRestart .
Valor devuelto
Esta función devuelve S_OK si se ejecuta correctamente o uno de los siguientes códigos de error.
Código devuelto | Descripción |
---|---|
|
Uno o más parámetros no son válidos. |
|
La aplicación no se registró para el reinicio. |
|
El búfer pwzCommandLine es demasiado pequeño. La función devuelve el tamaño de búfer necesario en pcchSize. Use el tamaño necesario para reasignar el búfer. |
Comentarios
Esta información solo está disponible para el proceso actual; No puede llamar a esta función después de reiniciar el programa para obtener la línea de comandos de reinicio. Para obtener la línea de comandos después de un reinicio, acceda al parámetro argv de la función principal .
Ejemplos
En el ejemplo siguiente se muestra cómo obtener la configuración de reinicio especificada al llamar a la función RegisterApplicationRestart .
#include <windows.h>
#include <stdio.h>
void wmain(int argc, WCHAR* argv[])
{
HRESULT hr = S_OK;
WCHAR wsCommandLine[RESTART_MAX_CMD_LINE + 1];
DWORD cchCmdLine = sizeof(wsCommandLine) / sizeof(WCHAR);
DWORD dwFlags = 0;
LPWSTR pwsCmdLine = NULL;
UNREFERENCED_PARAMETER(argv);
UNREFERENCED_PARAMETER(argc);
wprintf(L"Registering for restart...\n");
hr = RegisterApplicationRestart(L"/restart -f .\\filename.ext", 0);
if (FAILED(hr))
{
wprintf(L"RegisterApplicationRestart failed, 0x%x\n", hr);
goto cleanup;
}
wprintf(L"Get restart command line using static buffer...\n");
hr = GetApplicationRestartSettings(GetCurrentProcess(), wsCommandLine, &cchCmdLine, &dwFlags);
if (FAILED(hr))
{
wprintf(L"GetApplicationRestartSettings failed, 0x%x\n", hr);
goto cleanup;
}
wprintf(L"Command line: %s\n", wsCommandLine);
wprintf(L"\nGet settings using dynamic buffer...\n");
cchCmdLine = 0;
// Returns S_OK instead of ERROR_INSUFFICIENT_BUFFER when pBuffer is NULL and size is 0.
hr = GetApplicationRestartSettings(GetCurrentProcess(), (PWSTR)pwsCmdLine, &cchCmdLine, &dwFlags);
if (SUCCEEDED(hr))
{
pwsCmdLine = (LPWSTR)malloc(cchCmdLine * sizeof(WCHAR));
if (pwsCmdLine)
{
hr = GetApplicationRestartSettings(GetCurrentProcess(), (PWSTR)pwsCmdLine, &cchCmdLine, &dwFlags);
if (FAILED(hr))
{
wprintf(L"GetApplicationRestartSettings failed with 0x%x\n", hr);
goto cleanup;
}
wprintf(L"Command line: %s\n", pwsCmdLine);
}
else
{
wprintf(L"Allocating the command-line buffer failed.\n");
}
}
else
{
if (hr != HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) // Not a restart.
{
wprintf(L"GetApplicationRestartSettings failed with 0x%x\n", hr);
goto cleanup;
}
}
cleanup:
if (pwsCmdLine)
free(pwsCmdLine);
}
Requisitos
Cliente mínimo compatible | Windows Vista [solo aplicaciones de escritorio] |
Servidor mínimo compatible | Windows Server 2008 [solo aplicaciones de escritorio] |
Plataforma de destino | Windows |
Encabezado | winbase.h (incluye Windows.h) |
Library | Kernel32.lib |
Archivo DLL | Kernel32.dll |