RestartNetwork() - Restart "Local area connection" without admin privileges

Post your working scripts, libraries and tools
tmplinshi
Posts: 1432
Joined: 01 Oct 2013, 14:57

RestartNetwork() - Restart "Local area connection" without admin privileges

29 Jun 2019, 10:54

Code: Select all

/*
	Restart "Local area connection" without admin privileges

	Example: RestartNetwork("Local area connection")

	If ConnectionName is omited, the adapter name that contains "Realtek PCIe" will be selected.
*/
RestartNetwork(ConnectionName := "") {

	oShell := ComObjCreate("Shell.Application")
	oShell.Open("::{7007ACC7-3202-11D1-AAD2-00805FC1270E}") ; Open Network Connections

	FolderName := oShell.Namespace(0x31).Title

	; Find "Network Connections" window
	Loop
	{
		Sleep, 200

		for oWin in oShell.Windows
		{
			if ( oWin.LocationName = FolderName )
			&& ( oWin.LocationURL = "" )
			&& ( InStr(oWin.FullName, "\Explorer.EXE") )
				Break, 2
		}
	}

	oFolder := oWin.Document.Folder

	for item in oFolder.Items
	{
		devName := oFolder.GetDetailsOf(item, 2)

		if (item.name = ConnectionName)
		|| (ConnectionName = "" && InStr(devName, "Realtek PCIe"))
		{
			if InStr(item.Verbs.Item(0).Name, "&B")
			{
				item.InvokeVerb("disable")
				Sleep, 1000
			}

			item.InvokeVerb("enable")
			break
		}
	}
	
	oWin.Quit
}

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Cuadrix, DataLife, hasantr, kczx3 and 36 guests