| View previous topic :: View next topic |
| Author |
Message |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sun Sep 28, 2008 8:10 am Post subject: [C]Shutting Down Other Computer ? |
|
|
I'm using InitiateSystemShutdown to shutdown a computer that is connected to the same network as me, but it fails, why ?
my code is: //i did not code the EnablePriv() block
| Code: | #include <windows.h>
#include <stdio.h>
BOOL asdf(LPWSTR lpMachineName, LPWSTR lpMessage)
{
return InitiateSystemShutdown(lpMachineName, lpMessage, 5, TRUE, FALSE);
}
BOOL EnablePriv(LPCSTR lpszPriv) // by Napalm
{
HANDLE hToken;
LUID luid;
TOKEN_PRIVILEGES tkprivs;
RtlZeroMemory(&tkprivs, sizeof(tkprivs));
if(!OpenProcessToken(GetCurrentProcess(), (TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY), &hToken))
return FALSE;
if(!LookupPrivilegeValueA(NULL, lpszPriv, &luid)){
CloseHandle(hToken); return FALSE;
}
tkprivs.PrivilegeCount = 1;
tkprivs.Privileges[0].Luid = luid;
tkprivs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
BOOL bRet = AdjustTokenPrivileges(hToken, FALSE, &tkprivs, sizeof(tkprivs), NULL, NULL);
CloseHandle(hToken);
return bRet;
}
void main(void)
{
switch(EnablePriv("SeShutdownPrivilege")) //AAA
{
case TRUE:printf("Sccuess\n");break;
case FALSE:printf("Failed\n");break;
}
switch(asdf(L"192.168.123.156", L"Test")) //LAN
{
case TRUE:printf("Sccuess\n");break;
case FALSE:printf("Failed\n");break;
}
return;
} |
I get:
Success
Failed |
|
| Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Sun Sep 28, 2008 11:40 am Post subject: |
|
|
Because your asdf function is returning the InitiateSystemShutdown rather than a bool value. You're checking to see whether it returns true or false, and it doesn't return either. _________________
Blog
| Quote: | Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that |
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sun Sep 28, 2008 12:07 pm Post subject: |
|
|
| Overload wrote: | | Because your asdf function is returning the InitiateSystemShutdown rather than a bool value. You're checking to see whether it returns true or false, and it doesn't return either. |
Ahahaha... nice catch, now i'll fix it, but still, doesn't work :S. |
|
| Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Sun Sep 28, 2008 1:37 pm Post subject: |
|
|
The parameter for your function should be an LPCTSTR not LPCSTR _________________
Blog
| Quote: | Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that |
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sun Sep 28, 2008 2:58 pm Post subject: |
|
|
| Overload wrote: | | The parameter for your function should be an LPCTSTR not LPCSTR |
Which one ? EnablePriv ? |
|
| Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Sun Sep 28, 2008 4:05 pm Post subject: |
|
|
| Rot1 wrote: | | Overload wrote: | | The parameter for your function should be an LPCTSTR not LPCSTR |
Which one ? EnablePriv ? |
Yes. Right now you have it as LPCSTR. Change it to LPCTSTR _________________
Blog
| Quote: | Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that |
|
|
| Back to top |
|
 |
|