Is there anyway to have preset data for user input

2020-01-29 01:30发布

So basically I have a batch file that requires alot of user input. I was wondering if it was possible to have any filler data already present when the question is asked, and if the user needs to change something, they can go edit that data. For example

enter image description here And then the user enter their first and last name. enter image description here

But is it possible to start with a default name that the user can go back and edit if they need?

This probably isn't necessary, But this is the code I use for the user input.

Set /p "Author=Please enter your name: "

And I understand for the Author it wouldn't make much sense to have preset data, but there are other instances where it would be useful for me to do this. Is it possible?

7条回答
唯我独甜
2楼-- · 2020-01-29 02:31

The method below have the inconvenience that the screen must be cleared before the user enter the data, but I am working trying to solve this point:

EDIT: I fixed the detail of the first version

@if (@CodeSection == @Batch) @then

@echo off
rem Enter the prefill value
CScript //nologo //E:JScript "%~F0" "First Last"
rem Read the variable
echo -----------------------------------------------------------
set /P "Author=Please enter your name: "
echo Author=%Author%
goto :EOF

@end

WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));

For further details, see this post.

查看更多
登录 后发表回答