How do I redirect output of my console using PsExec?
-
I'm using a remote execution tool called 'PsExec' from sysinternals. I use it this way in my command prompt : D:\Tools\Testing>psexec netsh firewall show opmode>D:\Log.txt This generates the output for 'netsh firewall show opmode' and redirects to D:\Log.txt Now, I implement the same logic/code in my application like this :
CString csCmdLineParams = "netsh firewall show opmode>D:\\TestdwLog.txt";
STARTUPINFO StartUpInfo;
PROCESS_INFORMATION ProcInfo;DWORD ExitCode = -1;
memset(&StartUpInfo, 0, sizeof(StartUpInfo));
memset(&ProcInfo, 0, sizeof(ProcInfo));
StartUpInfo.dwFlags = STARTF_USESHOWWINDOW;
StartUpInfo.wShowWindow = SW_SHOW;
CreateProcess( "C:\\windows\\system32\\cmd.exe", csCmdLineParams.GetBuffer(csCmdLineParams.GetLength() + ONE), NULL, NULL, NULL, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &StartUpInfo, &ProcInfo);
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcInfo.hProcess, &ExitCode );
if (ExitCode) {
csCmdLineParams.ReleaseBuffer();
CloseHandle(ProcInfo.hProcess);
}csCmdLineParams.ReleaseBuffer();
CloseHandle(ProcInfo.hProcess);
But, I'm not able to redirect the output to D:\TestdwLog.txt. In fact the file is not created itself. Note : I do have administrator rights for my system. [required for PsExec] What am I doing wrongly ? I also tried StartUpInfo_IDI.dwFlags = STARTF_USESTDHANDLES; instead of StartUpInfo.dwFlags = STARTF_USESHOWWINDOW; Replies would be appreciated Thanks in advance.
-
I'm using a remote execution tool called 'PsExec' from sysinternals. I use it this way in my command prompt : D:\Tools\Testing>psexec netsh firewall show opmode>D:\Log.txt This generates the output for 'netsh firewall show opmode' and redirects to D:\Log.txt Now, I implement the same logic/code in my application like this :
CString csCmdLineParams = "netsh firewall show opmode>D:\\TestdwLog.txt";
STARTUPINFO StartUpInfo;
PROCESS_INFORMATION ProcInfo;DWORD ExitCode = -1;
memset(&StartUpInfo, 0, sizeof(StartUpInfo));
memset(&ProcInfo, 0, sizeof(ProcInfo));
StartUpInfo.dwFlags = STARTF_USESHOWWINDOW;
StartUpInfo.wShowWindow = SW_SHOW;
CreateProcess( "C:\\windows\\system32\\cmd.exe", csCmdLineParams.GetBuffer(csCmdLineParams.GetLength() + ONE), NULL, NULL, NULL, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &StartUpInfo, &ProcInfo);
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcInfo.hProcess, &ExitCode );
if (ExitCode) {
csCmdLineParams.ReleaseBuffer();
CloseHandle(ProcInfo.hProcess);
}csCmdLineParams.ReleaseBuffer();
CloseHandle(ProcInfo.hProcess);
But, I'm not able to redirect the output to D:\TestdwLog.txt. In fact the file is not created itself. Note : I do have administrator rights for my system. [required for PsExec] What am I doing wrongly ? I also tried StartUpInfo_IDI.dwFlags = STARTF_USESTDHANDLES; instead of StartUpInfo.dwFlags = STARTF_USESHOWWINDOW; Replies would be appreciated Thanks in advance.
Im pretty sure you'll get mileage out of the following links - the 3rd link is for VB, but illustrates an alternate technique - ymmv http://www.codeproject.com/KB/threads/RTconsole.aspx[^] http://www.codeproject.com/KB/threads/redir.aspx[^] http://www.devx.com/vb2themax/Article/19825/1954[^] Im pretty sure search on CP or google would have found these for you..
-
I'm using a remote execution tool called 'PsExec' from sysinternals. I use it this way in my command prompt : D:\Tools\Testing>psexec netsh firewall show opmode>D:\Log.txt This generates the output for 'netsh firewall show opmode' and redirects to D:\Log.txt Now, I implement the same logic/code in my application like this :
CString csCmdLineParams = "netsh firewall show opmode>D:\\TestdwLog.txt";
STARTUPINFO StartUpInfo;
PROCESS_INFORMATION ProcInfo;DWORD ExitCode = -1;
memset(&StartUpInfo, 0, sizeof(StartUpInfo));
memset(&ProcInfo, 0, sizeof(ProcInfo));
StartUpInfo.dwFlags = STARTF_USESHOWWINDOW;
StartUpInfo.wShowWindow = SW_SHOW;
CreateProcess( "C:\\windows\\system32\\cmd.exe", csCmdLineParams.GetBuffer(csCmdLineParams.GetLength() + ONE), NULL, NULL, NULL, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &StartUpInfo, &ProcInfo);
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcInfo.hProcess, &ExitCode );
if (ExitCode) {
csCmdLineParams.ReleaseBuffer();
CloseHandle(ProcInfo.hProcess);
}csCmdLineParams.ReleaseBuffer();
CloseHandle(ProcInfo.hProcess);
But, I'm not able to redirect the output to D:\TestdwLog.txt. In fact the file is not created itself. Note : I do have administrator rights for my system. [required for PsExec] What am I doing wrongly ? I also tried StartUpInfo_IDI.dwFlags = STARTF_USESTDHANDLES; instead of StartUpInfo.dwFlags = STARTF_USESHOWWINDOW; Replies would be appreciated Thanks in advance.
Put psexec netsh firewall show opmode>D:\Log.txt in a batch file, and run the batch file from
CreateProcess()
."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Put psexec netsh firewall show opmode>D:\Log.txt in a batch file, and run the batch file from
CreateProcess()
."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons