@@ -38,19 +38,23 @@ int main(int argc, char *argv[])
3838
3939 NtSuspendProcess pfnNtSuspendProcess = (NtSuspendProcess)GetProcAddress ( GetModuleHandle ( TEXT (" ntdll" ) ), " NtSuspendProcess" );
4040 NtResumeProcess pfnNtResumeProcess = (NtResumeProcess)GetProcAddress ( GetModuleHandle ( TEXT (" ntdll" ) ), " NtResumeProcess" );
41- bool bResume = false ;
42- Qt::CaseSensitivity bCaseSensitivity = Qt::CaseInsensitive ;
41+ bool bResume, bNoOp ;
42+ Qt::CaseSensitivity bCaseSensitivity;
4343 TCHAR szProcessName[MAX_PATH];
4444 _TCHAR* exeName;
4545 DWORD aProcesses[1024 ], cbNeeded, cProcesses, result;
4646 HANDLE hProcess;
4747
4848 // TODO
49+ // help text and description
50+ // pid mode
4951 QCommandLineParser parser;
50- parser.setApplicationDescription (" Test helper" );
51- parser.addHelpOption ();
52+ // parser.setApplicationDescription("Test helper");
53+ // parser.addHelpOption();
5254 parser.addOptions ({
53- // A boolean option with a single name (-p)
55+ {" n" , " no operation" },
56+ {" r" , " resume" },
57+ {" s" , " case sensitive" },
5458 {" p" , " process id" },
5559// // A boolean option with multiple names (-f, --force)
5660// {{"f", "force"},
@@ -60,14 +64,14 @@ int main(int argc, char *argv[])
6064// QCoreApplication::translate("main", "Copy all source files into <directory>."),
6165// QCoreApplication::translate("main", "directory")},
6266 });
67+ // bool parseResult = parser.parse(a.arguments());
68+ parser.process (a);
69+ bResume = parser.isSet (" r" );
70+ bNoOp = parser.isSet (" n" );
71+ bCaseSensitivity = parser.isSet (" s" )? Qt::CaseSensitive : Qt::CaseInsensitive;
72+ // bool bPID = parser.isSet(showProgressOption);
6373
64- QStringList nameList = a.arguments ();
65- nameList.removeFirst ();
66- if ( !nameList.empty () && !nameList.at (0 ).compare (" -r" ) )
67- {
68- nameList.removeFirst ();
69- bResume = true ;
70- }
74+ QStringList nameList = parser.positionalArguments ();
7175
7276
7377 // Get the list of process identifiers.
@@ -142,14 +146,15 @@ int main(int argc, char *argv[])
142146
143147// ****
144148
149+ if (bNoOp)
150+ std::wcout <<" no operation mode" << endl;
145151 if (bResume)
146152 {
147153 std::wcout <<" resumed process(es):" << endl;
148154 }
149155 else
150156 {
151157 std::wcout <<" suspended process(es):" << endl;
152-
153158 }
154159 for (unsigned int i = 0 ; i < cProcesses; i++ )
155160 {
@@ -171,16 +176,21 @@ int main(int argc, char *argv[])
171176 {
172177// qDebug() << nameList << endl;
173178// wcout <<"find" << endl;
174- if (bResume )
179+ if (!bNoOp )
175180 {
176- if (!pfnNtResumeProcess (hProcess))
177- std::wcout << exeName << endl;
181+ if (bResume)
182+ {
183+ if (!pfnNtResumeProcess (hProcess))
184+ std::wcout << exeName << endl;
185+ }
186+ else
187+ {
188+ if (!pfnNtSuspendProcess (hProcess))
189+ std::wcout << exeName << endl;
190+ }
178191 }
179192 else
180- {
181- if (!pfnNtSuspendProcess (hProcess))
182- std::wcout << exeName << endl;
183- }
193+ std::wcout << exeName << endl;
184194 }
185195 }
186196 }
0 commit comments