<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title> &#187; Visual Basic Scripting</title>
	<atom:link href="http://www.richstevenson.com/category/visual-basic-scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.richstevenson.com</link>
	<description></description>
	<lastBuildDate>Thu, 22 Dec 2011 18:41:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Map Windows drives based on group membership</title>
		<link>http://www.richstevenson.com/2009/03/31/map-windows-drives-based-on-group-membership/</link>
		<comments>http://www.richstevenson.com/2009/03/31/map-windows-drives-based-on-group-membership/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 23:00:21 +0000</pubDate>
		<dc:creator>Rich Stevenson</dc:creator>
				<category><![CDATA[Visual Basic Scripting]]></category>
		<category><![CDATA[Windows Servers]]></category>

		<guid isPermaLink="false">http://www.richstevenson.com/?p=157</guid>
		<description><![CDATA[Need a way to map a network share for a user, based on security group membership? It&#8217;s pretty easy and can be done with just a few lines of code. Using a Visual Basic Script, you can map a drive to a Windows share based on whether or not the authenticating Active Directory user is [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsensestart--><br />
Need a way to map a network share for a user, based on security group membership? It&#8217;s pretty easy and can be done with just a few lines of code. Using a Visual Basic Script, you can map a drive to a Windows share based on whether or not the authenticating Active Directory user is a member of a specific security group.<br />
<span id="more-157"></span><br />
In this example, I have an Active Directory group named acct and I want the members of that group to have the share located at \\server01\acct mapped using the drive letter Q. The text in <span style="color: #ffff99;">yellow</span>, represents where you modify this script to accommodate your environment.</p>
<p>&#8216;Set the variable ACCT to the group name acct<br />
<span style="color: #800000;"><code>Const <span style="color: #ffff99;">ACCT</span> = "cn=<span style="color: #ffff99;">acct</span>"</code></span></p>
<p>&#8216;Access to network resources.<br />
<span style="color: #800000;"><code>Set wshNetwork = CreateObject("WScript.Network")</code></span></p>
<p>&#8216;Network drive mapping info.<br />
<span style="color: #800000;"><code>Set EnuDrives = wshNetwork.EnumNetworkDrives()</code></span></p>
<p>&#8216;For checking group memberships<br />
<span style="color: #800000;"><code>Set ADSysInfo = CreateObject("ADSystemInfo")<br />
Set CurrentUser = GetObject("LDAP://" &amp; ADSysInfo.UserName)</code></span></p>
<p>&#8216;Prevents an error if user is not a member of any groups.<br />
<span style="color: #800000;"><code>If IsArray(CurrentUser.MemberOf) Then<br />
&nbsp;&nbsp;strGroups = LCase(Join(CurrentUser.MemberOf))<br />
Else<br />
&nbsp;&nbsp;strGroups = LCase(CurrentUser.MemberOf)<br />
End If</code></span></p>
<p>&#8216;This block first checks if the user is a member of<br />
&#8216;the ACCT group. If yes, then it checks for an existing<br />
&#8216;map using Q, if it finds one, it is disconnected and Q is<br />
&#8216;mapped to the \\server01\acct share.<br />
<code><span style="color: #800000;">If InStr(strGroups, <span style="color: #ffff99;">ACCT</span>) Then<br />
&nbsp;&nbsp;For i = 0 To EnuDrives.Count - 1 Step 2<br />
&nbsp;&nbsp;&nbsp;&nbsp;If LCase(EnuDrives.Item(i)) = "q:" Then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wshNetwork.RemoveNetworkDrive "q:", True, True<br />
&nbsp;&nbsp;&nbsp;&nbsp;End If<br />
&nbsp;&nbsp;Next<br />
&nbsp;&nbsp;wshNetwork.MapNetworkDrive "q:", "<span style="color: #ffff99;">\\server01\acct</span>"<br />
End If</span></code></p>
<p>Now just copy the above script and paste it into a text editor such as Notepad and name it with an .vbs extension. Double clicking the the file runs the script and you should see the Q: drive mapped to your specified share as long as you are a member of your specified group.<br />
<!--adsensestart--></p>
<g:plusone href="http://www.richstevenson.com/2009/03/31/map-windows-drives-based-on-group-membership/"  size="standard"   count="false"  ></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://www.richstevenson.com/2009/03/31/map-windows-drives-based-on-group-membership/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

