#include <advapi32.h>
-#include <ndk/exfuncs.h>
-
WINE_DEFAULT_DEBUG_CHANNEL(advapi);
-/**********************************************************************
- * AbortSystemShutdownW
- *
- * @unimplemented
- */
-BOOL WINAPI
-AbortSystemShutdownW(LPCWSTR lpMachineName)
-{
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return FALSE;
-}
-
-
/**********************************************************************
* AbortSystemShutdownA
*
return rv;
}
+
/**********************************************************************
- * InitiateSystemShutdownW
+ * AbortSystemShutdownW
*
* @implemented
*/
BOOL WINAPI
-InitiateSystemShutdownW(LPWSTR lpMachineName,
- LPWSTR lpMessage,
- DWORD dwTimeout,
- BOOL bForceAppsClosed,
- BOOL bRebootAfterShutdown)
+AbortSystemShutdownW(LPCWSTR lpMachineName)
{
- return InitiateSystemShutdownExW(lpMachineName,
- lpMessage,
- dwTimeout,
- bForceAppsClosed,
- bRebootAfterShutdown,
- SHTDN_REASON_MAJOR_OTHER |
- SHTDN_REASON_MINOR_OTHER |
- SHTDN_REASON_FLAG_PLANNED
- /* SHTDN_REASON_MAJOR_LEGACY_API */);
+ DWORD dwError;
+
+ RpcTryExcept
+ {
+ dwError = BaseAbortSystemShutdown((PREGISTRY_SERVER_NAME)lpMachineName);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ dwError = RtlNtStatusToDosError(RpcExceptionCode());
+ }
+ RpcEndExcept;
+
+ if (dwError != ERROR_SUCCESS)
+ {
+ TRACE("BaseAbortSystemShutdown() failed (Error %lu)\n", dwError);
+ SetLastError(dwError);
+ return FALSE;
+ }
+
+ return TRUE;
}
+
/**********************************************************************
* InitiateSystemShutdownA
*
BOOL bForceAppsClosed,
BOOL bRebootAfterShutdown)
{
- return InitiateSystemShutdownExA(lpMachineName,
- lpMessage,
- dwTimeout,
- bForceAppsClosed,
- bRebootAfterShutdown,
- SHTDN_REASON_MAJOR_OTHER |
- SHTDN_REASON_MINOR_OTHER |
- SHTDN_REASON_FLAG_PLANNED
- /* SHTDN_REASON_MAJOR_LEGACY_API */);
+ ANSI_STRING MachineNameA, MessageA;
+ UNICODE_STRING MachineNameW, MessageW;
+ NTSTATUS Status;
+ BOOL res;
+
+ MachineNameW.Buffer = NULL;
+ MessageW.Buffer = NULL;
+
+ if (lpMachineName)
+ {
+ RtlInitAnsiString(&MachineNameA, lpMachineName);
+ Status = RtlAnsiStringToUnicodeString(&MachineNameW, &MachineNameA, TRUE);
+ if (STATUS_SUCCESS != Status)
+ {
+ if(MachineNameW.Buffer)
+ RtlFreeUnicodeString(&MachineNameW);
+
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
+ }
+ }
+
+ if (lpMessage)
+ {
+ RtlInitAnsiString(&MessageA, lpMessage);
+ Status = RtlAnsiStringToUnicodeString(&MessageW, &MessageA, TRUE);
+ if (STATUS_SUCCESS != Status)
+ {
+ if (MessageW.Buffer)
+ RtlFreeUnicodeString(&MessageW);
+
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
+ }
+ }
+
+ res = InitiateSystemShutdownW(MachineNameW.Buffer,
+ MessageW.Buffer,
+ dwTimeout,
+ bForceAppsClosed,
+ bRebootAfterShutdown);
+
+ /* Clear the values of both strings */
+ if (lpMachineName)
+ RtlFreeUnicodeString(&MachineNameW);
+
+ if (lpMessage)
+ RtlFreeUnicodeString(&MessageW);
+
+ return res;
}
-/******************************************************************************
- * InitiateSystemShutdownExW [ADVAPI32.@]
+
+/**********************************************************************
+ * InitiateSystemShutdownW
*
- * @unimplemented
+ * @implemented
*/
BOOL WINAPI
-InitiateSystemShutdownExW(LPWSTR lpMachineName,
- LPWSTR lpMessage,
- DWORD dwTimeout,
- BOOL bForceAppsClosed,
- BOOL bRebootAfterShutdown,
- DWORD dwReason)
+InitiateSystemShutdownW(LPWSTR lpMachineName,
+ LPWSTR lpMessage,
+ DWORD dwTimeout,
+ BOOL bForceAppsClosed,
+ BOOL bRebootAfterShutdown)
{
- SHUTDOWN_ACTION action;
- NTSTATUS Status;
- ULONG Timeout_ms;
+ UNICODE_STRING Message;
+ DWORD dwError;
- /* Convert to milliseconds so we can use the value later on */
- Timeout_ms = dwTimeout * 1000;
+ RtlInitUnicodeString(&Message, lpMessage);
- if (lpMachineName != NULL)
+ RpcTryExcept
{
- /* FIXME: Remote system shutdown not supported yet */
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return FALSE;
+ dwError = BaseInitiateSystemShutdown((PREGISTRY_SERVER_NAME)lpMachineName,
+ (PRPC_UNICODE_STRING)&Message,
+ dwTimeout,
+ bForceAppsClosed,
+ bRebootAfterShutdown);
}
- else /* The local system is being used */
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
{
- /* FIXME: Right now, only basic shutting down and rebooting
- is supported */
- if(bRebootAfterShutdown == TRUE)
- {
- action = ShutdownReboot;
- }
- else
- {
- action = ShutdownNoReboot;
- }
+ dwError = RtlNtStatusToDosError(RpcExceptionCode());
+ }
+ RpcEndExcept;
- Status = NtShutdownSystem(action);
+ if (dwError != ERROR_SUCCESS)
+ {
+ TRACE("BaseInitiateSystemShutdown() failed (Error %lu)\n", dwError);
+ SetLastError(dwError);
+ return FALSE;
}
- SetLastError(RtlNtStatusToDosError(Status));
- return (Status == STATUS_SUCCESS);
+ return TRUE;
}
+
/******************************************************************************
* InitiateSystemShutdownExA [ADVAPI32.@]
*
ANSI_STRING MachineNameA, MessageA;
UNICODE_STRING MachineNameW, MessageW;
NTSTATUS Status;
- INT LastError;
- BOOL rv;
+ BOOL res;
MachineNameW.Buffer = NULL;
MessageW.Buffer = NULL;
}
}
- rv = InitiateSystemShutdownExW(MachineNameW.Buffer,
- MessageW.Buffer,
- dwTimeout,
- bForceAppsClosed,
- bRebootAfterShutdown,
- dwReason);
- LastError = GetLastError();
+ res = InitiateSystemShutdownExW(MachineNameW.Buffer,
+ MessageW.Buffer,
+ dwTimeout,
+ bForceAppsClosed,
+ bRebootAfterShutdown,
+ dwReason);
/* Clear the values of both strings */
if (lpMachineName)
if (lpMessage)
RtlFreeUnicodeString(&MessageW);
- SetLastError(LastError);
- return rv;
+ return res;
+}
+
+
+/******************************************************************************
+ * InitiateSystemShutdownExW [ADVAPI32.@]
+ *
+ * @unimplemented
+ */
+BOOL WINAPI
+InitiateSystemShutdownExW(LPWSTR lpMachineName,
+ LPWSTR lpMessage,
+ DWORD dwTimeout,
+ BOOL bForceAppsClosed,
+ BOOL bRebootAfterShutdown,
+ DWORD dwReason)
+{
+ UNICODE_STRING Message;
+ DWORD dwError;
+
+ RtlInitUnicodeString(&Message, lpMessage);
+
+ RpcTryExcept
+ {
+ dwError = BaseInitiateSystemShutdownEx((PREGISTRY_SERVER_NAME)lpMachineName,
+ (PRPC_UNICODE_STRING)&Message,
+ dwTimeout,
+ bForceAppsClosed,
+ bRebootAfterShutdown,
+ dwReason);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ dwError = RpcExceptionCode();
+ }
+ RpcEndExcept;
+
+ if (dwError != ERROR_SUCCESS)
+ {
+ TRACE("BaseInitiateSystemShutdownEx() failed (Error %lu)\n", dwError);
+ SetLastError(dwError);
+ return FALSE;
+ }
+
+ return TRUE;
}
+
/******************************************************************************
* InitiateShutdownW [ADVAPI32.@]
- *
- * @unimplamented
+ *
+ * @unimplemented
*/
DWORD WINAPI
InitiateShutdownW(LPWSTR lpMachineName,
/******************************************************************************
* InitiateShutdownA [ADVAPI32.@]
- *
+ *
* see InitiateShutdownW
*/
DWORD WINAPI