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
  • 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.

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.
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now