| 2901 | |
| 2902 | |
| 2903 | ResultType Line::ScriptProcess(char *aCmd, char *aProcess, char *aParam3) |
| 2904 | { |
| 2905 | ProcessCmds process_cmd = ConvertProcessCmd(aCmd); |
| 2906 | // Runtime error is rare since it is caught at load-time unless it's in a var. ref. |
| 2907 | if (process_cmd == PROCESS_CMD_INVALID) |
| 2908 | return LineError(ERR_PROCESSCOMMAND ERR_ABORT, FAIL, aCmd); |
| 2909 | |
| 2910 | HANDLE hProcess; |
| 2911 | DWORD pid, priority; |
| 2912 | BOOL result; |
| 2913 | |
| 2914 | switch (process_cmd) |
| 2915 | { |
| 2916 | case PROCESS_CMD_EXIST: |
| 2917 | return g_ErrorLevel->Assign(ProcessExist(aProcess)); // The discovered PID or zero if none. |
| 2918 | |
| 2919 | case PROCESS_CMD_CLOSE: |
| 2920 | if (pid = ProcessExist(aProcess)) // Assign |
| 2921 | { |
| 2922 | if (hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid)) |
| 2923 | { |
| 2924 | result = TerminateProcess(hProcess, 0); |
| 2925 | CloseHandle(hProcess); |
| 2926 | return g_ErrorLevel->Assign(result ? pid : 0); // Indicate success or failure. |
| 2927 | } |
| 2928 | } |
| 2929 | // Otherwise, return a PID of 0 to indicate failure. |
| 2930 | return g_ErrorLevel->Assign("0"); |
| 2931 | |
| 2932 | case PROCESS_CMD_PRIORITY: |
| 2933 | switch (toupper(*aParam3)) |
| 2934 | { |
| 2935 | case 'L': priority = IDLE_PRIORITY_CLASS; break; |
| 2936 | case 'B': priority = BELOW_NORMAL_PRIORITY_CLASS; break; |
| 2937 | case 'N': priority = NORMAL_PRIORITY_CLASS; break; |
| 2938 | case 'A': priority = ABOVE_NORMAL_PRIORITY_CLASS; break; |
| 2939 | case 'H': priority = HIGH_PRIORITY_CLASS; break; |
| 2940 | case 'R': priority = REALTIME_PRIORITY_CLASS; break; |
| 2941 | default: |
| 2942 | return g_ErrorLevel->Assign("0"); // 0 indicates failure in this case (i.e. a PID of zero). |
| 2943 | } |
| 2944 | if (pid = *aProcess ? ProcessExist(aProcess) : GetCurrentProcessId()) // Assign |
| 2945 | { |
| 2946 | if (hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, pid)) // Assign |
| 2947 | { |
| 2948 | // If OS doesn't support "above/below normal", seems best to default to normal rather than high/low, |
| 2949 | // since "above/below normal" aren't that dramatically different from normal: |
| 2950 | if (!g_os.IsWin2000orLater() && (priority == BELOW_NORMAL_PRIORITY_CLASS || priority == ABOVE_NORMAL_PRIORITY_CLASS)) |
| 2951 | priority = NORMAL_PRIORITY_CLASS; |
| 2952 | result = SetPriorityClass(hProcess, priority); |
| 2953 | CloseHandle(hProcess); |
| 2954 | return g_ErrorLevel->Assign(result ? pid : 0); // Indicate success or failure. |
| 2955 | } |
| 2956 | } |
| 2957 | // Otherwise, return a PID of 0 to indicate failure. |
| 2958 | return g_ErrorLevel->Assign("0"); |
| 2959 | |
| 2960 | case PROCESS_CMD_WAIT: |
nothing calls this directly
no test coverage detected