Microsoftee

I'm writing a C# application that uses NTBACKUP utility to backup and restore, I successfully backuped up using NTACKUP command line but command line doesn't support restore as written in NTBACKUP docs.

Now to restore I'm running NTBAKUP process from my application and controlling it by sending messages to its window using Win32API. I've done all of the things but stuck in a TreeView control where I've to check its checkboxes to select items to restore in the bacup catalog. I even able to expand tree, get the specified tree node and selected it but couldn't able to check its checkbox, when I send the "TVM_SETITEM" message to TreeView to check the TreeView item the NTBACKUP utility crashes with the message "An unhandled win32 exception occured in ntbackup.exe". The code I'm using to check the TreeView checkbox is taken from a Microsoft knowledge base article http://support.microsoft.com/kb/313134 and its correct.

Here is the code I'm using to check the checkbox

SendMessage((int)hwndTree, (int)Win32API.WindowsMessages.TVM_EXPAND, (int)TVM_EXPAND_wParam.TVE_EXPAND, (IntPtr)hItm);
hItm = TreeView_GetChild(hwndTree, hItm);

// Got the specified TreeView item selected by this function call, so, it means handle to the item (hItm) is correct
SendMessage(hwndTree, (int)TV_Messages.TVM_SELECTITEM, (int)TVM_GETNEXTITEM_wParam.TVGN_CARET, (IntPtr)hItm);


// Initializing TVITEM structure with appropriate values
TVITEM tvItm = new TVITEM();
tvItm.hItem = (IntPtr)hItm;
tvItm.mask = TVIF_HANDLE | TVIF_STATE;
tvItm.state = (uint)(2 << 12);
tvItm.stateMask = TVIS_STATEIMAGEMASK;

// Initialize the rest to zero.
tvItm.pszText = (IntPtr)0;
tvItm.cchTextMax = 0;
tvItm.iImage = 0;
tvItm.iSelectedImage = 0;
tvItm.cChildren = 0;
tvItm.lParam = (IntPtr)0;

// Send the TVM_SETITEM message.
// TVM_SETITEM = 4365
SendMessage((IntPtr)hwndTree, (UInt32)TVM_SETITEM, (UInt32)0, ref tvItm);

regards,

Adil



Re: Windows SDK TreeView TVM_SETITEM message

Paul Marriott

I dont think you will be able to do this with SendMessage sending a structure, as when the message gets to the ntbackup program, the (LPARAM)ptr will have no relevance to it, as it is a memory block in your apps memory space, not in ntbackups memory space. The SendMessage method will only work if it is passing values in wparam and lparam and not pointers.

To do what you are doing, i.e pass memory between programs WM_COPYDATA is used, but that can not be used to a treeview as far as I am aware.





Re: Windows SDK TreeView TVM_SETITEM message

Microsoftee

Paul,

I understood your point, the Microsoft KB example is doing it in the same process but I'm doing in separate process space.

How can I achieve my objective can you or someone else looking into guide me with steps, API calls or sample code to do this task.

regards,

Adil





Re: Windows SDK TreeView TVM_SETITEM message

AndyCadley

The only way to do this (that I've ever heard of) is to script it using SendKeys. That's an incredibly fragile approach though and hence generally not something you want to do when restoring data. I'd strongly recommend using an alternative backup solution that is designed to perform automated backup and restore.





Re: Windows SDK TreeView TVM_SETITEM message

Microsoftee

Andy,

Thanks for your reply, I've actually almost done with everything in application except the restore. The reason I'm using NTBACKUP for this solution is, it uses Volume Shadow Copy to copy files even when Windows is running and most of the files are in use and locked and it takes System State backup that restores all settings, user accounts, registry, even the user's passwords as it was before crash.

Is there any other third party backup solution in your knowledge that restores the exact Windows OS state

I tried sending BN_CLICKED, WM_KEYDOWN, WM_KEYUP messages to TreeView and to specific Tree Item but couldn't able to check the item checkbox. Can you guide me how can I check the checkbox by sending "Space" key or "Click" message to TreeView.

regards,

Adil