I this correct?
-
Sir, I want to execute a windows command in my C++ program. I know it can be done by adding system function. I want to add the windows command to a specific drive. I have coded a program which will collect the specific drive and will store the value in a wchar_t store[4] so in order to go for that specific drive I used
system("store");//variable in which the disk like D:\ is stored
command is this correct or wrong? Thank you
-
Sir, I want to execute a windows command in my C++ program. I know it can be done by adding system function. I want to add the windows command to a specific drive. I have coded a program which will collect the specific drive and will store the value in a wchar_t store[4] so in order to go for that specific drive I used
system("store");//variable in which the disk like D:\ is stored
command is this correct or wrong? Thank you
-
No that will try to execute a program/script called
store
. It is not clear what you mean by "add the windows command to a specific drive". Do you mean that you wish to add the drive letter to the command as a parameter, like:program D:
Please clarify.
-
Yes sir store is now carrying the value D:\ I want to execute it by using the variable. What should I do now?
-
Sir, I think I have not explained my problem briefly.here is the brief explanation of my problem I want to find the attributes of the removable drive so, I need to get the string of the drive I've done everything and stored the string value in the "store" variable I mean the variable consists the drive location(D:\) so that I can execute another system function called attrib to find its attributes. Thank you
-
Sir, I think I have not explained my problem briefly.here is the brief explanation of my problem I want to find the attributes of the removable drive so, I need to get the string of the drive I've done everything and stored the string value in the "store" variable I mean the variable consists the drive location(D:\) so that I can execute another system function called attrib to find its attributes. Thank you
Then it is simply a matter of creating the full command and parameter in a string and passing that string to the system command.
wchar_t sysCommand[128];
swprintf_s(sysCommand, L"attrib %s", store);
system(sysCommand);See also system, _wsystem[^].
-
Then it is simply a matter of creating the full command and parameter in a string and passing that string to the system command.
wchar_t sysCommand[128];
swprintf_s(sysCommand, L"attrib %s", store);
system(sysCommand);See also system, _wsystem[^].
I have no idea if this is the right answer to the OP's question, Richard, but the fact that you were able to ascertain something from it is impressive. :thumbsup:
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Then it is simply a matter of creating the full command and parameter in a string and passing that string to the system command.
wchar_t sysCommand[128];
swprintf_s(sysCommand, L"attrib %s", store);
system(sysCommand);See also system, _wsystem[^].
Sir, errors are quiet similar to my initial work. i.e initially when I use system(store) it shows me an error the same error is showing when I use system(sysCommand); Error:
Severity Code Description Project File Line
Error C2664 'int system(const char *)': cannot convert argument 1 from 'wchar_t [128]' to 'const char *' CG C:\Users\User\Desktop\Analyser tools\Sub-Project\Sub-Project\USB informer.cpp 52Thank you for your kind help
-
I have no idea if this is the right answer to the OP's question, Richard, but the fact that you were able to ascertain something from it is impressive. :thumbsup:
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Sir, errors are quiet similar to my initial work. i.e initially when I use system(store) it shows me an error the same error is showing when I use system(sysCommand); Error:
Severity Code Description Project File Line
Error C2664 'int system(const char *)': cannot convert argument 1 from 'wchar_t [128]' to 'const char *' CG C:\Users\User\Desktop\Analyser tools\Sub-Project\Sub-Project\USB informer.cpp 52Thank you for your kind help
This is a Unicode issue.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Sir, errors are quiet similar to my initial work. i.e initially when I use system(store) it shows me an error the same error is showing when I use system(sysCommand); Error:
Severity Code Description Project File Line
Error C2664 'int system(const char *)': cannot convert argument 1 from 'wchar_t [128]' to 'const char *' CG C:\Users\User\Desktop\Analyser tools\Sub-Project\Sub-Project\USB informer.cpp 52Thank you for your kind help
-
This is a Unicode issue.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
To sir DavidCrow: I am using Unicode characet set what should I do now? I am using only unicode and not multibyte Thank you for your kind help
You can't send a
wchar_t
array tosystem()
. It's expecting achar
pointer/array instead."One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Sorry, my mistake, you need to use
_wsystem
. See the link I provided in a previous message. -
Sorry, my mistake, you need to use
_wsystem
. See the link I provided in a previous message. -
Sir, I have completed everything and when I run my code the command window disappears immediately what should I do now? Thank you
-
The system process will only run the command that you send it, and then terminate. There are alternative ways of doing this: see the exec commands at Process and Environment Control[^].
Sir, I referred here Execute a Program with C++[^] and did this
ShellExecute(
NULL,
_T("open"),
_T("cmd.exe"),
_T("attrib"),
(show),
SW_SHOW);it is showing the show (I mean the directory) like this K:\ but not ececuting the attrib.how could I solve this? Thank you
-
Sir, I referred here Execute a Program with C++[^] and did this
ShellExecute(
NULL,
_T("open"),
_T("cmd.exe"),
_T("attrib"),
(show),
SW_SHOW);it is showing the show (I mean the directory) like this K:\ but not ececuting the attrib.how could I solve this? Thank you
If you are wanting to get the attributes of a file/folder, why do it the way we were doing it 30 years ago? See
GetFileAttributes()
instead."One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Sir, I referred here Execute a Program with C++[^] and did this
ShellExecute(
NULL,
_T("open"),
_T("cmd.exe"),
_T("attrib"),
(show),
SW_SHOW);it is showing the show (I mean the directory) like this K:\ but not ececuting the attrib.how could I solve this? Thank you
Your parameters are not correct, and it will not work just by opening cmd.exe. You need to add the option to tell cmd to execute the sub-command in the parameter list automatically like:
PWSTR show = L"/k attrib D:\\";
ShellExecute(
NULL,
L"open",
L"cmd.exe",
show,
NULL,
SW_SHOW);Of course, the attrib command will not operate on a drive letter, and as David mentions, there are better ways of getting this information.
-
Your parameters are not correct, and it will not work just by opening cmd.exe. You need to add the option to tell cmd to execute the sub-command in the parameter list automatically like:
PWSTR show = L"/k attrib D:\\";
ShellExecute(
NULL,
L"open",
L"cmd.exe",
show,
NULL,
SW_SHOW);Of course, the attrib command will not operate on a drive letter, and as David mentions, there are better ways of getting this information.
Sir, Is there any other way to execute some commands like this to a specific drive by giving the drive string at the run time? because I have to define the drive name here? I have referred to create process, shell execute etc., attributes is one of my functions I need to execute several different commands like this on a specific drive how could one do it? Thank you