locked
FBWF management from c# RRS feed

  • Question

  • I'm using fbwf on a project that I'm working on.  I've been able to utilize the fbwflib.dll library to manage different aspects of write filtering to manage updates to the system.  However, I've run into a wall of sorts when trying to use the addexclusion feature either from the API or running the fbwfmgr.exe from a process object.  Both give me the same errors and just dont seem to work programatically.  Here's my code for each version:

     

    // Using API
    [DllImport( @"c:\Windows\System32\fbwflib.dll" )]
    public static extern ulong FbwfAddExclusion(
       [In] string volume,
       [In] string path );
    
    if ( NativeMethods.FbwfAddExclusion( "c:", "\MyStuff\Store" ) != (ulong)NativeMethods.FBWF_RESPOSE.NO_ERROR )
    {
       Win32Exception errorCode = new Win32Exception();
       Logging.LogError( string.Format( "InstallUpdates(): failed calling FbwfAddExclusion({0}), error code: {1}, message: {2}",
                                                             "\MyStuff\Store", errorCode, errorCode.Message ) );
    }
    
    // using process object
    
    private static void AddExclusion( string volume, string targetFolder )
    {
        try
        {
            Process addExclusionProc = new Process();
            addExclusionProc.StartInfo.UseShellExecute = false;
            addExclusionProc.StartInfo.WorkingDirectory = @"C:\Windows\System32";
            addExclusionProc.StartInfo.FileName = @"fbwfMgr.exe";
            addExclusionProc.StartInfo.CreateNoWindow = true;
            addExclusionProc.StartInfo.ErrorDialog = false;
            addExclusionProc.StartInfo.Arguments = "/addexclusion " + volume + " " + targetFolder;
    
            Logging.LogInformation( "File: " + addExclusionProc.StartInfo.FileName + " exists: " + File.Exists( addExclusionProc.StartInfo.FileName ));
    
            Logging.LogInformation( "AddExclusion(): calling " +
                                    addExclusionProc.StartInfo.FileName + " " +
                                    addExclusionProc.StartInfo.Arguments );
    
            bool started = addExclusionProc.Start();
    
            if ( !started )
            {
                string msg = string.Format( "AddExclusion(): Error, {0} failed to start with ExitCode [{1}].",
                                            addExclusionProc.StartInfo.FileName,
                                            addExclusionProc.ExitCode );
                throw new ApplicationException( msg );
            }
    
            addExclusionProc.WaitForExit( 5000 );
        }
        catch ( Exception e )
        {
            Logging.LogError( e );
        }
    }
    
    AddExclusion( "c:", "\MyStuff\Store" );
    
    

     


    Here is the error I get when I run either solution:

     

     

    The system cannot find the file specified
    
       at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
    
       at System.Diagnostics.Process.Start()
    
       at CompassCommon.PlatformInstall.AddExclusion(String volume, String targetFolder)

     


    The other interesting thing that I'm logging is where I'm calling the File.Exists function on the fbwfmgr.exe file and it's returning false.  Yet, I can go into my explore and see it just fine.  I can run it just fine with the exact same parameters but from a command prompt.  I've also played with when I create the exclude folder: before and after I call the API.

    It would be a BIG help if someone has solved this problem already since there's no sample code in the documentation to ensure that I'm calling the API correctly.  I'm having NO problems calling the following APIs:

     

    [DllImport( @"c:\Windows\System32\fbwflib.dll" )]
    public static extern ulong FbwfDisableFilter();
    
    [DllImport( @"c:\Windows\System32\fbwflib.dll" )]
    public static extern ulong FbwfEnableFilter();
    
    [DllImport( @"c:\Windows\System32\fbwflib.dll" )]
    public static extern ulong FbwfIsFilterEnabled(
        [In] ref ulong currentSession,
        [In] ref ulong nextSession );
    
    

     


    Please help if you can, thanks.

     

    matt


    • Edited by mgranic Tuesday, December 13, 2011 4:10 PM
    Monday, December 12, 2011 11:38 PM

Answers

  • Ok, after about 2 days of fighting with the managed API, I am now able to invoke the FbwfAddExclusion method.  It was a marshaling issue which I should have saw sooner, but hey, it happens sometimes.  It's just a signature update to this API:

            [DllImport( @"c:\Windows\System32\fbwflib.dll" )]

            public static extern ulong FbwfAddExclusion(

                [In] [MarshalAs(UnmanagedType.LPWStr)] string volume,

                [In] [MarshalAs(UnmanagedType.LPWStr)] string path );

    The strings must have been garbled in the API and just did not give a great message for troubleshooting.


    Matthew Granic
    • Marked as answer by mgranic Tuesday, December 13, 2011 10:08 PM
    Tuesday, December 13, 2011 10:08 PM

All replies

  • Not sure if it will help, but I have a solution from a few years back: http://www.annabooks.com/Articles/Articles_XPE/FBWF_API_NET.pdf. The latest is in the WES7 book.

    -Sean

     


    www.sjjmicro.com / www.seanliming.com / www.annabooks.com, Book Author - Pro Guide to WES 7, XP Embedded Advanced, Pro Guide to POS for .NET
    Tuesday, December 13, 2011 3:06 AM
  • Thanks for the input Sean, but I'm not really having trouble calling native APIs from managed code, since I'm making successful calls to many FBWF APIs as well as file transaction APIs.  It's possible that I have the managed->native definition wrong, but that usually gives a different error.

    I can add that we do use our own shell (vs the standard Windows shell).  I cannot explain why the calls do not seem to work or why when I perform a File.Exists() on the fbwfmgr.exe file it says it's not there when is clearly is when I bring up a command prompt in the same login/session.  

    Part of the problem is the terrible error reporting from the API.  You would think that Microsoft could add the name of the file to the error message so I could diagnose the specific problem.  The other part is that there is absolutely no sample code to reference since the parameters are not 100% clear in the documentation.

    Has anybody else had success using the FbwfAddExclusion() function?


    Matthew Granic
    Tuesday, December 13, 2011 4:09 PM
  • Sean, I've gone through your book and there are some code snippets for the APIs.  I dont think the book came with a CDROM or a link to any working code.  I'm getting pretty frustrated with this method call so I'm willing to try about anything.  Is there a link to some source that I could try or do I need to go through the different examples and piece them together?
    Matthew Granic
    Tuesday, December 13, 2011 9:55 PM
  • Ok, after about 2 days of fighting with the managed API, I am now able to invoke the FbwfAddExclusion method.  It was a marshaling issue which I should have saw sooner, but hey, it happens sometimes.  It's just a signature update to this API:

            [DllImport( @"c:\Windows\System32\fbwflib.dll" )]

            public static extern ulong FbwfAddExclusion(

                [In] [MarshalAs(UnmanagedType.LPWStr)] string volume,

                [In] [MarshalAs(UnmanagedType.LPWStr)] string path );

    The strings must have been garbled in the API and just did not give a great message for troubleshooting.


    Matthew Granic
    • Marked as answer by mgranic Tuesday, December 13, 2011 10:08 PM
    Tuesday, December 13, 2011 10:08 PM