Solved

How to tell if ntbackup is currently executing

Posted on 2003-10-30
10
718 Views
Last Modified: 2012-05-04
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
Comment
Question by:DJudd
  • 4
  • 3
  • 3
10 Comments
 
LVL 16

Expert Comment

by:_nn_
ID: 9652535
I would use

  FindWindow("CMainBackupApp", NULL);

But, are you sure there isn't a better method ? What language are you using ?
0
 

Author Comment

by:DJudd
ID: 9652580
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
 

Author Comment

by:DJudd
ID: 9652613
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 16

Expert Comment

by:_nn_
ID: 9653248
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
 
LVL 22

Expert Comment

by:cookre
ID: 9653259
Never having been happy with window titles, I'd lean to shelling out a PSLIST and parsing its output.
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9653303
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
 

Author Comment

by:DJudd
ID: 9654125
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
 
LVL 16

Expert Comment

by:_nn_
ID: 9654194
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
 
LVL 22

Expert Comment

by:cookre
ID: 9655279
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
 
LVL 22

Accepted Solution

by:
cookre earned 250 total points
ID: 9655831
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
A short article about problems I had with the new location API and permissions in Marshmallow
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

809 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