How to set a Property Value by Name in C# and VB.NET

To set a Property Value by Name in C# and VB.NET you can use the following snippet.

Sample C#

public static bool SetPropertyByName(this Object obj, string name, Object value)
{
	var prop = obj.GetType().GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
	if (null == prop || !prop.CanWrite) return false;
	prop.SetValue(obj, value, null);
	return true;
}

Sample VB.NET

Public Shared Function SetPropertyValueByName(obj As [Object], name As String, value As [Object]) As Boolean
	Dim prop = obj.[GetType]().GetProperty(name, BindingFlags.[Public] Or BindingFlags.Instance)
	If prop Is Nothing OrElse Not prop.CanWrite Then
		Return False
	End If
	prop.SetValue(obj, value, Nothing)
	Return True
End Function

Please rate this snippet

How to reset the windows audio mixer in Batch

To reset the windows audio mixer in Batch you can use the following snippet.
This snippet will set all volume levels equal. If you know a simpler way to reset the audio mixer, without setting all volume levels manually please let us know.

Sample Batch

@ECHO OFF
ECHO Resetting Volume Mixer Settings!
NET STOP Audiosrv
NET STOP AudioEndpointBuilder
REG DELETE "HKCU\Software\Microsoft\Internet Explorer\LowRegistry\Audio\PolicyConfig\PropertyStore" /F
REG ADD "HKCU\Software\Microsoft\Internet Explorer\LowRegistry\Audio\PolicyConfig\PropertyStore"
NET START Audiosrv

Please rate this snippet