Wrong icacls command not giving any error on being called by CreateProcessW function
I am trying to call the CreateProcessW() function to call dos command icacls in my C++ code . However this CreateProcessW() is not responding correctly to icacls command . I can say this because for negative testing i passed wrong icacls command to CreateProcessW() function an it just didnt throw any error.
However same command was failing in command prompt
I am attaching the code here
#include <vector>
#include <algorithm>
#include <atomic>
#include <memory>
#include <type_traits>
#include <Windows.h>
#include <iostream>
#include <string>
int main()
{
std::wstring command_line(L"icacls XXXCCCCC");//throws error with command prompt
STARTUPINFOW startup_info;
PROCESS_INFORMATION process_info;
size_t len(command_line.size());
std::vector<wchar_t> buff(len + 1);
std::copy(command_line.begin(), command_line.end(), buff.begin());
buff[len] = 0;
GetStartupInfoW(&startup_info);
BOOL result(CreateProcessW(nullptr, &buff[0], 0, 0, false, CREATE_NO_WINDOW, 0, 0,
&startup_info, &process_info));
if (!result)
{
std::cout << "FAIL" << std::endl;
std::wcout << " command line: <" << command_line << ">" << std::endl;
}
else
{
std::cout << "PASS" << std::endl;
std::wcout << " command line: <" << command_line << ">" << std::endl;
}
return 0;
}
c++ window createprocess
add a comment |
I am trying to call the CreateProcessW() function to call dos command icacls in my C++ code . However this CreateProcessW() is not responding correctly to icacls command . I can say this because for negative testing i passed wrong icacls command to CreateProcessW() function an it just didnt throw any error.
However same command was failing in command prompt
I am attaching the code here
#include <vector>
#include <algorithm>
#include <atomic>
#include <memory>
#include <type_traits>
#include <Windows.h>
#include <iostream>
#include <string>
int main()
{
std::wstring command_line(L"icacls XXXCCCCC");//throws error with command prompt
STARTUPINFOW startup_info;
PROCESS_INFORMATION process_info;
size_t len(command_line.size());
std::vector<wchar_t> buff(len + 1);
std::copy(command_line.begin(), command_line.end(), buff.begin());
buff[len] = 0;
GetStartupInfoW(&startup_info);
BOOL result(CreateProcessW(nullptr, &buff[0], 0, 0, false, CREATE_NO_WINDOW, 0, 0,
&startup_info, &process_info));
if (!result)
{
std::cout << "FAIL" << std::endl;
std::wcout << " command line: <" << command_line << ">" << std::endl;
}
else
{
std::cout << "PASS" << std::endl;
std::wcout << " command line: <" << command_line << ">" << std::endl;
}
return 0;
}
c++ window createprocess
CreateProcess succeeded. It ran the command you asked for. Now, if you wanted to get the result code from that command or parse the output to detect and error that's a different thing, but as far as CreateProcess is concerned it did exactly what you asked for.
– Retired Ninja
Nov 27 '18 at 5:04
Thats what my question is , that why it ran . Its a negative scenario . This is the wrong command there is no such parameters or files named XXXCCCCC......
– rish626509
Nov 27 '18 at 6:51
when you will run the same command from command prompt it will fail , and hence this code also when run should go to if condition and print FAIL
– rish626509
Nov 27 '18 at 6:52
Your expectation of what CreateProcess does and what would constitute a failure is incorrect. Success for CreateProcess means it successfully loaded and began executing whatever you asked it to load. That executable could crash, print out an error, return a particular value that for it indicates an error, but none of that matters to CreateProcess because it did what you asked and created a process. If you need to decide if executing a program was a success or failure you cannot expect CreateProcess to tell you because it does not know.
– Retired Ninja
Nov 27 '18 at 14:25
Failure to CreateProcess means it could not find, load, or run the executable you asked for. When you receive an error at the command prompt it isn't because the program didn't run, it is because it did run and the result was to print an informative message telling you that you gave it invalid input.
– Retired Ninja
Nov 27 '18 at 14:28
add a comment |
I am trying to call the CreateProcessW() function to call dos command icacls in my C++ code . However this CreateProcessW() is not responding correctly to icacls command . I can say this because for negative testing i passed wrong icacls command to CreateProcessW() function an it just didnt throw any error.
However same command was failing in command prompt
I am attaching the code here
#include <vector>
#include <algorithm>
#include <atomic>
#include <memory>
#include <type_traits>
#include <Windows.h>
#include <iostream>
#include <string>
int main()
{
std::wstring command_line(L"icacls XXXCCCCC");//throws error with command prompt
STARTUPINFOW startup_info;
PROCESS_INFORMATION process_info;
size_t len(command_line.size());
std::vector<wchar_t> buff(len + 1);
std::copy(command_line.begin(), command_line.end(), buff.begin());
buff[len] = 0;
GetStartupInfoW(&startup_info);
BOOL result(CreateProcessW(nullptr, &buff[0], 0, 0, false, CREATE_NO_WINDOW, 0, 0,
&startup_info, &process_info));
if (!result)
{
std::cout << "FAIL" << std::endl;
std::wcout << " command line: <" << command_line << ">" << std::endl;
}
else
{
std::cout << "PASS" << std::endl;
std::wcout << " command line: <" << command_line << ">" << std::endl;
}
return 0;
}
c++ window createprocess
I am trying to call the CreateProcessW() function to call dos command icacls in my C++ code . However this CreateProcessW() is not responding correctly to icacls command . I can say this because for negative testing i passed wrong icacls command to CreateProcessW() function an it just didnt throw any error.
However same command was failing in command prompt
I am attaching the code here
#include <vector>
#include <algorithm>
#include <atomic>
#include <memory>
#include <type_traits>
#include <Windows.h>
#include <iostream>
#include <string>
int main()
{
std::wstring command_line(L"icacls XXXCCCCC");//throws error with command prompt
STARTUPINFOW startup_info;
PROCESS_INFORMATION process_info;
size_t len(command_line.size());
std::vector<wchar_t> buff(len + 1);
std::copy(command_line.begin(), command_line.end(), buff.begin());
buff[len] = 0;
GetStartupInfoW(&startup_info);
BOOL result(CreateProcessW(nullptr, &buff[0], 0, 0, false, CREATE_NO_WINDOW, 0, 0,
&startup_info, &process_info));
if (!result)
{
std::cout << "FAIL" << std::endl;
std::wcout << " command line: <" << command_line << ">" << std::endl;
}
else
{
std::cout << "PASS" << std::endl;
std::wcout << " command line: <" << command_line << ">" << std::endl;
}
return 0;
}
c++ window createprocess
c++ window createprocess
edited Nov 27 '18 at 5:06
Retired Ninja
3,58231530
3,58231530
asked Nov 27 '18 at 4:47
rish626509rish626509
154
154
CreateProcess succeeded. It ran the command you asked for. Now, if you wanted to get the result code from that command or parse the output to detect and error that's a different thing, but as far as CreateProcess is concerned it did exactly what you asked for.
– Retired Ninja
Nov 27 '18 at 5:04
Thats what my question is , that why it ran . Its a negative scenario . This is the wrong command there is no such parameters or files named XXXCCCCC......
– rish626509
Nov 27 '18 at 6:51
when you will run the same command from command prompt it will fail , and hence this code also when run should go to if condition and print FAIL
– rish626509
Nov 27 '18 at 6:52
Your expectation of what CreateProcess does and what would constitute a failure is incorrect. Success for CreateProcess means it successfully loaded and began executing whatever you asked it to load. That executable could crash, print out an error, return a particular value that for it indicates an error, but none of that matters to CreateProcess because it did what you asked and created a process. If you need to decide if executing a program was a success or failure you cannot expect CreateProcess to tell you because it does not know.
– Retired Ninja
Nov 27 '18 at 14:25
Failure to CreateProcess means it could not find, load, or run the executable you asked for. When you receive an error at the command prompt it isn't because the program didn't run, it is because it did run and the result was to print an informative message telling you that you gave it invalid input.
– Retired Ninja
Nov 27 '18 at 14:28
add a comment |
CreateProcess succeeded. It ran the command you asked for. Now, if you wanted to get the result code from that command or parse the output to detect and error that's a different thing, but as far as CreateProcess is concerned it did exactly what you asked for.
– Retired Ninja
Nov 27 '18 at 5:04
Thats what my question is , that why it ran . Its a negative scenario . This is the wrong command there is no such parameters or files named XXXCCCCC......
– rish626509
Nov 27 '18 at 6:51
when you will run the same command from command prompt it will fail , and hence this code also when run should go to if condition and print FAIL
– rish626509
Nov 27 '18 at 6:52
Your expectation of what CreateProcess does and what would constitute a failure is incorrect. Success for CreateProcess means it successfully loaded and began executing whatever you asked it to load. That executable could crash, print out an error, return a particular value that for it indicates an error, but none of that matters to CreateProcess because it did what you asked and created a process. If you need to decide if executing a program was a success or failure you cannot expect CreateProcess to tell you because it does not know.
– Retired Ninja
Nov 27 '18 at 14:25
Failure to CreateProcess means it could not find, load, or run the executable you asked for. When you receive an error at the command prompt it isn't because the program didn't run, it is because it did run and the result was to print an informative message telling you that you gave it invalid input.
– Retired Ninja
Nov 27 '18 at 14:28
CreateProcess succeeded. It ran the command you asked for. Now, if you wanted to get the result code from that command or parse the output to detect and error that's a different thing, but as far as CreateProcess is concerned it did exactly what you asked for.
– Retired Ninja
Nov 27 '18 at 5:04
CreateProcess succeeded. It ran the command you asked for. Now, if you wanted to get the result code from that command or parse the output to detect and error that's a different thing, but as far as CreateProcess is concerned it did exactly what you asked for.
– Retired Ninja
Nov 27 '18 at 5:04
Thats what my question is , that why it ran . Its a negative scenario . This is the wrong command there is no such parameters or files named XXXCCCCC......
– rish626509
Nov 27 '18 at 6:51
Thats what my question is , that why it ran . Its a negative scenario . This is the wrong command there is no such parameters or files named XXXCCCCC......
– rish626509
Nov 27 '18 at 6:51
when you will run the same command from command prompt it will fail , and hence this code also when run should go to if condition and print FAIL
– rish626509
Nov 27 '18 at 6:52
when you will run the same command from command prompt it will fail , and hence this code also when run should go to if condition and print FAIL
– rish626509
Nov 27 '18 at 6:52
Your expectation of what CreateProcess does and what would constitute a failure is incorrect. Success for CreateProcess means it successfully loaded and began executing whatever you asked it to load. That executable could crash, print out an error, return a particular value that for it indicates an error, but none of that matters to CreateProcess because it did what you asked and created a process. If you need to decide if executing a program was a success or failure you cannot expect CreateProcess to tell you because it does not know.
– Retired Ninja
Nov 27 '18 at 14:25
Your expectation of what CreateProcess does and what would constitute a failure is incorrect. Success for CreateProcess means it successfully loaded and began executing whatever you asked it to load. That executable could crash, print out an error, return a particular value that for it indicates an error, but none of that matters to CreateProcess because it did what you asked and created a process. If you need to decide if executing a program was a success or failure you cannot expect CreateProcess to tell you because it does not know.
– Retired Ninja
Nov 27 '18 at 14:25
Failure to CreateProcess means it could not find, load, or run the executable you asked for. When you receive an error at the command prompt it isn't because the program didn't run, it is because it did run and the result was to print an informative message telling you that you gave it invalid input.
– Retired Ninja
Nov 27 '18 at 14:28
Failure to CreateProcess means it could not find, load, or run the executable you asked for. When you receive an error at the command prompt it isn't because the program didn't run, it is because it did run and the result was to print an informative message telling you that you gave it invalid input.
– Retired Ninja
Nov 27 '18 at 14:28
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53492924%2fwrong-icacls-command-not-giving-any-error-on-being-called-by-createprocessw-func%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53492924%2fwrong-icacls-command-not-giving-any-error-on-being-called-by-createprocessw-func%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
CreateProcess succeeded. It ran the command you asked for. Now, if you wanted to get the result code from that command or parse the output to detect and error that's a different thing, but as far as CreateProcess is concerned it did exactly what you asked for.
– Retired Ninja
Nov 27 '18 at 5:04
Thats what my question is , that why it ran . Its a negative scenario . This is the wrong command there is no such parameters or files named XXXCCCCC......
– rish626509
Nov 27 '18 at 6:51
when you will run the same command from command prompt it will fail , and hence this code also when run should go to if condition and print FAIL
– rish626509
Nov 27 '18 at 6:52
Your expectation of what CreateProcess does and what would constitute a failure is incorrect. Success for CreateProcess means it successfully loaded and began executing whatever you asked it to load. That executable could crash, print out an error, return a particular value that for it indicates an error, but none of that matters to CreateProcess because it did what you asked and created a process. If you need to decide if executing a program was a success or failure you cannot expect CreateProcess to tell you because it does not know.
– Retired Ninja
Nov 27 '18 at 14:25
Failure to CreateProcess means it could not find, load, or run the executable you asked for. When you receive an error at the command prompt it isn't because the program didn't run, it is because it did run and the result was to print an informative message telling you that you gave it invalid input.
– Retired Ninja
Nov 27 '18 at 14:28