Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 460
  • Last Modified:

Run Dos Program and Pass Arguments

Hi,
I want to run a command program by passing arguments via a textbox etc., then execute the program from VB. I use some of the utilities from www.systeminternals.com and I want to create a gui to run them. Thanks,
d
0
dingo11
Asked:
dingo11
  • 9
  • 8
  • 5
1 Solution
 
vinnyd79Commented:
you can use shell to run a command.

This will run whatever command is in Text1 and send the results of the command to a file.

Private Sub Command1_Click()
Dim cm As String
cm = "command.com /c " & Text1.Text & ">C:\tempfile.txt"
Shell cm, vbNormalFocus
End Sub
0
 
vinnyd79Commented:
to run a file try this.

Private Sub Command1_Click()
Dim cm As String
cm = "command.com /c " & Text1.Text
Shell cm, vbNormalFocus
End Sub
0
 
Richie_SimonettiIT OperationsCommented:
well, try with:
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation
As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal
nShowCmd As Long) As Long

dim ret as long

ret=shellexecute(me.hwnd,"open",pathto_your_exe_here,"paremeters(if any otherwise vbnullstring)",vbnullstring,vbnormal)
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
dingo11Author Commented:
guys,
I thought I sent this yesterday but no,
Here is one of the programs by Mark Russinovich, who I e-mailed about the programs usage.

sdelete [-p passes] [-s] [-q] <file or directory>
-p passes      Specifies number of overwrite passes
-s             Recurse subdirectories
-q             Don't print errors (quiet)

======================================
vin,
I only want to enter the arguments via the textboxes.

richie,
ret returned a 42? and didn't delete a thing. What if you want to leave out an argument? Eg a file does need recursion. I guess Mark will answer that if he he gets back to me.

---------------
    Dim ret As Long
    Dim sCommand, sFiletoDelete As String

    sCommand = "C:\Documents and Settings\Administrator\Desktop\SecureDelete\SDELETE.EXE"
    sFiletoDelete = "C:\Documents and Settings\Administrator\Desktop\SecureDelete\test.txt"
   
    ret = ShellExecute(Me.hwnd, "open", sCommand, "1  sFiletoDelete", vbNullString, vbNormal)
    MsgBox ret

0
 
vinnyd79Commented:
Maybe you can do something like this:

Private Sub Command1_Click()
Dim sCommand, sFiletoDelete As String
Dim sCm, mResp As String
sCommand = "C:\Documents and Settings\Administrator\Desktop\SecureDelete\SDELETE.EXE"
sFiletoDelete = "C:\Documents and Settings\Administrator\Desktop\SecureDelete\test.txt"
If Text1.Text = "" Then
    mResp = MsgBox("No arguments entered!", vbYesNoCancel, "Do you want to launch without arguments?")
    If mResp <> vbYes Then GoTo skpIt
    sCm = sCommand & Space(1) & sFiletoDelete
    Shell sCm, vbNormalFocus
    GoTo skpIt
End If
sCm = sCommand & Space(1) & Text1.Text & Space(1) & sFiletoDelete
Shell sCm, vbNormalFocus
skpIt:
End Sub
0
 
Richie_SimonettiIT OperationsCommented:
if i am not wrong (i don't know that prog):


   Dim ret As Long
   Dim sCommand, sFiletoDelete As String

   sCommand = "C:\Documents and Settings\Administrator\Desktop\SecureDelete\SDELETE.EXE"
   sFiletoDelete = "C:\Documents and Settings\Administrator\Desktop\SecureDelete\test.txt"
   
   ret = ShellExecute(Me.hwnd, "open", sCommand, "1 " &   chr$(34) & sFiletoDelete chr$(34), vbNullString, vbNormal)
   MsgBox ret
0
 
dingo11Author Commented:
richie
That did not do it.

I don't know if guys have command utilities but I am quite anxious to have a gui to use them.
d
0
 
vinnyd79Commented:
I just tried my last comment with sdelete.exe and it worked fine.

I put a textbox called Text1 and a command button Called Command1 on a form and then I put the arguments in Text1
and clicked the button and the file was deleted.
0
 
Richie_SimonettiIT OperationsCommented:
wath is the 1 in the shellexecute argument?
0
 
vinnyd79Commented:
Richie has a point,shouldn't it be "-p 1" ? And why did you include the sFiletoDelete string inside the quotes with the argument?
0
 
dingo11Author Commented:
Vin,
I think Richie is asking you what is Space(1) for.

incl the sfiletodelete was a mistake
0
 
vinnyd79Commented:
I'm sure Richie knows what Space(1) is for. He is asking you what the "1" is in the shellexecute argument.
0
 
Richie_SimonettiIT OperationsCommented:
then, shellex...
should be
ret = ShellExecute(Me.hwnd, "open", sCommand, chr$(34) & sFiletoDelete & chr$(34), vbNullString, vbNormal)
?
0
 
dingo11Author Commented:
Yes I guess he does... thats why I am asking and you two are answering.

the first argument in sdelete is passes, the default is 1.
0
 
vinnyd79Commented:
if 1 is the default and you are not using any of the other arguments such as -q or -z,then you do not need to specify the "1". But wasn't the whole point of the question how to pass arguments specified in a Textbox?
0
 
Richie_SimonettiIT OperationsCommented:
so,
ret = ShellExecute(Me.hwnd, "open", sCommand, chr$(34) & text1.text & chr$(34), vbNullString, vbNormal)
??
or

dim sh as object
set sh =createobject("wscript.shell")
sh.run sCommand & " " & chr$(34) & text1.text & chr$(34)
??

run command of wscript is like if you write command line in Start, Execute
0
 
dingo11Author Commented:
vinny,
I just ran the program at the prompt. -p etc are part of the argument. Leaving out -q displays results. I cannot seem to follow leaving out -s for folders.

Tone is not easily conveyed it print - you seem annoyed?

I guess the point is sometimes depending upon the situation and/or program, I will use this for other programs besides sdelete I may or may not want to run a parameter.
d
0
 
vinnyd79Commented:
Im not sure what you mean by the -s for folders.I just tried -s and it deleted the folder and all files and subfolders within.Is that what you are looking to do?

I was just asking a question,Im not annoyed at all.
Just trying to help.

Vinny

0
 
dingo11Author Commented:
vinny
-s seems a mandatory argument to delete a folder
sdelete -p 3 -q Folder_A
doesn't work
sdelete -p 3 -q test.txt
works

d

0
 
dingo11Author Commented:
vinny
-s seems a mandatory argument to delete a folder
sdelete -p 3 -q Folder_A
doesn't work regarless if it has contents or not
d
0
 
vinnyd79Commented:
d,
Yes,it does seem -s is mandatory argument for sdelete to delete a folder.
0
 
dingo11Author Commented:
vinny,
I wasn't paying attention to detail. This worked perfectly. Thanks,
d
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 9
  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now