Saturday, January 28, 2012

Reading & Writing registry key using C#


Reading registry key :


try
{
    RegistryKey registry = Registry.LocalMachine.CreateSubKey("SOFTWARE\\myKey");
    if (registry != null)
   {
      MessageBox.Show(registry.GetValue("myValue").ToString());
      registry.Close();
    }
}
catch (Exception ex)
{
   MessageBox.Show (ex.ToString());
}

Writing registry key :



try
{
RegistryKey registry = Registry.LocalMachine.CreateSubKey("SOFTWARE\\myKey");
if (registry != null)
{
registry.SetValue("myValue", "myReturnValue");
registry.Close();
}
}
catch (Exception ex)
{
MessageBox.Show (ex.ToString());
}

Wednesday, October 12, 2011

Extracting backgound image from powerpoint slide using c#


PowerPoint.Application objApp;
PowerPoint.Presentations objPresSet;
PowerPoint._Presentation objPres;

objApp = new PowerPoint.Application();
objPresSet = objApp.Presentations;

objPres = objPresSet.Open("G:\\temp.ppt", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue);

int SlideCount = objPres.Slides.Count;
int FirstSlideId = objApp.ActiveWindow.Selection.SlideRange.SlideID;

for (int j = FirstSlideId; j < FirstSlideId + SlideCount; j++)
{
      objPres.Slides.FindBySlideID(j).Master.Background.Export("C:\\img" + j + ".jpg",
      Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatJPG, 800, 600,
      Microsoft.Office.Interop.PowerPoint.PpExportMode.ppScaleToFit);     // Exporting Slide Background                                                          
}