-
January 17th, 2016, 02:59 AM
#1
InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
I'm trying to implement rebooting of a remote computer with InitiateShutdown API using the following code, but it fails with RPC_S_SERVER_UNAVAILABLE or 1722 error code:
Code:
//Process is running as administrator
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);
//Receive nErrorCode == 1722, or RPC_S_SERVER_UNAVAILABLE
}
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;
}
192.168.42.105 computer has file and printer sharing enabled on the network.
Note that the following shutdown command seems to work just fine to reboot the remote computer:
Code:
shutdown /r /m \\192.168.42.105 /t 30
What am I missing with my code?
-
January 17th, 2016, 03:55 PM
#2
Re: InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
My only question is whether you are coding in C or C++.
-
January 17th, 2016, 04:09 PM
#3
Re: InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
Originally Posted by Arjay
My only question is whether you are coding in C or C++.
It is a C++ VS2008 project. But the code itself can be reduced down to plain C. Why would it matter though?
-
January 18th, 2016, 03:23 PM
#4
Re: InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
Originally Posted by dc_2000
It is a C++ VS2008 project. But the code itself can be reduced down to plain C. Why would it matter though?
It was in reference to another forum post. I should have used a .
-
January 18th, 2016, 05:34 PM
#5
Re: InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
Originally Posted by Arjay
It was in reference to another forum post. I should have used a .
If we run into an issue one of my colleagues may ask the same question in a different location (of his choosing.)
Still back to the point. Any idea about my actual question?
Can anyone at least repro it?
-
January 19th, 2016, 12:50 PM
#6
Re: InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
Originally Posted by dc_2000
If we run into an issue one of my colleagues may ask the same question in a different location (of his choosing.)
Still back to the point. Any idea about my actual question?
Can anyone at least repro it?
Have you looked into the answers on the other forum - it seems to give some idea there? Search bing or google for "InitiateShutdown RPC_S_SERVER_UNAVAILABLE".
-
January 19th, 2016, 03:54 PM
#7
Re: InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
First thing I would try was dropping install updates flag. Second would be specifying some specific reason code instead of the zero.
Best regards,
Igor
-
January 19th, 2016, 11:15 PM
#8
Re: InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
Originally Posted by Arjay
Have you looked into the answers on the other forum - it seems to give some idea there? Search bing or google for "InitiateShutdown RPC_S_SERVER_UNAVAILABLE".
Arjay, are you talking about this one? (That's the first one that comes up for me.) I tried all this. Microsoft's shutdown works fine if I do the following from that same machine:
shutdown /r /m \\192.168.42.105 /t 30
Originally Posted by Igor Vartanov
First thing I would try was dropping install updates flag. Second would be specifying some specific reason code instead of the zero.
Yes, tried it. Dropping SHUTDOWN_INSTALL_UPDATES doesn't change anything, as well as specifying a reason code. I also tried using just "192.168.42.105" without two slashes. Still the same error code RPC_S_SERVER_UNAVAILABLE. Worse still, if I simply use "somebadservername" instead, it also returns RPC_S_SERVER_UNAVAILABLE.
Further exploration.
If I use InitiateSystemShutdown(ex) instead, everything works as expected. The problem with that API is that I can't use SHUTDOWN_INSTALL_UPDATES flag, which is the sole reason why I went with InitiateShutdown.
My colleague put those APIs through a low-level debugger and the problem seems to lie in the way InitiateShutdown makes an RPC call to the server. Are you guys familiar with RPC binding and mostly RPC authentication? Because that's where the root of this error seems to be in.
-
January 20th, 2016, 06:01 AM
#9
Re: InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
Well, natural thing to ask about is if the remote server version is high enough to support the InitiateShutdown API. Did you try that with different server platforms? My guess is W2008 Server is minimal platform to be kicked with InitiateShutdown.
Best regards,
Igor
-
January 20th, 2016, 06:15 AM
#10
Re: InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
Originally Posted by Igor Vartanov
Well, natural thing to ask about is if the remote server version is high enough to support the InitiateShutdown API. Did you try that with different server platforms? My guess is W2008 Server is minimal platform to be kicked with InitiateShutdown.
From MSDN, the minimum supported server is 2008 and the client is Vista (but from previous experience this is not always correct!).
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 20th, 2016, 06:19 AM
#11
Re: InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
Originally Posted by dc_2000
Are you guys familiar with RPC binding and mostly RPC authentication? Because that's where the root of this error seems to be in.
How RPC Works
I believe most of the times what you need to know about RPC authentication is that it exists and works properly. Distributed COM builds on top of RPC, and I never had an issue of unreasonable DCOM call failure.
As for RPC binding, it's the same play with stubs like in COM. Client calls are actually processed by server stubs, and the corresponding APIs get called on behalf of the remote caller. Of course, to be called the remote procedure must exist. That's why I asked about remote Windows server version.
Best regards,
Igor
-
January 20th, 2016, 11:28 AM
#12
Re: InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
Thank you, guys. To answer your questions.
I tried it using the following configuration:
Server Client
------- ---------
Windows Server 2008 R2 --- Windows 7 Professional
Windows 7 Professional --- Windows 7 Professional
They may not have the latest updates installed (both ran in a VM) but would that matter for that API?
Also question to you -- if you substitute my server name with a loopback address and run my code on your system, can you repro this error?
-
January 20th, 2016, 03:17 PM
#13
Re: InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
I've tried this and can confirm that from a Windows 7 computer trying to shut down a Windows 10 computer I get the error code 1722.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 20th, 2016, 04:26 PM
#14
Re: InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
Originally Posted by 2kaud
I've tried this and can confirm that from a Windows 7 computer trying to shut down a Windows 10 computer I get the error code 1722.
Thanks.
So what's the next step in trying to make this work? Any suggestions?
-
January 20th, 2016, 05:32 PM
#15
Re: InitiateShutdown fails for a remote computer with RPC_S_SERVER_UNAVAILABLE error
Originally Posted by dc_2000
Thanks.
So what's the next step in trying to make this work? Any suggestions?
Well, if you are sure that this cmd code
Code:
shutdown /r /m \\192.168.42.105 /t 30
worked then the possible workaround would be just spawn the cmd process with this command line!
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|