LISTING 1:RasPerms.vbs Option Explicit ' Force variable declarations for safety! Dim objArguments, objHash, objRAS, arg, cSwitch, Messages, nMsgIndex Messages = Array("Dialin Permission Enabled (specified Call Back settings changed).",_ "Dialin Permission Disabled (specified Call Back settings unchanged).",_ "No Change (s=0|1 switch not specified).") BEGIN CALLOUT A (Delete the Callout names for final version) ' Check command-line argument collection. If the user doesn't specify any arguments or the first ' argument contains a question mark, call the Usage subroutine. Set objArguments = WScript.Arguments If(objArguments.Count = 0) Then Call Usage() ElseIf(InStr(objArguments(0), "?")) Then Call Usage() End If END CALLOUT A BEGIN CALLOUT B 'Create Dictionary object to store arguments in switch=value pairs. Set objHash = CreateObject("Scripting.Dictionary") For Each arg in objArguments cSwitch = LCase(Left(arg,1)) If (cSwitch = "h") Then objHash.Add "h", (Split(arg, "=", 2, 1))(1) End If If (cSwitch = "u") Then objHash.Add "u", (Split(arg, "=", 2, 1))(1) End If If (cSwitch = "s") Then objHash.Add "s", (Split(arg, "=", 2, 1))(1) End If If (cSwitch = "t") Then objHash.Add "t", (Split(arg, "=", 2, 1))(1) End If If (cSwitch = "n") Then objHash.Add "n", (Split(arg, "=", 2, 1))(1) End If Next END CALLOUT B BEGIN CALLOUT C ' If the user specified a host name and username, create an NTAccess.RAS object and ' initialize its Server and User properties with the values in the Dictionary object. If the user failed to ' specify a host name or a username, echo an error message. If(objHash.Exists("h") And objHash.Exists("u")) Then Set objRAS = CreateObject("NTAccess.RAS") objRAS.Server = objHash("h") objRAS.User = objHash("u") Else WScript.Echo "ERROR: h=\\Hostname and u=Username switches mandatory." WScript.Quit(0) End If END CALLOUT C ' Change the target user's RAS permissions to match the Dictionary object's values. If(objHash.Exists("s")) Then objRAS.Dialin = objHash("s") If(objRAS.Dialin) Then If(objHash.Exists("t")) Then objRAS.CallBackType = objHash("t") End If If((objHash.Exists("n")) And (objRAS.CallBackType = 2)) Then objRAS.CallBack = objHash("n") End If nMsgIndex = 0 Else nMsgIndex = 1 End If Else nMsgIndex = 2 End If BEGIN CALLOUT D ' Echo an appropriate message to the user. Message depends on the actions the script took. WScript.Echo Messages(nMsgIndex) & vbNewLine & vbNewLine &_ "Username: " & objRAS.User & vbNewLine &_ "Server Name: " & objRAS.Server & vbNewLine &_ "Dialin: " & objRAS.Dialin & vbNewLine &_ "Call Back Type: " & objRAS.CallBackType & vbNewLine &_ "Call Back Number: " & objRAS.CallBack END CALLOUT D ' Clean up and exit. Set objArguments = Nothing Set objHash = Nothing Set objRAS = Nothing WScript.Quit(1) ' Usage subroutine. Sub Usage() WScript.Echo "Usage:" & vbNewLine & vbNewLine &_ "c:\> wscript | cscript rasperms.vbs h=\\Hostname u=Username" &_ vbNewLine &_ "[ s=0 | 1 ] [ t=1 | 2 | 4 ] [ n=""(123) 456-7890"" ]" &_ vbNewLine & vbNewLine &_ "h=\\Hostname: Mandatory host name where the target account resides." &_ vbNewLine & vbNewLine &_ "u=Username: Mandatory switch which specifies the target user account." &_ vbNewLine & vbNewLine &_ "s=0 | 1: s=0 disables RAS permissions -or- s=1 enables RAS permissions." &_ vbNewLine &_ "If no s= argument is supplied, current RAS settings are echoed." &_ vbNewLine & vbNewLine &_ "t=1 | 2 | 4: Optional switch that sets Call back type where:" &_ vbNewLine &_ "t=1: No Call Back" &_ vbNewLine &_ "t=2: Preset To: (Telephone number set by n= switch)" &_ vbNewLine &_ "t=4: Set By Caller" &_ vbNewLine & vbNewLine &_ "n=""(nnn) nnn-nnnn"": Optional switch that sets the Call Back telephone" &_ vbNewLine &_ "number associated with the Preset To: Call Back setting." &_ vbNewLine & vbNewLine &_ "Note: The s=1 switch must be specified to change Call Back settings." WScript.Quit(0) End Sub