Monday, June 20, 2011

vbs loginscript actions based on ip range

Here’s an example:

On Error Resume Next

' #################################################
'Select the number of characters on the left that need to be checked
' Note the following situations:
'  10.150.9.    <-- check on charleft=9 including trailing "."!
'  10.150.10
'  10.150.11
' or
'  10.150.99.   <-- check on charleft=10 including trailing "."!
'  10.150.100
'  10.150.101
Const charleft = 10
' #################################################

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" & ".\root\default:StdRegProv")
Set WSHShell = CreateObject("Wscript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"

oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys
    DHCPAddress = WSHShell.RegRead("HKLM" & strKeyPath & subkey & "\DhcpIPAddress")
	'Skip disconnected adapters and apipa addresses (failed dhcp)
	If DHCPAddress <> "0.0.0.0" And Left(DHCPAddress,3) <> "169" Then
		'wscript.echo "Interface " + subkey + " = " + DHCPAddress
		TestOctet1 = left(DHCPAddress, int(charleft))
		Select Case TestOctet1
			case "10.150.123"
			'location A with 1 ip range
			WScript.Echo "this is location A"
			'actions for location A
			WSHNetwork.AddWindowsPrinterConnection "\\printserver\main_printer_location_A"
			WSHNetwork.MapNetworkDrive "L:", "\\NT2000\data_location_A"

			case "10.150.99.","10.150.101"
			'location B with 2 ranges, note the first range with trailing "." because it's shorter
			WScript.Echo "this is location B"
			'actions for location A
			WSHNetwork.AddWindowsPrinterConnection "\\printserver\main_printer_location_B"
			WSHNetwork.MapNetworkDrive "L:", "\\NT2000\data_location_B"

			case "192.168.2","10.150.102","10.234.234"
			'location C with 3 ranges
			WScript.Echo "this is location C"
			'actions for location A
			WSHNetwork.AddWindowsPrinterConnection "\\printserver\main_printer_location_C"
			WSHNetwork.MapNetworkDrive "L:", "\\NT2000\data_location_C"

			case "10.22.164","10.22.165"
			'location D with 2 ranges
			WScript.Echo "this is location D"
			'actions for location A
			WSHNetwork.AddWindowsPrinterConnection "\\printserver\main_printer_location_D"
			WSHNetwork.MapNetworkDrive "L:", "\\NT2000\data_location_D"

		End Select
	End If
Next
  1. layar138 alternatif

    Sunday, May 10, 2026 at 11:06:18

    Howdy just wanted to give you a quick heads up. The words in your post seem to be running off the screen in Opera.
    I’m not sure if this is a format issue or something to do with browser compatibility but I figured I’d post to let you know.
    The layout look great though! Hope you get the issue solved soon. Many
    thanks

  2. subur88 alternatif

    at 13:05:43

    I really like what you guys are up too. This type of clever work and reporting!

    Keep up the awesome works guys I’ve you guys to my own blogroll.

  3. penipu

    Saturday, May 23, 2026 at 11:21:42

    Hey there! I’ve been reading your site for a long time now and finally got the
    bravery to go ahead and give you a shout out from Houston Texas!
    Just wanted to say keep up the great work!

  4. Https://dailyseolinks.com/

    Tuesday, June 23, 2026 at 09:58:26

    Hello there, just became alert to your blog through Google, and found that it is truly informative.
    I am going to watch out for brussels. I will be grateful if you continue this
    in future. Many people will be benefited from your writing.
    Cheers!

  5. Buy Usa Proxies

    Sunday, June 28, 2026 at 23:52:28

    Good info. Lucky me I recently found your website
    by chance (stumbleupon). I have saved it for later!

  6. 变性人肛交变性人变性人交变性人交变性人肛交变性人交变性人变性人内射变性人内射变性人亚洲海妖

    Friday, July 3, 2026 at 13:08:21

    领先的成人网站 为成熟观众提供优质内容。探索 安全中心 以确保质量和隐私。

  7. subur88

    Friday, July 17, 2026 at 02:34:19

    Hello just wanted to give you a quick heads up
    and let you know a few of the pictures aren’t loading properly.
    I’m not sure why but I think its a linking
    issue. I’ve tried it in two different web browsers and both show the same
    results.

  8. watch top porn videos

    Thursday, July 23, 2026 at 12:52:42

    Top xxx sites bieden veilige en premium inhoud voor volwassenen. Ontdek veilige sites
    voor een kwaliteitservaring.

  9. web traffic

    Tuesday, August 18, 2026 at 02:47:15

    Appreciation to my father who told me about this webpage, this web
    site is actually amazing.

  10. watch anal porn

    Monday, August 31, 2026 at 02:18:09

    Adult wweb platforms offer a variety oof videos for
    adupt entertainment. Opt for trusted web sources for a
    ssafe experience.

  11. WATCH ANAL PORN

    Tuesday, September 1, 2026 at 07:25:44

    Adult content site offers a range oof videos for adult entertainment.

    Select secure adult sitds for a safe experience.

Add comment

Fill out the form below to add your own comments