Photo Gallery
Member List
Search
Calendars
FAQ
Ticket List
Log Out
Forums
Register
Login
My Profile
Inbox
Address Book
My Subscription
My Forums
Map network drives based on ip-subnets
Logged in as: Guest
arrSession:exec spGetSession 2,16,50118
Active Users: There are
0
members and
0
guests.
Users viewing this topic: none
Printable Version
All Forums
>>
[Scripting]
>>
Post a VBScript
>> Map network drives based on ip-subnets
Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page:
[1]
Login
Message
<< Older Topic
Newer Topic >>
Map network drives based on ip-subnets -
7/29/2007 11:08:11 PM
geezery
Posts: 22
Score: 0
Joined: 5/28/2007
Status:
offline
I needed this kind of script for one of my projects and it could be useful for someone else too.
Const TemporaryFolder = 2 Const ForAppending = 8 Dim ObjShell : Set ObjShell = CreateObject("WScript.Shell") Dim Objfso : Set Objfso = CreateObject("Scripting.FileSystemObject") Dim TmpFile : TmpFile = Objfso.GetSpecialFolder(2) & "/ip.txt" Dim ThisLine, IP Set WSHNetwork = CreateObject("Wscript.Network") ObjShell.run "%comspec% /c ipconfig > " & TmpFile, 0, True With Objfso.GetFile(TmpFile).OpenAsTextStream Do While NOT .AtEndOfStream ThisLine = .ReadLine 'For Windows Vista If InStr(ThisLine, "IPv4") <> 0 Then IP = Mid(ThisLine, InStr(ThisLine, ":") + 2) 'For Windows XP If InStr(ThisLine, "IP-") <> 0 Then IP = Mid(ThisLine, InStr(ThisLine, ":") + 2) Loop .Close End With If IP <> "" Then If Asc(Right(IP, 1)) = 13 Then IP = Left(IP, Len(IP) - 1) End If Dim Array, Subnet Array = Split(IP, ".", -1, 1) If Array(2) = "" Then MsgBox("There is some problems with the network settings!") End If Subnet = Array(0) & "." & Array(1) & "." & Array(2) Set Objfso = Nothing Dim StrUserName, strPassword 'Username that have rights to shares. Change theselines strUserName = "Admin" strPassword = "AdminPassword" 'Here comes the Select Case portion Select Case Subnet Case "192.168.1" WSHNetwork.MapNetworkDrive "j:", "\\Server01\Distribution" ,False, strUsername, strPassword 'Case "192.168.2" 'WSHNetwork.MapNetworkDrive "y:", "\\Server02\Distribution" ,False, strUsername, strPassword End Select
< Message edited by
geezery
--
7/29/2007 11:10:49 PM
>
Revisions: 1
|
Post #: 1
RE: Map network drives based on ip-subnets -
7/31/2007 2:29:52 PM
dm_4ever
Posts: 2174
Score: 32
Joined: 6/29/2006
From: Orange County, California
Status:
offline
This is another way to get the same info without having to write to a text file first. Should work on WinXP or greater.
Option Explicit Test() Sub Test Dim arrIP : arrIP = Split(ResolveIP("it-laptop"), ".") Dim strSubnet : strSubnet = arrIP(0) & "." & arrIP(1) & "." & arrIP(2) Select Case strSubnet Case "192.168.1" WScript.Echo "192.168.1" Case "192.168.2" WScript.Echo "192.168.2" Case "192.168.3" WScript.Echo "192.168.3" End Select End Sub Function ResolveIP(strComputer) Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Dim wmiQuery : wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strComputer & "'" Dim objPing : Set objPing = objWMIService.ExecQuery(wmiQuery) Dim objStatus For Each objStatus in objPing ResolveIP = objStatus.ProtocolAddress Next End Function
_____________________________
dm_4ever
My philosophy:
K.I.S.S - Keep It Simple Stupid
Read Me:
http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff:
http://www.visualbasicscript.com/m_47117/tm.htm
(in reply to
geezery
)
Post #: 2
If you found our site useful please link to us
<a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>
.
All Forums
>>
[Scripting]
>>
Post a VBScript
>> Map network drives based on ip-subnets
Page:
[1]
Jump to:
Select a Forum
All Forums
----------------------
[Welcome]
- - Forum Rules
- - Test Posting Messages
- - New Member Area/Introduction
[Scripting]
- - WSH & Client Side VBScript
- - WSH & Client Side VBScript Tutorial
- - Post a VBScript
- - Windows PowerShell
- - ASP
- - ASP.NET
- - Windows Script Components
[General Forum]
- - Other Programming/Scripting Languages
- - Suggestions & Feedback
- - Off-Topic Lounge
New Messages
No New Messages
Hot Topic w/ New Messages
Hot Topic w/o New Messages
Locked w/ New Messages
Locked w/o New Messages
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
Forum Software ©
ASPPlayground.NET
Advanced Edition
2.5.5 ANSI