• DOS Variables (Windows XP)

    Author
    Topic
    #381954

    I don’t really know how to explain this. If you create a shortcut to a batch file in Win95/98 and then alter the shortcuts properties by adding a ” ?” at the end of the path and file name it makes windows call up an Enter Variable box before the batch file runs. What ever you type in variable box is then stored in the “%1” variable for use in the batch file. Anyone know of a way of doing this in XP? Or a way to ASK the user to specify a variable, I.e. A Path, Filename or Password! I know how to ask it for keys but i want the equivulent of a stored String in VB.

    Thanks
    Jamie

    Viewing 1 reply thread
    Author
    Replies
    • #645905

      Do you need to prompt the user for input, or can you pass the value to the batch file using a static value? I use the IF statement to check for a valid variable that will determine the execution of certain subroutines in a command script. If the user’s choice isn’t valid, it calls a :SYNTAX label to let them know the proper use.

      I haven’t tried it, but perhaps you could use the old CHOICE.COM in your script. It may not run properly or at all under CMD.EXE, and COMMAND.COM is slow as molasses but might work.

      Historically, getting input in a batch file has been a difficult task, but there are ways if you’re willing to spend the time. smile

    • #645919

      You can use the new enhanced SET command to get user input. Not quite the same as the question you had under w98, but should achieve much the same result. You’ll need to modify your batch files slightly, since they’ll be getting the user input, rather than having it passed as a command line parameter.

      Insert a set command, eg “set /p userinput=Please enter filename”, at the start of your batch file, and then use the %userinput% environment variable in lieu of %1 in the rest of the batch file.

      For more details do a “set /?” in a cmd window. And you may find the Batch Files and Command Line Commands threads interesting, maybe even adding to your batch armoury.. grin

      • #646004

        Tim – thanks for pulling that up. I had completely forgotten about it even though I frequently use SET /a in my scripts!

      • #646028

        Cheers Tim, just what the doctor ordered! I wanted to write a batch file that extracts Unreal Tournament files from inside zip files and places them in the appropriate directory, for this i needed to know where the unreal tournament directory was, thanks to you i can now ask the user!

        Thanks Again
        Jamie

    Viewing 1 reply thread
    Reply To: DOS Variables (Windows XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: