Link to home
Start Free TrialLog in
Avatar of carrollbluesfan
carrollbluesfan

asked on

Using Input Box and a Command Button to launch a DOS app


all, thanks for any input. Using VB6 I have a requirement to create a simple 3 command button interface to perform some DOS command line syntax

the buttons will be taking input from three Input boxes

add user
BESUserAdminClient -add -u <1stInputBox> -p <2ndInputBox>

delete user
BESUserAdminClient -del -u <1stInputBox>

add IT policy
BESUserAdminClient -add -itpolicy <3rdInputBox>

total novice at VB6 so any help would be useful.
Avatar of gilbar
gilbar

there is a Shell command in vb that will let you enter batch commands, but it doesn't wait for the command to finish before going on to the next vb command. So i like to use the WSH object Shell, like this:

Cmd1 = "dir > C:\test.txt"
Set objWsh = CreateObject("WScript.Shell")
Call objWsh.Run("cmd /c " & Cmd1, 0, True)
Set objWsh = Nothing

you need the cmd /c part so that you can run things built into dos (that is, that aren't .exe's)
the ,True part tells it to wait for the doc command to finish before continuing
The .Run command doesn't show up as a command prompt window, but also doesn't allow results to be returned, thus the pipe for my dir command.  Another way to get results is to use the .Exec command instead, but it shows up as a blak command prompt which i find distracting. Here should be a link to the help page for these:
http://www.microsoft.com/technet/scriptcenter/guide/default.mspx
By "input boxes" you mean TextBox Controls or Popup window that get user's input?
If its Textboxes You can use something like this:

Private Sub Command1_Click()
Dim Cmd As String
Cmd = "BESUserAdminClient -add -u " & Text1.Text & " -p " & Text2.Text
Shell Cmd
End Sub

Private Sub Command2_Click()
Dim Cmd As String
Cmd = "BESUserAdminClient -del -u " & Text1.Text
Shell Cmd
End Sub

Private Sub Command3_Click()
Dim Cmd As String
Cmd = "BESUserAdminClient -add -itpolicy" & Text3.Text
Shell Cmd
End Sub


Its good Idea to check user input prior to execute the command:
Like this :

Private Sub Command2_Click()

If Text1.Text="" Then
   MsgBox "Please enter valid Username"
   Exit Sub
End If

Dim Cmd As String
Cmd = "BESUserAdminClient -del -u " & Text1.Text
Shell Cmd
End Sub

Avatar of carrollbluesfan

ASKER


Thanks Mike, I'll check this over the weekend on the machine I'm using...

That would be a PopUp window that gets a user input
ASKER CERTIFIED SOLUTION
Avatar of Michael_D
Michael_D
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial