How to get the current path using VBScript

To get the current path using VBScript you can use the snippet below.

Samples

VBScript Sample

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to get the current Database and Log Filesize using MSSQL

To get the current Database and Log Filesize using MSSQL you can use the snippet below. Tested using SQL Server 2012.

Sample MSSQL

with database_files_CTE as
(
    select
        name, type_desc, physical_name, size_mb = convert(decimal(11, 2), size * 8.0 / 1024),
        space_used_mb = convert(decimal(11, 2), fileproperty(name, 'spaceused') * 8.0 / 1024) from sys.database_files
)
select name,type_desc as [type],physical_name as [path],size_mb as [Filesize],space_used_mb as [Filesize used],
case size_mb when 0 then 0 else convert(decimal(5, 2), space_used_mb / size_mb * 100) end as [Filesize used %]  from database_files_CTE;

Sample Output

Query Results Filesizes

Please rate this snippet

How to get current Domain of the PC in C# and VB.NET

To get current Domain of the PC in C# and VB.NET you can use the snippet below.

Sample C#

using System;
using System.DirectoryServices.ActiveDirectory;

namespace de.Fesslersoft.DomainTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var myDomain = Domain.GetComputerDomain();
            foreach (DomainController dc in myDomain.DomainControllers)
            {
                Console.WriteLine("{0} - {1}", dc.IPAddress, dc.Name);
            }
            Console.Read();
        }
    }
}

Sample VB.NET

Imports System.DirectoryServices.ActiveDirectory

Namespace de.Fesslersoft.DomainTest
	Class Program
		Private Shared Sub Main(args As String())
			Dim myDomain = Domain.GetComputerDomain()
			For Each dc As DomainController In myDomain.DomainControllers
				Console.WriteLine("{0} - {1}", dc.IPAddress, dc.Name)
			Next
			Console.Read()
		End Sub
	End Class
End Namespace

Please rate this snippet

How to get the Month name of a Datetime in C# and VB.NET

To get the Month name of a Datetime in C# and VB.NET you can use the following snippet.

Sample C#

Console.WriteLine(new DateTime(2010, 1, 1).ToString("MMM", CultureInfo.InvariantCulture)); //Jan
Console.WriteLine(new DateTime(2010, 1, 1).ToString("MMMM", CultureInfo.InvariantCulture)); //January

Sample VB.NET

Console.WriteLine(New DateTime(2010, 1, 1).ToString("MMM", CultureInfo.InvariantCulture))
'Jan
Console.WriteLine(New DateTime(2010, 1, 1).ToString("MMMM", CultureInfo.InvariantCulture))
'January

Please rate this snippet

How to get monday date of current week in MSSQL

To get the Monday date of the current week you can use the snippet below.

SELECT DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0) AS Monday

Please rate this snippet

How to get selected value of dropdownlist using JavaScript

To get selected value of dropdownlist using JavaScript you can use the following snippet.

Sample Javascript

var dropDown = document.getElementById("MyDropDownId");
var dropdownValue = e.options[e.selectedIndex].value; //get the value
var dropdownText = e.options[e.selectedIndex].text; //get the text

Please rate this snippet

How to get the executable filename in C# and VB.NET

To get the executable filename in C# and VB.NET you can use one the following methods.

Sample C#

//prefered way to retrieve exe filename
Console.WriteLine(Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName));
 

Console.WriteLine(AppDomain.CurrentDomain.FriendlyName); //can cause problems when using click once, also this property does not always returns the right result.

Console.WriteLine(Path.GetFileName(Assembly.GetExecutingAssembly().Location)); //can fail when used in wcf application.
Console.WriteLine(Path.GetFileName(Assembly.GetExecutingAssembly().CodeBase)); //better if shadow copy feature is active, but can fail when used in wcf application
Console.WriteLine(Path.GetFileName(Assembly.GetEntryAssembly().Location));

Sample VB.NET

'prefered way to retrieve exe filename
Console.WriteLine(Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName))


Console.WriteLine(AppDomain.CurrentDomain.FriendlyName)
'can cause problems when using click once, also this property does not always returns the right result.
Console.WriteLine(Path.GetFileName(Assembly.GetExecutingAssembly().Location))
'can fail when used in wcf application.
Console.WriteLine(Path.GetFileName(Assembly.GetExecutingAssembly().CodeBase))
'better if shadow copy feature is active, but can fail when used in wcf application
Console.WriteLine(Path.GetFileName(Assembly.GetEntryAssembly().Location))

Please rate this snippet

How to get current cpu usage in C# and VB.NET

To get current cpu usage in C# and VB.NET you can use the following snippet.

Sample C#

public static string GetCurrentCpuUsage()
{
	var cpuCounter = new PerformanceCounter
	{
		CategoryName = "Processor",
		CounterName = "% Processor Time",
		InstanceName = "_Total"
	};
	cpuCounter.NextValue();
	System.Threading.Thread.Sleep(1000);
	return (cpuCounter.NextValue() + "%");
}

Sample VB.NET

Public Shared Function GetCurrentCpuUsage() As String
	Dim cpuCounter = New PerformanceCounter() With { _
		Key .CategoryName = "Processor", _
		Key .CounterName = "% Processor Time", _
		Key .InstanceName = "_Total" _
	}
	cpuCounter.NextValue()
	System.Threading.Thread.Sleep(1000)
	Return (cpuCounter.NextValue() + "%")
End Function

Please rate this snippet