Results 1 to 7 of 7

Thread: DOS VS VB

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    49
    Is it possible to send parameter from dos to visual basic,
    EXAMPLE: when formatting a A: drive in dos, can you follow the execution in visual basic with a progressbar

  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    I think u can

    shell the formatting
    get a handle on the process
    loop with doevents
    and progress bar while the handle is still active...


    If you HAVE TO DO THIS, we can talk further

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    49
    i just wanted to no, how do u follow the process with DoEvents
    example
    shell format a:
    and then......
    thanxs my friend

  4. #4
    Guest
    I assume that with the DoEvents you are only able to check whether or not a process is in progress. This would imply that a progress bar (showing the % completion) might not be what you want.

    Perhaps some kind of animated cursor would be more applicable? There seem to be millions of them out there.

    Good Luck
    DerFarm

  5. #5
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    ok

    try this for me...
    Let me know if it works

    Create your own Shell function as follows
    then invoke it

    ShellWait "format a:" or whatever u do
    and put a progress bar on your form
    and simulate the progress of the format

    I tested this with a command button on my form executing
    in its click event
    MsgBox IIf(ShellWait(Text1.Text) = True, "Done!", "Cannot execute this command")


    Public Function ShellWait(cCommandLine As String) As Boolean
    Dim NameOfProc As PROCESS_INFORMATION
    Dim NameStart As STARTUPINFO
    Dim i As Long

    ShellWait = False

    NameStart.cb = Len(NameStart)
    i = CreateProcessA(0&, cCommandLine, 0&, 0&, 1&, _
    NORMAL_PRIORITY_CLASS, 0&, 0&, NameStart, NameOfProc)

    Do
    'Here do your own progress bar simulation!
    DoEvents: progressbar1.Value = progressbar1.Value + 1

    Loop While i = 0

    Call WaitForSingleObject(NameOfProc.hProcess, INFINITE)
    Call CloseHandle(NameOfProc.hProcess)
    ShellWait = True 'Indicating completion

    End Function

    Put these in your declaration module

    Private 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

    Private Declare Function CloseHandle Lib "kernel32" (hObject As Long) As Boolean

    Private Declare Function WaitForSingleObject Lib "kernel32" _
    (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

    Private Declare Function CreateProcessA Lib "kernel32" _
    (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, _
    ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
    ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
    ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
    lpStartupInfo As STARTUPINFO, _
    lpProcessInformation As PROCESS_INFORMATION) As Long

    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Private Const INFINITE = -1&

    Private Type STARTUPINFO
    cb As Long
    lpReserved As String
    lpDesktop As String
    lpTitle As String
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Long
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
    End Type

    Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessId As Long
    dwThreadID As Long
    End Type

    good luck

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2000
    Posts
    49

    dos vs vb

    it's seem to be the right thing to do but while the commang goes to
    Do
    'Here do your own progress bar simulation!
    DoEvents: ProgressBar1.Value = ProgressBar1.Value + 1
    Loop While i = 0

    Call WaitForSingleObject(NameOfProc.hProcess, INFINITE)
    Call CloseHandle(NameOfProc.hProcess)
    ShellWait = True 'Indicating completion
    MsgBox "fini"

    it's always equal to 1, so it never goes in the Do command!!

    thanxs

  7. #7
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    hmm

    Shell a different app like notepad or something like that
    and see if i is always 1...

    Could it be that the format is so fast that
    there is no chance to follow the progrss bar?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width