select variable

Posted on 2006-06-20
Last Modified: 2012-05-05
ok so i have this really rought script to reset a password.

SET username=myusername
SET password=mypassword
SET file1=svn-auth-file1
SET file2=svn-auth-file2
"D:\Program Files\Apache Group\Apache2\bin\htpasswd.exe" -b "D:\Program Files\Apache Group\Apache2\etc\%file?%"  %username% %password%

What i want to do is to have the command window to pause and promt for the user to add the username then the passowrd and the to select the file (one or two).

Question by:willa666
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +1
LVL 20

Accepted Solution

alainbryden earned 500 total points
ID: 16943422
So do you want the form as follows?

ResetPass "userName" "oldPassword" "newPassword" "newPasswordCheck"

and then you would like it to execute the above command from within the program? If that's what you would like let me know and I reserve the right to come up with the answer first :)

LVL 17

Expert Comment

ID: 16943476
Dim sUser As String
Dim sPW as String

sUser = InputBox("Enter User Name")
sPW = InputBox("Enter Password")


PID = Shell("""D:\Program Files\Apache Group\Apache2\bin\htpasswd.exe"" -b ""D:\Program Files\Apache Group\Apache2\etc\%file?%"" " + sUser+" "+sPW,vbNormalFocus)

LVL 17

Expert Comment

ID: 16943490
Did not ask for the file name but you get the idea.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 16943512
Sorry forgot to add the main thing, This is a script that will run in a command windows.

I want the script to be run like follows

select a fiel to use (type 1 or 2)
promt for the username
promt for the password to reset the user account with.
LVL 17

Expert Comment

ID: 16943847
Simple way is to generate a batch file

Open "C:\tmp.bat" for output as #1
Print #1,"........."
Close #1
OK = Shell("c:\tmp.bat", vbNormalFocus)
LVL 30

Expert Comment

ID: 16948015
hmmmm this actually has nothing to do with visual basic. If you ask this in the OS / DOS section you'll have an answer in five seconds.
LVL 20

Expert Comment

ID: 16948121
no this can 100% be done in visual basic. VB's main() sub can take command prompt parameters just like C, Java, or any other language. I'm just not familiar with how you manipulate these and I'm not interested in doing the research at the moment.
LVL 30

Expert Comment

ID: 16948660
It certainly can be done 100% in visual basic.

But willa666 's request is written in a batch file and they are asking for a prompt in the command window, so I assume they want to remain on that platform.

LVL 17

Expert Comment

ID: 16949105
DOS Batch files have been replaced by Script files.  Using a script you get user imput and then use it.  The problem with script files is that some Anti-virus products block the use of scripting. If you can code in VB then the answer is so simple and it works with all anti-virus products. So if you have VB suggest you use it. If you do not have VB then you can do what you want with VBS.

Here is some info on how to create a VBS file.

And here is the script that will do as you wish.
1) Create a blank text file, paste the following code into the file.
2) The rename the file as you wish but end with .vbs.
3) Double click on the file or use as anyother comamnd.

Option Explicit
Dim objShell
Dim sFile
Dim sUser
Dim sPW
Dim sCmd

' Get user input

sUser = InputBox("Enter User Name")
sPW = InputBox("Enter Password")
sFile = InputBox("Enter file (1 or 2)")
' Create command line

sCMD ="""D:\Program Files\Apache Group\Apache2\bin\htpasswd.exe"" -b "
sCMD = sCMD & """D:\Program Files\Apache Group\Apache2\etc\svn-auth-file" & sFile & """ "
sCMD = sCMD & sUser & " " & sPW

' Comment out the following after testing
MsgBox "CMD=" & sCMD ' only need this for debugging"

' run the command
Set objShell = CreateObject("WScript.Shell")
objShell.Run sCMD

' close up

LVL 30

Expert Comment

ID: 16949750
>> DOS Batch files have been replaced by Script files

Thats a bit of a blanket statement. Some things are more eloquently done in batch files than VBScript... I believe the solution is dictated by a lot of factors and in some cases a batch file is a better solution.

Anyway thats my 2 cents!
LVL 17

Expert Comment

ID: 16950038
nmcdermaid yes you are write, especially on systems where scripting is blocked by anti-virus.
LVL 17

Expert Comment

ID: 16950045
Write? Did I mean right? Too much coding!

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month4 days, 23 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question