// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS) return FALSE;
// Display the shutdown dialog box and start the countdown.
fResult = InitiateSystemShutdown( NULL, // shut down local computer NULL, // message for user 5, // time-out period FALSE, // ask user to close apps FALSE); // reboot after shutdown
// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS) return FALSE;
// Display the shutdown dialog box and start the countdown.
fResult = InitiateSystemShutdown( NULL, // shut down local computer NULL, // message for user 5, // time-out period FALSE, // ask user to close apps TRUE); // reboot after shutdown
你的意思是把String 转成char
而char就可以被LPWSTR所用
//#include "Winbase.h"
#include "Windows.h"
#include <iostream>
#include "jni.h"
#include "reconserver_SystemDll.h"
JNIEXPORT jboolean JNICALL Java_reconserver_SystemDll_newprocess(JNIEnv *, jobject, jstring str){
STARTUPINFO si;
PROCESS_INFORMATION pi;
char* message;
message=(char*)(*env)->GetStringUTFChars(env, str, NULL); //改了这里 ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) ); // Start the child process.
if( !CreateProcess( NULL, // No module name (use command line).
message, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure.
)
{
return false;
}
//cout<<π
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return true;
}
JNIEXPORT jboolean JNICALL Java_reconserver_SystemDll_killprocess(JNIEnv *, jobject, jint id){HANDLE hProcessSnap = NULL;
BOOL bRet = FALSE;
int pid=id;
hProcessSnap=OpenProcess(PROCESS_ALL_ACCESS,false,pid);
bRet=TerminateProcess(hProcessSnap,1);
return bRet;
}
JNIEXPORT jboolean JNICALL Java_reconserver_SystemDll_poweroff(JNIEnv *, jobject){
HANDLE hToken; // handle to process token
TOKEN_PRIVILEGES tkp; // pointer to token structure
BOOL fResult; // system shutdown flag
// Get the current process token handle so we can get shutdown
// privilege.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return FALSE;
// Get the LUID for shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
return FALSE;
// Display the shutdown dialog box and start the countdown.
fResult = InitiateSystemShutdown(
NULL, // shut down local computer
NULL, // message for user
5, // time-out period
FALSE, // ask user to close apps
FALSE); // reboot after shutdown
if (!fResult)
return FALSE;
// Disable shutdown privilege.
tkp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
return TRUE;
}JNIEXPORT jboolean JNICALL Java_reconserver_SystemDll_restart(JNIEnv *, jobject){
HANDLE hToken; // handle to process token
TOKEN_PRIVILEGES tkp; // pointer to token structure
BOOL fResult; // system shutdown flag
// Get the current process token handle so we can get shutdown
// privilege.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return FALSE;
// Get the LUID for shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
return FALSE;
// Display the shutdown dialog box and start the countdown.
fResult = InitiateSystemShutdown(
NULL, // shut down local computer
NULL, // message for user
5, // time-out period
FALSE, // ask user to close apps
TRUE); // reboot after shutdown
if (!fResult)
return FALSE;
// Disable shutdown privilege.
tkp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
return TRUE;
}
void main(int argc, char *argv[])
{}