Skip to content

Instantly share code, notes, and snippets.

View drewchapin's full-sized avatar

Drew Chapin drewchapin

View GitHub Profile
@drewchapin
drewchapin / HTML Application.hta
Last active June 9, 2022 02:23
Template for an HTML Application file (.hta), add to C:\Windows\ShellNew, and add ShellNew\Filename="HTML Application.hta" to .hta HKCR key.
<html>
<head>
<!--
@tag hta:application
@attribute ApplicationName Sets the name of the HTA.
@attribute Border [Thick]|Thin|None
@attribute BorderStyle [Normal]|Raised|Sunken|Complex|Static
@attribute Caption [Yes]|No
@drewchapin
drewchapin / List-MismatchedSIP.ps1
Created August 1, 2018 18:24
List users with mismatches msRTCSIP-PrimaryUserAddress and proxyAddresses attributes.
Import-Module ActiveDirectory
$users = Get-ADUser -Server dc01.drewchapin.com -Properties proxyAddresses,msRTCSIP-PrimaryUserAddress
# -Filter { physicalDeliveryOfficeName -eq "Location Name" }
ForEach( $user in $users )
{
$sip1 = $user.'msRTCSIP-PrimaryUserAddress'
$sip2 = $user.proxyAddresses | Where { $_ -like "SIP:*" }
@drewchapin
drewchapin / SendEmail.vbs
Created July 3, 2018 21:16
VBScript to send an email without using Outlook
Sub SendEmail( fromAddress, toAddress, subject, body )
On Error Resume Next
Dim Email
Set Email = CreateObject("CDO.Message")
Email.From = fromAddress
Email.To = toAddress
Email.Subject = subject
Email.TextBody = body
Email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.google.com"
@drewchapin
drewchapin / BrokenLinks.bas
Last active September 26, 2022 06:37
List broken hyperlinks in Excel
@drewchapin
drewchapin / ThisAddin.cs
Last active September 26, 2022 06:38
IWin32Window implementation to allow VSTO addins to access Excel's main window.
using System.Reflection;
using System.Windows.Forms;
namespace MyExcelAddin
{
public partial class ThisAddIn
{
public Win32Window MainWindow { get; set; }
@drewchapin
drewchapin / ControlsOfType.cs
Created December 12, 2017 02:37
Returns all child and grandchild controls of of the specified type.
/// <summary>
/// Returns all child and grandchild controls of of the specified type.
/// </summary>
/// <typeparam name="T">Type of control to look for</typeparam>
/// <param name="parent">Parent to get list of controls from</param>
/// <returns></returns>
public static IEnumerable<T> ControlsOfType<T>( this Control parent ) where T : Control
{
foreach( Control child in parent.Controls )
{
@drewchapin
drewchapin / ControlDoubleBuffering.cs
Created December 12, 2017 02:36
Turns on or off double buffering for controls that do not expose the property.
/// <summary>
/// Turns on or off double buffering for controls that do not expose the property.
/// </summary>
public static void DoubleBuffered( this Control control, bool value )
{
Type type = control.GetType();
PropertyInfo info = type.GetProperty("DoubleBuffered",BindingFlags.Instance|BindingFlags.NonPublic);
info.SetValue(control,value,null);
}
@drewchapin
drewchapin / SaveColumnSettings.cs
Last active September 26, 2022 06:41
Extension methods to save/load column settings to/from the current user registry for a DataGridView control.
/// <summary>
/// Generate a backslash separated path showing parent\child\grandchild relationship.
/// </summary>
public static string GeneratePath( this Control control )
{
string path = control.Name;
for( Control parent = control.Parent; parent != null; parent = parent.Parent)
path = String.Format("{0}\\{1}",parent.Name,path);
return path;
}
static int Update( SqlConnection sql, DataTable table, string tableName = null )
{
int count = 0;
tableName = tableName ?? table.TableName;
if( String.IsNullOrWhiteSpace(tableName) ) throw new NullReferenceException("tableName cannot be null or empty");
if( sql.State != ConnectionState.Open )
sql.Open();
using( SqlCommand cmd = sql.CreateCommand() )
{
List<string> keys = table.PrimaryKey.Select(x=>x.ColumnName).ToList();
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;
namespace ActiveDirectoryExTest
{