Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. System Admin
  4. Interactive batch in Windows NT

Interactive batch in Windows NT

Scheduled Pinned Locked Moved System Admin
c++sysadminwindows-adminlinuxtutorial
3 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dave Midgley
    wrote on last edited by
    #1

    I'm trying to make an interactive batch file (.cmd) to run under Windows NT. The obvious way is to have a program that displays a prompt and sets an environment variable with the response, however 1) using _setenv (I'm in C/C++ here) only alters the environment for the current program, so the batch file that ran the program does not see them; conversely 2) altering the registry where the environment variables are kept (HKEY_CURRENT_USER\Environment etc.) has no effect until a new DOS shell is started, so the batch file that ran the program does not see them; 3) the old DOS method of getting the PSP and walking up the environment areas isn't allowed under NT (and there's never enough space in the environment area anyway); If anyone knows how to write a program that can do this, or any other way of making a batch file intercative, I'd love to hear about it. (PS I know that using VBS or some other scripting language is the right way to go, but I need this to run on any NT Server machine, and the CMD processor seems to be the only scripting engine that is guaranteed to be available) Thanks Dave Dave

    G 1 Reply Last reply
    0
    • D Dave Midgley

      I'm trying to make an interactive batch file (.cmd) to run under Windows NT. The obvious way is to have a program that displays a prompt and sets an environment variable with the response, however 1) using _setenv (I'm in C/C++ here) only alters the environment for the current program, so the batch file that ran the program does not see them; conversely 2) altering the registry where the environment variables are kept (HKEY_CURRENT_USER\Environment etc.) has no effect until a new DOS shell is started, so the batch file that ran the program does not see them; 3) the old DOS method of getting the PSP and walking up the environment areas isn't allowed under NT (and there's never enough space in the environment area anyway); If anyone knows how to write a program that can do this, or any other way of making a batch file intercative, I'd love to hear about it. (PS I know that using VBS or some other scripting language is the right way to go, but I need this to run on any NT Server machine, and the CMD processor seems to be the only scripting engine that is guaranteed to be available) Thanks Dave Dave

      G Offline
      G Offline
      Garth J Lancaster
      wrote on last edited by
      #2

      Dave - I dont know if you've since found a solution (or if Ive understood the problem), but here's my $AUD 0.02c worth (probably not worth much in other currencies) I would start with :- http://www.pgh.net/~newcomer/processes.htm or http://www.pgh.net/~newcomer/process.htm or go to http://www.pgh.net/~newcomer/mvp\_tips.htm and look for 'asynchronous process notification' these solve the problem of starting (for example) a batch file and reading the console output back into a listbox etc .. from there, the listbox could be parsed looking for certain triggers etc, to get the results.. 'Franky Braem' also has an article on Codeproject entitled 'Redirect' which could be used as a starting point. If thats not what you want 100%, then how about creating a console window using one of the above techniques, and reading (much like screen scraping from it) directly - I have seen examples on doing this, but cant find any to hand right now ... hth Garth

      D 1 Reply Last reply
      0
      • G Garth J Lancaster

        Dave - I dont know if you've since found a solution (or if Ive understood the problem), but here's my $AUD 0.02c worth (probably not worth much in other currencies) I would start with :- http://www.pgh.net/~newcomer/processes.htm or http://www.pgh.net/~newcomer/process.htm or go to http://www.pgh.net/~newcomer/mvp\_tips.htm and look for 'asynchronous process notification' these solve the problem of starting (for example) a batch file and reading the console output back into a listbox etc .. from there, the listbox could be parsed looking for certain triggers etc, to get the results.. 'Franky Braem' also has an article on Codeproject entitled 'Redirect' which could be used as a starting point. If thats not what you want 100%, then how about creating a console window using one of the above techniques, and reading (much like screen scraping from it) directly - I have seen examples on doing this, but cant find any to hand right now ... hth Garth

        D Offline
        D Offline
        Dave Midgley
        wrote on last edited by
        #3

        Thanks Garth, but either you've misunderstood the question or I've misunderstood the answer. Basically all I want is a way of putting user interaction into a batch file, such that the user is prompted to enter values which can then be used by subsequent operations in the batch file (ie. passed to other programs as parameters, used in IF constructs, etc.). There is(are) no Windows/windows involved here at all (except for the DOS box that the user runs the batch file in). Thanks for trying anyway. Dave Dave

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups