+ Post New Thread
Results 1 to 2 of 2
Scripts Thread, vbscript arguements ? in Coding and Web Development; I have this script : Code: Option Explicit Dim StrUserName, objNetwork, user, pass, strprofile Set objNetwork = CreateObject("Wscript.Network") strUserName = ...
  1. #1

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,796
    Thank Post
    3,306
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365

    vbscript arguements ?

    I have this script :

    Code:
    Option Explicit
    Dim StrUserName, objNetwork, user, pass, strprofile
     
    Set objNetwork = CreateObject("Wscript.Network")
    strUserName = objNetwork.UserName
    Select Case strUserName
     
    Case "UserOne":
     
    Call check("M:","\\server\Marketing")
     
    Case "UserTwo":
     
    Call check("M:","\\server\Marketing")
     
    Case Else:
     
    Call check("K:","\\dc\company")
    Call cs("S:","\\server\share",false,"username","password")
    Call check("Z:","\\dc\mitn")
     
    End Select
     
     
     
    'Example for strDriveLetter and strRemotePath replacing drive letter and remote path with relevant paths
    'strDriveLetter = "W:"
    'strRemotePath = "\\alan\drivers"
     
    
    Public Function check(ByRef strDriveLetter, ByRef strRemotePath)
    Set objNetwork = CreateObject("Wscript.Network")
    Dim CheckDrive, AlreadyConnected, intDrive
    Set CheckDrive = objNetwork.EnumNetworkDrives()
    ' This section deals with a For ... Next loop
    ' See how it compares the enumerated drive letters
    ' with strDriveLetter
    On Error Resume Next
    AlreadyConnected = False
    For intDrive = 0 To CheckDrive.Count - 1 Step 2
    If CheckDrive.Item(intDrive) = strDriveLetter Then
    AlreadyConnected = True
    End If
    Next
    ' This section uses the If = then, else logic
    ' This tests to see if the Drive is already mapped.
    ' If yes then disconnects
    Select Case AlreadyConnected
    Case "True":
    objNetwork.RemoveNetworkDrive strDriveLetter
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    Case "False":
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    End Select
    End Function
     
    Public Function cs(ByRef strDriveLetter, ByRef strRemotePath, ByRef prof, ByRef User, ByRef Pass)
    Set objNetwork = CreateObject("Wscript.Network")
    Dim CheckDrive, AlreadyConnected, intDrive
    Set CheckDrive = objNetwork.EnumNetworkDrives()
    ' This section deals with a For ... Next loop
    ' See how it compares the enumerated drive letters
    ' with strDriveLetter
    On Error Resume Next
    AlreadyConnected = False
    For intDrive = 0 To CheckDrive.Count - 1 Step 2
    If CheckDrive.Item(intDrive) = strDriveLetter Then
    AlreadyConnected = True
    End If
    Next
    ' This section uses the If = then, else logic
    ' This tests to see if the Drive is already mapped.
    ' If yes then disconnects
    Select Case AlreadyConnected
    Case "True":
    objNetwork.RemoveNetworkDrive strDriveLetter
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, strprofile, user, pass
    Case "False":
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, strprofile, user, pass
    End Select
    End Function
    I have duplicated the check function and renamed it to cs because there is one drive that needs credentials to be able to connect to it.

    What I want to know is what do I have to do to be able to use the first check function and get rid of the second one and still be able to map a network drive both ways ie with or without credentials and the profile set to false ??

  2. #2

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 307 Times in 243 Posts
    Rep Power
    115

    Re: vbscript arguements ?

    what do I have to do to be able to use the first check function and get rid of the second one
    It's probably not what you want, but the best answer is to eliminate the need to map S: drive via another set of credentials.

SHARE:
+ Post New Thread

Similar Threads

  1. VBScript / SQL Server
    By Gatt in forum Scripts
    Replies: 7
    Last Post: 23rd September 2011, 03:21 PM
  2. VBScript Error
    By sqdge in forum Scripts
    Replies: 20
    Last Post: 13th September 2007, 03:34 PM
  3. another VBScript question!
    By StewartKnight in forum Coding
    Replies: 4
    Last Post: 3rd May 2007, 05:41 PM
  4. VBScript
    By StewartKnight in forum Coding
    Replies: 5
    Last Post: 1st May 2007, 11:04 AM
  5. Printer vbscript ?
    By mac_shinobi in forum Scripts
    Replies: 1
    Last Post: 14th September 2005, 08:21 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •