• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 728
  • Last Modified:

How to tell if ntbackup is currently executing

What are the parameters to use with FindWindow to tell if ntbackup is executing? I shell ntbackup from my application and need to know when it completes.
0
DJudd
Asked:
DJudd
  • 4
  • 3
  • 3
1 Solution
 
_nn_Commented:
I would use

  FindWindow("CMainBackupApp", NULL);

But, are you sure there isn't a better method ? What language are you using ?
0
 
DJuddAuthor Commented:
I was wanting to find a method, but just thought of this at first. Do you have a better idea?

I am using VB. For FindWindow() where do you find the "class" signatures to look for? For example, VB is ThunderForm, Word is OpusApp and Notepad is Notepad. You just gave me CMainBackupApp.

Thanks!
0
 
DJuddAuthor Commented:
I just tried this in VB and it didn't work. This is the code:

    Dim hWnd As Long
    Dim sClassName As String
    Dim sWindow As String

    sClassName = "CMainBackupApp" & Chr$(0)
    sWindow = Chr$(0)
    hWnd = FindWindow(sClassName, Null)
    If hWnd > 0 Then
      BringWindowToTop hWnd
    End If

Thanks!
0
Industry Leaders: 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!

 
_nn_Commented:
There's a companion tool in Visual Studio called Spy++.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcug98/html/_asug_home_page.3a_.spy.2b2b.asp

I guess you must have it too. There's a search tool, drop it on a running instance of NtBackup. Then check the properties of that window, at the 'Class' tab, you'll find the classname.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcug98/html/_asug_searching_for_a_window.asp
0
 
cookreCommented:
Never having been happy with window titles, I'd lean to shelling out a PSLIST and parsing its output.
0
 
_nn_Commented:
I'm no VB coder : isn't there any way to shell and wait ?
or instead of shelling ntbackup directly, maybe try with something like "start /wait ntbackup <options>" ?
0
 
DJuddAuthor Commented:
I haven't tried the start /wait option above, but will research it.

I have used Spy minimally in the past, but not recently. I don't have any experience with PSList, but will research that.

I program in C, C++ (not much MFC) and C# too, so if you anyone has a solution, I can probably parse it to VB. I suppose I can try it. I think you just pass in 0 for NULL in VB, so I will try that too. The problem is that I need to get my shelled ntbackup process, not any other (although this is unlikely, I have to provide for this occurring).

Thanks for the responses so far, but I still don't have a solution to the original problem. If I find one (I usually do) I will post, and will keep checking this board for further responses.

Thanks!
0
 
_nn_Commented:
This is C/C++ :

    HWND hWnd = FindWindow("CMainBackupApp", NULL);

It works on my W2K box with

  Microsoft Windows Backup
  Version 5.0
  © 1999 VERITAS Software Corporation. All rights reserved.

Possibly, you need to use another classname for another version. Using Spy++ (or any other similar tool) should give you that classname.
0
 
cookreCommented:
nn:
The VB Shell() is asynchronous, but at least it returns the PID.  But then you have to use the regular API functions to check on the PID, so you might as well use CreateProcess() to begin with.

djudd: I meant to say TLIST instead of PSLIST (which is TSLIST on steroids)

TLIST is in the resource kit.
Sample output:
   0 System Process  
   8 System          
 144 SMSS.EXE        
 168 CSRSS.EXE      
 164 WINLOGON.EXE    
 216 SERVICES.EXE    
 228 LSASS.EXE      
 408 svchost.exe    
 444 spoolsv.exe    


PSLIST is from:
http://www.systeminternals.com/ntw2k/freeware/pslist.shtml
0
 
cookreCommented:
Just came across this VB bit from:
http://www.vb-helper.com/howto_shell_wait.html

that acts like a synchronous Shell():

' Start the indicated program and wait for it
' to finish, hiding while we wait.
Private Sub ShellAndWait(ByVal program_name As String, _
    ByVal window_style As VbAppWinStyle)
Dim process_id As Long
Dim process_handle As Long

    ' Start the program.
    On Error GoTo ShellError
    process_id = Shell(program_name, window_style)
    On Error GoTo 0

    ' Hide.
    Me.Visible = False
    DoEvents

    ' Wait for the program to finish.
    ' Get the process handle.
    process_handle = OpenProcess(SYNCHRONIZE, 0, process_id)
    If process_handle <> 0 Then
        WaitForSingleObject process_handle, INFINITE
        CloseHandle process_handle
    End If

    ' Reappear.
    Me.Visible = True
    Exit Sub

ShellError:
    MsgBox "Error starting task " & _
        txtProgram.Text & vbCrLf & _
        Err.Description, vbOKOnly Or vbExclamation, _
        "Error"
End Sub
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now