[Solved] Sending input to system("command") prompt Windows
-
In my program I'm using
system("")
command to add a variable intoUser variables
usingreg add
. In the future I'll want to update the variable value to something else, but if the variable exists it will prompt the user to input Y/N to override it. Is there a way to automatically give the input instead of the user? I was thinking that maybe I could usesystem("y")
, but it still waits for the input from the user, and then gives the error that y is not a command. I can't use Windows.h to modify registry, so I want to find a solution to this. Maybe I'll needsystem("")
for something else in the future that will have the same problem with having to input something. Solution:Victor Nijegorodov wrote:
According to the reg add | Microsoft Docs you can add option /f that will cause the adding the registry entry without prompting for confirmation.
-
In my program I'm using
system("")
command to add a variable intoUser variables
usingreg add
. In the future I'll want to update the variable value to something else, but if the variable exists it will prompt the user to input Y/N to override it. Is there a way to automatically give the input instead of the user? I was thinking that maybe I could usesystem("y")
, but it still waits for the input from the user, and then gives the error that y is not a command. I can't use Windows.h to modify registry, so I want to find a solution to this. Maybe I'll needsystem("")
for something else in the future that will have the same problem with having to input something. Solution:Victor Nijegorodov wrote:
According to the reg add | Microsoft Docs you can add option /f that will cause the adding the registry entry without prompting for confirmation.
-
I do not understand how
system("")
can add a variable to anything. I think we need more details.He said he's using
system("reg add")
to do it. I've never used either one, but I assume it's a way for a program to add something to the registry. I think he's now looking for a way for a program to enter"y"
on the user's behalf, perhaps to confirm a system command invoked bysystem()
. But I don't know of a way to fake console input. Do you?Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
I do not understand how
system("")
can add a variable to anything. I think we need more details.system("reg add \"HKEY_CURRENT_USER\\Environment\" /v TestVariable /t REG_EXPAND_SZ /d \"TestValue\"");
Result: "The operation completed successfully." And the variable is added with the given value. But then when wanting to update it:
system("reg add \"HKEY_CURRENT_USER\\Environment\" /v TestVariable /t REG_EXPAND_SZ /d \"TestValueUpdated\"");
Result: "Value TestVariable exists, overwrite(Yes/No)?" If Y is given as input, then "The operation completed successfully.", and the value is updated. But I want to skip the step where the user has to give the Y input, and send it automatically.
-
system("reg add \"HKEY_CURRENT_USER\\Environment\" /v TestVariable /t REG_EXPAND_SZ /d \"TestValue\"");
Result: "The operation completed successfully." And the variable is added with the given value. But then when wanting to update it:
system("reg add \"HKEY_CURRENT_USER\\Environment\" /v TestVariable /t REG_EXPAND_SZ /d \"TestValueUpdated\"");
Result: "Value TestVariable exists, overwrite(Yes/No)?" If Y is given as input, then "The operation completed successfully.", and the value is updated. But I want to skip the step where the user has to give the Y input, and send it automatically.
At first I was thinking, well if I can't modify it, what if I try to first delete it and then add it with the new value, but I get in the same situation, and that is I have to give it an input because when you want to delete a variable, you have to input Y/N.
system("reg delete \"HKEY_CURRENT_USER\\Environment\" /v TestVariable");
Result: "Delete the registry value TestVariable (Yes/No)?"
-
system("reg add \"HKEY_CURRENT_USER\\Environment\" /v TestVariable /t REG_EXPAND_SZ /d \"TestValue\"");
Result: "The operation completed successfully." And the variable is added with the given value. But then when wanting to update it:
system("reg add \"HKEY_CURRENT_USER\\Environment\" /v TestVariable /t REG_EXPAND_SZ /d \"TestValueUpdated\"");
Result: "Value TestVariable exists, overwrite(Yes/No)?" If Y is given as input, then "The operation completed successfully.", and the value is updated. But I want to skip the step where the user has to give the Y input, and send it automatically.
According to the [reg add | Microsoft Docs](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/reg-add) you can add option /f that will cause the adding the registry entry without prompting for confirmation.
-
According to the [reg add | Microsoft Docs](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/reg-add) you can add option /f that will cause the adding the registry entry without prompting for confirmation.
Yeah, that works. I have no idea how I managed to skip that one line that I needed... Thanks!
-
He said he's using
system("reg add")
to do it. I've never used either one, but I assume it's a way for a program to add something to the registry. I think he's now looking for a way for a program to enter"y"
on the user's behalf, perhaps to confirm a system command invoked bysystem()
. But I don't know of a way to fake console input. Do you?Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
In my program I'm using
system("")
command to add a variable intoUser variables
usingreg add
. In the future I'll want to update the variable value to something else, but if the variable exists it will prompt the user to input Y/N to override it. Is there a way to automatically give the input instead of the user? I was thinking that maybe I could usesystem("y")
, but it still waits for the input from the user, and then gives the error that y is not a command. I can't use Windows.h to modify registry, so I want to find a solution to this. Maybe I'll needsystem("")
for something else in the future that will have the same problem with having to input something. Solution:Victor Nijegorodov wrote:
According to the reg add | Microsoft Docs you can add option /f that will cause the adding the registry entry without prompting for confirmation.
Why are you not using the registry API directly rather than going through (antiquated)
system()
calls?"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