title: Get a variable from a CMD popup
body: <p>I currently am trying to create a batch file in which one of the purposes rely on getting a 6 digit value from the user. It's needed for aesthetics sake that the batch file show a popup message that will have a message requesting the info, and a space for the user to type said info, and obviously a button to confirm.
  The issue being that I can't for the life of me figure this out, it's the first time that I am doing some batch scripting, most of my doubts were simple and I was able to advance pretty far on intuition and google alone. I've found a couple methods to generate a message box like</p>
  
  <pre><code>mshta "javascript:var sh=new ActiveXObject( 'WScript.Shell' ); sh.Popup( 'Message!', 10, 'Title!', 64 );close()"
  </code></pre>
  
  <p>and</p>
  
  <pre><code>@powershell.exe -ExecutionPolicy Bypass -Command "[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.MessageBox]::Show('We are proceeding with next step.')"
  </code></pre>
  
  <p>which both work to show a message box, but I can't figure out how to get input from either of those. 
  The cmd will be hidden from the user so the only part of it they should see is the message box that will show up. I want to have the user input a value, and the I want to set a variable to that value.
  So far what I've been developing is the following code, with changed variables. The important part is the last line.</p>
  
  <pre><code>@ECHO OFF
  SETLOCAL ENABLEEXTENSIONS
  set PGUSER=postgres
  set PGPASSWORD=password
  set PGHOST=localhost
  set PGPORT=5432
  set Arch=x64
  if "%PROCESSOR_ARCHITECTURE%" == "x86" ( 
      if not defined PROCESSOR_ARCHITEW6432 set Arch=x86
  )
  wmic product where "name like 'Java%'" call uninstall
  start /D "C:\path\instaladores" /WAIT regedit -v -s path.reg
  if %Arch% EQU x64 goto :okpg
  if %Arch% NEQ x64 goto :failpg
  :failpg
  start /D "C:\path\instaladores" /WAIT pg32.exe --mode unattended --superpassword password --servicepassword root --serverport 5432
  start /D "C:\path\instaladores" /WAIT Java32.exe INSTALL_SILENT=Enable STATIC=Enable REBOOT=Disable REMOVEOUTOFDATEJRES=0
  goto :continue
  
  :okpg
  start /D "C:\path\instaladores" /WAIT pg64.exe --mode unattended --superpassword password --servicepassword root --serverport 5432
  start /D "C:\path\instaladores" /WAIT Java64.exe INSTALL_SILENT=Enable STATIC=Enable REBOOT=Disable REMOVEOUTOFDATEJRES=0
  :continue
  cd/
  cd "C:\Program Files\PostgreSQL\9.6\bin"
  psql -d sped -c "select 'ok';"
  if %errorlevel% EQU 0 goto :ok
  if %errorlevel% NEQ 0 goto :fail
  :fail
  cd/
  cd "C:\Program Files\PostgreSQL\9.6\bin"
  createdb -E WIN1252 -T template0 sped
  psql -U postgres -d sped  -c "CREATE ROLE ""user"" LOGIN PASSWORD 'password' SUPERUSER CREATEDB CREATEROLE REPLICATION VALID UNTIL 'infinity';"
  pg_restore.exe --dbname "sped" "C:\SAAM-SPED\instaladores\banco.backup"
  psql -U user -d sped  -c "update reg_1102 a set num_reg = '%variableIWant%";
  </code></pre>
  
  <p>which works fine, the issue being how to get the variable I Want in the last line which i can't quite figure out. @Apolymoxic  <a href="https://itfordummies.net/2016/05/09/create-input-box-powershell/" rel="nofollow noreferrer">sen't me a very helpfull link</a></p>
  
  <p>in which I came up with something like</p>
  
  <pre><code>set variableIWant="@powershell.exe -ExecutionPolicy Bypass -Command "[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null; $User = [Microsoft.VisualBasic.Interaction]::InputBox('Enter a user name', 'User', "$env:UserName")""
  </code></pre>
  
  <p>Which I tried for testing, and didn't work, giving an error, I then after some more reading decided to try to make the powershell part set an enviroment variable which looked kinda like this</p>
  
  <pre><code>@powershell.exe -ExecutionPolicy Bypass -Command "[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null;$Env:variableIWant = [Microsoft.VisualBasic.Interaction]::InputBox('Enter a Id', 'Id', "$env:variableIWant")"
  </code></pre>
  
  <p>That one didn't return any errors but when I tried to echo the variable on CMD, it doesn't work. That's as far as I was able to get so far. It Seems to me that the command I am using to set the variable on powershell doesn't actually set it on the computer, so when the CMD exits the powershell script the variable ceases to exist, I'm currently trying to figure out how to do it properly but to no avail so far</p>