VBS login script

Discussion in 'Software' started by bubba7465, Mar 28, 2005.

  1. bubba7465

    bubba7465 Private E-2

    Everything in my script works excpet the remover network dirves I am not that great at scripting. The main part is someone elses script and works great I addes the remove drives part. Right now it is set to only remove drive z, but when the script runs i got an obeject required. Can any one help.

    Thanks


    'declare global variables here
    Option Explicit

    Dim oShell, oNet, oFSO, oWshNetwork, oGroupDict

    '-----------------
    'Objects go here

    Set oShell = CreateObject("Wscript.Shell")
    Set oNet = CreateObject("Wscript.Network")
    set oFSO = CreateObject("Scripting.FileSystemObject")


    'WshNetwork.RemoveNetworkDrive "m:"
    'WshNetwork.RemoveNetworkDrive "n:"
    'WshNetwork.RemoveNetworkDrive "o:"
    'WshNetwork.RemoveNetworkDrive "p:"
    'WshNetwork.RemoveNetworkDrive "q:"
    'WshNetwork.RemoveNetworkDrive "r:"
    'WshNetwork.RemoveNetworkDrive "s:"
    'WshNetwork.RemoveNetworkDrive "t:"
    'WshNetwork.RemoveNetworkDrive "u:"
    'WshNetwork.RemoveNetworkDrive "v:"
    'WshNetwork.RemoveNetworkDrive "w:"
    'WshNetwork.RemoveNetworkDrive "x:"
    'WshNetwork.RemoveNetworkDrive "y:"
    oWshNetwork.RemoveNetworkDrive "z:"

    '-----------------
    'all mapping and stuff is done from'here
    'you should not have to change functions
    'unless they do not work for some'reason

    Greeting()
    'you can put any combination ofcode in
    'MapDrive "z:", "\\colliers", "\test3" 'to process the function calls
    'this is just a quick example
    If IsMember("office test") Then
    MapDrive "x:", "\\colliers", "\test2"
    End If

    'MapPrinter "\\zeus", "\garbo"

    DisplayResources()
    'this is the end of the function calls
    '-----------------
    'display cheezy greeting to the user
    Function Greeting()
    Dim sTime, sDate, sMessage, sAdsPath, GreetingTime, oUser

    sTime = Hour(Now)
    sDate = Now

    If sTime <= 11 Then
    GreetingTime = "morning"
    ElseIf sTime <= 18 Then
    GreetingTime = "afternoon"
    Else
    GreetingTime = "evening"
    End If

    sMessage = VbCrLf & sDate & VbCrLf & VbCrLf
    sMessage = sMessage & "Good " & GreetingTime & " " & oNet.UserName & ","
    sMessage = sMessage & VbCrLf
    Wscript.Echo(sMessage)

    End Function

    '-----------------
    'find out what groups the user belongs too
    Function IsMember(sGroup)
    Dim sAdsPath, oUser, oGroup

    If IsEmpty(oGroupDict) Then
    Set oGroupDict = CreateObject("Scripting.Dictionary")
    oGroupDict.CompareMode = vbTextCompare

    sAdsPath = oNet.UserDomain & "/" & oNet.UserName
    Set oUser = GetObject("WinNT://" & sAdsPath & ",user")

    For Each oGroup In oUser.Groups
    oGroupDict.Add oGroup.Name, "-"
    Next

    Set oUser = Nothing
    End If

    IsMember = CBool(oGroupDict.Exists(sGroup))

    End Function

    '-----------------
    'map the drives
    Function MapDrive(Drive, FileServer, Share)

    If oFSO.DriveExists(FileServer & Share) = True Then
    oNet.MapNetworkDrive Drive, FileServer & Share
    Wscript.Echo("Mapping drive " & Drive & " to " & FileServer & Share)
    Else
    Wscript.Echo("Cannot Map " & Drive & " to " & FileServer & Share)
    End If

    End Function

    '-----------------


    '-----------------
    'little display to show the user what is mapped
    Function DisplayResources()
    Dim DriveCollection, PrinterCollection, MsgString, i

    Set DriveCollection = oNet.EnumNetworkDrives
    Set PrinterCollection = oNet.EnumPrinterConnections
    MsgString = VbCrLf & VbCrLf & "The following network resources are connected:" & VbCrLf

    For i = 0 To DriveCollection.Count - 1 Step 2
    MsgString = MsgString & VbCrLf & DriveCollection(i) & " " & DriveCollection(i + 1)
    Next

    'Wscript.Echo(MsgString)

    'MsgString = ""

    'For i = 1 To PrinterCollection.Count - 1 Step 2
    'MsgString = MsgString & VbCrLf & PrinterCollection(i)
    'Next

    Wscript.Echo(MsgString & VbCrLf)
    End Function
     
  2. Kodo

    Kodo SNATCHSQUATCH

    I see this:
    Dim oShell, oNet, oFSO, oWshNetwork, oGroupDict
    and


    Set oShell = CreateObject("Wscript.Shell")
    Set oNet = CreateObject("Wscript.Network")
    set oFSO = CreateObject("Scripting.FileSystemObject")

    But where is the set oWshnetrwork object?

    did you mean to assign oWshNetwork object to wscript.network?
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds