From: Allan Bruce on
Is there a way I can remotely reboot one of my machines? I have setup a TV
server but occasionally the software serving the TV crashes and I would like
to remotely reboot the machine. I could have remote desktop access to
another machine on the network but would prefer to run apache and use it to
remotely reboot.

Thanks
Allan


From: Kellie Fitton on
Hello,

Well, you should use the win32 API InitiateSystemShutdownEx()
function,
simply because, it works great locally and remotely as well.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/initiatesystemshutdownex.asp


Hope these information helps.

Kellie.

From: Allan Bruce on

"Kellie Fitton" <KELLIEFITTON(a)YAHOO.COM> wrote in message
news:1120014495.597965.211780(a)g47g2000cwa.googlegroups.com...
> Hello,
>
> Well, you should use the win32 API InitiateSystemShutdownEx()
> function,
> simply because, it works great locally and remotely as well.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/initiatesystemshutdownex.asp
>
>
> Hope these information helps.
>
> Kellie.
>

Excellent, this looks like it will do the trick. Is there a way to
Enumerate the windows machine names visible on the network? I will make a
more general utility to shutdown/reboot any machine on the network.

Thanks.
Allan


From: Allan Bruce on

"Kellie Fitton" <KELLIEFITTON(a)YAHOO.COM> wrote in message
news:1120014495.597965.211780(a)g47g2000cwa.googlegroups.com...
> Hello,
>
> Well, you should use the win32 API InitiateSystemShutdownEx()
> function,
> simply because, it works great locally and remotely as well.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/initiatesystemshutdownex.asp
>
>
> Hope these information helps.
>
> Kellie.
>

Hmm, I keep getting error 5 (ERROR_ACCESS_DENIED) from InitiateShutdownEx().
My code is below. I am logged in as a user with administrator priveleges.
Do you know what I need to do to get this working?

Thanks,
Allan


int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
bool lSuccess = false;

while (!lSuccess)
{
if (DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_MAINDLG), NULL,
(DLGPROC)GetDetails) == CANCELLED)
return EXIT_FAILURE;

// get the privelege for shutting down
HANDLE lHToken;
TOKEN_PRIVILEGES lTKP;

// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES |
TOKEN_QUERY, &lHToken))
return EXIT_FAILURE;

// Get the LUID for the shutdown privilege.
if (LookupPrivilegeValue(NULL, SE_REMOTE_SHUTDOWN_NAME,
&lTKP.Privileges[0].Luid) == 0)
{
DWORD d=GetLastError();
DWORD a= d;
}

lTKP.PrivilegeCount = 1; // one privilege to set
lTKP.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

// Get the shutdown privilege for this process.
AdjustTokenPrivileges(lHToken, false, &lTKP, 0, (PTOKEN_PRIVILEGES)NULL,
0);

if (GetLastError() != ERROR_SUCCESS)
return EXIT_FAILURE;

DWORD lReason = SHTDN_REASON_MAJOR_SOFTWARE;
if (InitiateSystemShutdownEx(gMachineName, gReason, gTimeout, gForce,
gReboot, lReason))
{
lSuccess = true;
MessageBox(NULL, "Shutdown Initiation Successful", "Success",
MB_ICONINFORMATION);
}
else
{
DWORD d = GetLastError();
}

// take away shutdown priveledges
lTKP.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(lHToken, false, &lTKP, 0, (PTOKEN_PRIVILEGES)NULL,
0);
}

return lSuccess?EXIT_SUCCESS:EXIT_FAILURE;
}


From: #2pencil on
> Is there a way to Enumerate the windows machine names visible on the
> network? I will make a more general utility to shutdown/reboot any machine > on the network.

Make your network a domain. Or don't use dhcp & then you'll have a
solid ip list of each machine.

-#2pencil-