VB Script to bypass case sensitive AD user name

Author Message
jbis

  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 12/6/2011
  • Status: offline
VB Script to bypass case sensitive AD user name Tuesday, December 06, 2011 4:51 AM (permalink)
0
[Helpful answer received] / [List Solutions Only]
I have a script where the user enters an AD user name, the script then creates the AD user's network folder, set's his/her NTFS permission and last creates the share using the folder name.  This script is shown below.  My problem is with case sensitivity.  If the user enters "smithj" when in AD the user is entered "SmithJ", then the script returns an error.  How can I add vb script to bypass this problem, where the script would continue since a match was found? 
 
Here is my script: 
 
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click 
' BUTTON 14 for DOM Create folder and set permissions 
' Set server/drive name and ask for user name 
ServName = "MyServer" 
objFSO = CreateObject("Scripting.FileSystemObject") 
objShell = CreateObject("Wscript.shell") 
FolderName = InputBox("Please enter the user name in the same format as the network name ( DO NOT ENTER THE DOM- ). Example: SmithJ", "Folder Name for New Share") 
 
'entered an empty value 
If FolderName = "" Then 
MsgBox("You have entered nothing, please enter the user name") 
Else 
 
'retrieve user name 
objDomain = GetObject("WinNT://DOMAIN") 
objDomain.Filter = ("User") 
blnFound = False 
For Each Me.objuser In objDomain 
If Me.objuser.Name = "DOM-" & FolderName Then blnFound = True 
Exit For 
End If 
Next 
 
'user does not exist  
If blnFound <> True Then  
MsgBox("The user account DOM-" & FolderName & " does not exist in the domain, therefore please use a valid user name.")  
 
'user exists, but so does folder 
ElseIf objFSO.FolderExists("\\" & ServName & "\" & "volume_U\" & FolderName) Then 
MsgBox("The folder already exists, please enter another user name") 
Else 
OKProceed = MsgBox("You have entered " & FolderName & ". A folder by that name will be created and access granted to DOM-" & FolderName & ". Is this correct? ", vbYesNo, "User Name for creation of Share / Folder") 
If OKProceed = "6" Then 
 
' Create folder 
If objFSO.FolderExists("\\" & ServName & "\" & "volume_U\" & FolderName) Then 
objFolder = objFSO.GetFolder("\\" & ServName & "\" & "volume_U\" & FolderName) 
MsgBox("ERROR, folder already exists, or you have cancelled. Not creating the folder: \volume_U\" & FolderName & " on " & ServName) 
Else 
objFSOCF = CreateObject("Scripting.FileSystemObject") 
objFolder = objFSOCF.CreateFolder("\\" & ServName & "\" & "volume_U\" & FolderName) 
 
' Set NTFS Permissions 
strHomeFolder = "\\MyServer\volume_U\" & FolderName 
objShell = CreateObject("Wscript.Shell") 
objFSO = CreateObject("Scripting.FileSystemObject") 
If objFSO.FolderExists(strHomeFolder) Then 
 
' Assign user permission to home folder 
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " _ & strHomeFolder & " /e /t /c /g DOM-" & FolderName & ":C ", 2, True) 
If intRunError <> 0 Then 
WScript.Echo("Error assigning permissions for user " _ & strUser & " to home folder " & strHomeFolder) 
End If 
End If 
MsgBox("Success" & vbNewLine & "Server name: " & ServName & vbNewLine & "Folder name created: U:\" & FolderName & vbNewLine & "Permissions set for: DOM-" & FolderName & " " & vbNewLine & vbNewLine & "Please Create share now. " & vbNewLine) 
End If 
Else 
MsgBox("User Abort") 
End If 
End If 
End If 
End Sub 
 
 
<message edited by jbis on Tuesday, December 06, 2011 6:22 AM>
 
#1
    Wakawaka

    • Total Posts : 456
    • Scores: 23
    • Reward points : 0
    • Joined: 8/27/2009
    • Status: offline
    Re:VB Script to bypass case sensitive AD user name Tuesday, December 06, 2011 8:18 AM (permalink)
    0
    [This post was marked as helpful]
    If you are seeking vbscript, you can use UCase or LCase to convert the string to all lower or upper case.  If this is .net, the string class has the .ToUpper and .ToLower methods.  It also houses a .Contains method that might suit you.
     
    vbs
     If UCase(user) = UCase(adUser) Then... 

     
    vb.net
     If user.ToUpper = adUser.ToUpper Then.... If String.Contains(user, adUser) Then.... 

     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • 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
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9