I am trying to reboot a remote computer using the InitiateShutdown API using the following code, but with an error RPC_S_SERVER_UNAVAILABLEor error 1722code:
LPCTSTR pServerName = L"192.168.42.105";
if(AdjustPrivilege(NULL, L"SeShutdownPrivilege", TRUE) &&
AdjustPrivilege(pServerName, L"SeRemoteShutdownPrivilege", TRUE))
{
int nErrorCode = ::InitiateShutdown(pServerName, NULL, 30,
SHUTDOWN_INSTALL_UPDATES | SHUTDOWN_RESTART, 0);
}
BOOL AdjustPrivilege(LPCTSTR pStrMachine, LPCTSTR pPrivilegeName, BOOL bEnable)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
BOOL bRes = FALSE;
if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return FALSE;
if(LookupPrivilegeValue(pStrMachine, pPrivilegeName, &tkp.Privileges[0].Luid))
{
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = bEnable ? SE_PRIVILEGE_ENABLED : SE_PRIVILEGE_REMOVED;
bRes = AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
int nOSError = GetLastError();
if(bRes)
{
if(nOSError != ERROR_SUCCESS)
bRes = FALSE;
}
}
CloseHandle(hToken);
return bRes;
}
So, in order to prepare for the execution of this code, I do the following on a computer thisthat is equal Windows 7 Pro(as I would do for Microsoft shutdown ):
- Run the "administrator" to allow SMB access to the registered user
D1on the computer 192.168.42.105(for this answer ):
NET USE \\192.168.42.105\IPC$ 1234 /USER:D1
- Run the process with my code above "as administrator".
192.168.42.105, Windows 7 Pro ( )
, ,
"Private" " "
:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
LocalAccountTokenFilterPolicy = DWORD: 1
RUN secpol.msc, " ", " ", " ", " ". "Everyone" "Force shutdown from remote system". ( !)
, shutdown , :
shutdown /r /m \\192.168.42.105 /t 30
?
EDIT:
OK. , , InitiateShutdown "" , InitiateSystemShutdownEx InitiateSystemShutdown . ( , dwShutdownFlags, SHUTDOWN_INSTALL_UPDATES, ...)
, WinDbg... , , ...
(A) , InitiateSystemShutdownEx RPC-. RPC RpcStringBindingComposeW, :
ObjUuid = NULL
ProtSeq = ncacn_np
NetworkAddr = \\192.168.42.105
EndPoint = \\PIPE\\InitShutdown
Options = NULL
:
ncacn_np:\\\\192.168.42.105[\\PIPE\\InitShutdown]
(B) InitiateShutdown :
ObjUuid = 765294ba-60bc-48b8-92e9-89fd77769d91
ProtSeq = ncacn_ip_tcp
NetworkAddr = 192.168.42.105
EndPoint = NULL
Options = NULL
:
ncacn_np:\\\\192.168.42.105[\\PIPE\\lsarpc]
RPC, WsdrInitiateShutdown (, , ):

, , InitiateShutdown Unknown RPC service ( UUID {765294ba-60bc-48b8-92e9-89fd77769d91}), :

, , , :)
, "Local Security Authority" ( t226 > named pipe). , - , , RPC , , , ?