Announcement

Collapse
No announcement yet.

control dsa.msc by script (was: Is it possible?)

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • control dsa.msc by script (was: Is it possible?)

    Is it possible with vbscript to pass a distinguished name such as

    CN=.All Users Harefield Site,OU=RBH Distribution lists,OU=User Management,DC=int,DC=rbht,DC=nhs,DC=uk

    to the Active Directory Users and Computers snap in application and cause this application to open and goto this object?

    if at all possible please can you send me a sample script to

    EMAIL REMOVED!!!!

    Thanks
    Last edited by danielp; 5th September 2007, 22:06.

  • #2
    Re: Is it possible?

    H. Ghelani do you know what a forum is? It is not about just sending a request and let do others (all independed) spend hours to answer your question, and let them send all answers to your personal emailaddres oneway ticket. Hey what did you think???

    Forums are also there for visitors searching for questions and answers that could solve a problem they have, or visit these forums to enhance their knowledge.
    Now this forum in particular has 'forum rules' to help us making this forum a quality knowlegedbase.

    As a member you have to read the rules before sending in questions or answers;
    http://forums.petri.com/announcement.php?f=26



    * Can you Edit the subject title, to something like "control dsa.msc by script"

    * Remove your email address from your question

    * And next time, before sending a question choose the right forum. You sent this question to the 'Active Directory' forum, but technically it has noting to do with AD. Technically you are looking for the vbs-code to start- and navigate through a particular mmc snap-in, so this question should have been asked in the scripting forum.


    \Rems
    Last edited by Rems; 6th September 2007, 14:13.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Is it possible?

      I don't think users can change the titles to their threads... but otherwise I'm with you all the way.


      Tom
      For my own and your protection, I do not provide support by private message under any circumstances. All such messages will be deleted and ignored.

      Anything you say will be misquoted and used against you

      Comment


      • #4
        Re: Is it possible?

        Originally posted by Stonelaughter View Post
        I don't think users can change the titles to their threads
        I.c. (I thought there was an *advanced edit* button after you hit the normal edit button).

        Well I think after 'hg363' was willing to edit the question, then one of the forum moderators possibly is willing to help him changing the topic? And to move this thread to the scripting forum.

        btw 'hg363' I think 'it is possible' (referring to the question).


        \Rems

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: control dsa.msc by script (was: Is it possible?)

          Originally posted by hg363 View Post
          Is it possible with vbscript to pass a distinguished name such as

          CN=.All Users Harefield Site,OU=RBH Distribution lists,OU=User Management,DC=int,DC=rbht,DC=nhs,DC=uk

          to the Active Directory Users and Computers snap in application and cause this application to open and goto this object?

          if at all possible please can you send me a sample script to

          EMAIL REMOVED!!!!

          Thanks
          Here is an example:
          Code:
          ' name  : OpenInADUC.vbs
          ' author: Remco Simons [NL] 2007
          '
          ' ( http://forums.petri.com/showthread.php?t=18179 )
          '=======================================================================
          '
          ' This scripts accepts;
          ' 1. names from the command-line (place the complete distinguishedname(s) between quotes) 
          ' 2. Or, hardcoded distinguishedname in this script (at line 19)
          ' 3. Or, input via inputbox (not use quotes here)
          '
          'note:
          ' Never use "commas" (,) and "equals" (=) and "dQuotes" (") when you name items
          ' in Active Directory. Because this will cause future query problems.
          '(this script asumes there aren't any of these signs used in names!)
          
          'comment' the next line if you prefere to use the inputbox
          HardCoded = "CN=.All Users Harefield Site,OU=RBH Distribution lists,OU=User Management,DC=int,DC=rbht,DC=nhs,DC=uk"
          
          strMMC      = "%WinDir%\system32\dsa.msc"
          'Just in case of language differences? these two extra variables;
          strProcName = "Active Directory Users and Computers"  '<= Title shown in TaskManager (Case-sensitive!)
          strADUCRoot = "Active Directory Users and Computers"  '<= Shown in ADUC as the root
          
          
          'input: distinguished name of the object to open
          ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
          If wscript.arguments.count > 0 Then
           If wscript.arguments.count > 1 Then
            For n = 0 to wscript.arguments.count -1
             oPath = wscript.arguments(n)
             OpenInADUC(oPath)
            Next
            With CreateObject("WScript.Shell")
             If n > 0 Then
              Wscript.sleep 100
              .AppActivate(strProcName)
              If .AppActivate(strProcName) then _
               .SendKeys "(% )":Wscript.sleep 5
              .AppActivate(strProcName)
              If .AppActivate(strProcName) then _
               .SendKeys "N"
             End If
            End With
            Wscript.quit
           Else
            oPath = wscript.arguments(0)
           End If
          Else 'hard coded':
            oPath = HardCoded '(line 19)
          End If
          Do until Instr(UCASE(oPath), "DC=")
           oPath = InputBox(VBNewLine & VBNewLine & VBNewLine _
                   & "Enter Distinguished Name:","Open In ADUC  ~Full path required~","")
           If oPath = Cancel  Then  WScript.Quit
          Loop
          ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
          
          OpenInADUC(oPath)
          
          wscript.quit
          
          
          Sub OpenInADUC(oPath)
          ' Set objOU = GetObject("GC://" & oPath)  'If your computer can't bind to the GC then replace with: LDAP
          Set objOU = GetObject("LDAP://" & oPath)
          '------------------------------------------------
          ' 1) determine domainname from path
          ' 2) Set path to forward lookup notation
          '------------------------------------------------
          arrOUs = Split(objOU.distinguishedname, ",")
          
           For i = 0 To Ubound(arrOUs)
          
             If Not UCase(Left(arrOUs(i), 3)) = "DC=" Then
               If i = 0 then 
                 arrOUsRev = Mid(arrOUs(0), 4)
               Else
                 arrOUsRev = Mid(arrOUs(i), 4) & "," & arrOUsRev
               End If
          
             Else
               sDomain =  sDomain & "." & Mid(arrOUs(i), 4) 
             End If
          
           Next
          
          '------------------------------------------------
          ' 1) Start DSA.msc
          ' 2) send keystrokes to the logged-on session for browsing
          '------------------------------------------------
          sL = 25 
          Set objShell = CreateObject("WScript.Shell")
          sDomain = Trim(Mid(sDomain,2))
          
          'check if already started
          objShell.AppActivate strProcName
          If Not objShell.AppActivate(strProcName) then
             errorReturn = objShell.Run("mmc.exe """ & strMMC & """", 1, False)
             strNew = True
          Else
             If n < 1 Then
              objShell.AppActivate(strProcName)
              If objShell.AppActivate(strProcName) then _
               objShell.SendKeys "~"
             End If
          End If
          
          If strNew AND Not errorReturn then 
             Do until objShell.AppActivate(strProcName)
               wscript.sleep 250
               objShell.AppActivate strProcName
             Loop
          End If
          
             wscript.sleep sL
             objShell.AppActivate strProcName
             If objShell.AppActivate(strProcName) then _
              objShell.SendKeys strADUCRoot
          
             wscript.sleep sL
             objShell.AppActivate strProcName
             If objShell.AppActivate(strProcName) then _
              objShell.SendKeys "{LEFT}"
          
             wscript.sleep sL
             objShell.AppActivate strProcName
             If objShell.AppActivate(strProcName) then _
              objShell.SendKeys "{RIGHT}"
          
             wscript.sleep sL
             objShell.AppActivate strProcName
             If objShell.AppActivate(strProcName) then _
              objShell.SendKeys sDomain
          
          'Browse to the object
          arrOUs = split(arrOUsRev, ",")
          For i = 0 To  Ubound(arrOUs)
             strOU = Trim(arrOUs(i))
          
             wscript.sleep sL
             objShell.AppActivate strProcName
             If objShell.AppActivate(strProcName) then _
             objShell.SendKeys "{RIGHT}"
          
             wscript.sleep sL
             objShell.AppActivate strProcName
             If objShell.AppActivate(strProcName) then _
             objShell.SendKeys strOU
          
          Next
          
          '------------------------------------------------
          'Open the Properies Windows of the object
          '------------------------------------------------
             wscript.sleep sL + 500
             objShell.AppActivate strProcName
             If objShell.AppActivate(strProcName) then _
              objShell.SendKeys "(%A)":wscript.sleep 5
             objShell.AppActivate strProcName
             If objShell.AppActivate(strProcName) then _
              objShell.SendKeys "R"
             wscript.sleep sL + 10
          End Sub
          There is a chance that you have to fine-tune the script for your system, but I think it will be OK.

          The nice thing of this script is when you use the command-line (or a shortcut) option, you can pass as many DNs you like the same time. Each full distinguishedname is a parameter, each parameter must be between quotes on the command-line.


          \Rems


          EDIT - - - - - - - - - -
          how this script handles the input;
          The script will always use the parameters if there are any. If there are none, then it checks for a hardcoded DN.
          If still no complete DN was found automaticaly an Inputbox will appear, the script will then only use the manualy entered DN.

          I mensioned that you can also use a ShortCut to pass more DNs BUT there is a limitation of characters that a shortcut can save, so use a Batch-file instead;
          < @start wscript.exe "path\scriptname.vbs" "parameter" "parameter" "parameter" >

          Modifications:
          I slowed down the browsing speed of the script in ADUC a tiny bit:
          added line 111: wscript.sleep 250
          edited line 92: sL = 5 to: sL = 25

          (other values you could try to increase when the script has trouble openig the properties of multiple objects are at lines 36, 156 and 163 )


          - - just a thought - -
          An other way to pass objects to this script is by using an AD search.
          When starting the script it will automaticaly create a vbDictionary containing the names (or any other attribute you like to search in) and the DNs of all the common object-types ( query string: (&(|(objectCategory=computer)(objectCategory=contact)(objectCategory=container)(objectCategory=group)(objectCategory=organizationalUnit)(objectCategory=user))) )
          An Inputbox shows up asking you for a cName. It searches the dictionary to get the DN and opens all the objects with duplicate names in ADUC for you.
          Again the same Inputbox shows up for a next round to look for another name until you press Cancel.

          of course, the script has to write to a log too, because the properties of a object alone does not reveal its path in active directory.

          -2nd edit-
          btw... to find *any* duplicate names in active directory, just let the script compare every cName in the vbDictionary to all the other names in the dictionary in a loop, if record count within a loop is >1 then popup the names and DNs (or OpenInADUC or write to file).
          Or you can save the complete dictionary to a txt file and use Log Parser to analyse the log.
          Last edited by Rems; 20th November 2007, 17:07.

          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment


          • #6
            Re: control dsa.msc by script (was: Is it possible?)

            Here is something that does not give a complete solution to the OP's question, but is a nice to know: you can pass the RDN of the container/OU to the dsa.msc to make it open at the OU/container you specify:

            Code:
            dsa.msc /server:mydc01 /rdn=ou=dev
            Note that the RDN of the container does not contain the domain part - ADU&C will append by itself.
            Guy Teverovsky
            "Smith & Wesson - the original point and click interface"

            Comment

            Working...
            X