+ Post New Thread
Results 1 to 6 of 6
Scripts Thread, How to Run VBScript as a domain user in Coding and Web Development; ...
  1. #1

    Join Date
    Nov 2011
    Location
    Middlesbrough
    Posts
    41
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0

    How to Run VBScript as a domain user

    I need to run a script to add a computer to a security group however I need to run it as a domain user, I can achieve it using the two scripts below. When I run script1 which in turns runs script2 as the domain user. Ideally I’d like to run it all through one script: any help would be much appreciated:

    Script1:


    Option explicit
    Dim oShell
    set oShell= Wscript.CreateObject("WScript.Shell")
    oShell.Run "RunAs /user:domainuser@domain.local ""cscript.exe gl_student_computer_membership_part2.vbs"
    WScript.Sleep 100
    oShell.Sendkeys "domainpassword~"
    Wscript.Quit


    Part 2:

    Option Explicit
    Dim strComputerDN, objSysInfo
    Dim objComputer, objGroup

    ' Retrieve computer Distinguished Name.
    Set objSysInfo = CreateObject("ADSystemInfo")
    strComputerDN = objSysInfo.ComputerName

    ' Bind to the computer object.
    Set objComputer = GetObject("LDAP://" & strComputerDN)

    ' Bind to the group object.
    Set objGroup = GetObject("LDAP://cn=Student Computers,ou=Computers,ou=AB,ou=Groups,dc=domain,d c=local")

    ' Check if computer already a member of the group.
    If (objGroup.IsMember(objComputer.AdsPath) = False) Then
    ' Add the computer to the group.
    objGroup.Add(objComputer.AdsPath)
    End If


    Any help woudl be much appreciate

  2. #2

    jinnantonnixx's Avatar
    Join Date
    Mar 2011
    Location
    In the Calamatorium.
    Posts
    2,029
    Thank Post
    120
    Thanked 513 Times in 347 Posts
    Blog Entries
    2
    Rep Power
    288
    You could store your scripts in a scheduled task with the appropriate security credentials, but scheduled to never run (stay with me...)

    Then, when you need to, use the "schtasks /run /tn TaskName " command to run the script on demand.
    How to use Schtasks.exe to Schedule Tasks in Windows Server 2003

    SCHTASKS /Run [/S system [/U username [/P [password]]]] [/I] /TN taskname

    Description:
    Runs a scheduled task on demand.

    Parameter List:
    /S system Specifies the remote system to connect to.

    /U username Specifies the user context under
    which the schtasks.exe should execute.

    /P [password] Specifies the password for the given
    user context. Prompts for input if omitted.

    /I Runs the task immediately by ignoring any constraint.

    /TN taskname Identifies the scheduled task to run now.

    /? Displays this help message.

    Examples:
    SCHTASKS /Run /?
    SCHTASKS /Run /TN "Start Backup"
    SCHTASKS /Run /S system /U user /P password /I /TN "Backup and Restore"
    Last edited by jinnantonnixx; 12th June 2014 at 12:45 PM.

  3. #3

    Join Date
    Nov 2011
    Location
    Middlesbrough
    Posts
    41
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    I'll stay be in the same situation as I will still need to create a schedule task. Ideally if I can have it all done in the one script. Unfortunately my vbscript skills are very poor.

  4. #4

    Join Date
    Nov 2011
    Location
    Middlesbrough
    Posts
    41
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    can I deirectly run a vbscript from the commandline using schtasks /run
    if so that maybe a way forward.

  5. #5

    jinnantonnixx's Avatar
    Join Date
    Mar 2011
    Location
    In the Calamatorium.
    Posts
    2,029
    Thank Post
    120
    Thanked 513 Times in 347 Posts
    Blog Entries
    2
    Rep Power
    288
    Quote Originally Posted by ccadit View Post
    can I deirectly run a vbscript from the commandline using schtasks /run
    if so that maybe a way forward.
    Yes, the scheduled task can be a VBS, but you must call it using the full path of the script interpreter (usually cscript)
    Explained here.
    vbscript - can .vbs file be a scheduled script? - Stack Overflow

  6. #6

    jinnantonnixx's Avatar
    Join Date
    Mar 2011
    Location
    In the Calamatorium.
    Posts
    2,029
    Thank Post
    120
    Thanked 513 Times in 347 Posts
    Blog Entries
    2
    Rep Power
    288
    Much as I hate Powershell, I think it will be the preferred method for what you want to do.

    Powershell - Adding computers to a security group in Active Directory - Stack Overflow

    Of course you will need the correct security to do this, but you can run this yourself with nothing more than a list of the computers and the one line of Powershell.


    To view the group memberships of computers, Powershell is useful.
    Code:
    get-adcomputer -filter 'name -eq "name_of_computer"' -Properties memberof
    You can use wildcards
    Code:
    get-adcomputer -filter 'name -like "science*"' -Properties memberof
    Last edited by jinnantonnixx; 12th June 2014 at 03:02 PM.



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 0
    Last Post: 6th November 2012, 04:30 PM
  2. How to copy files from two domains
    By timbo343 in forum Scripts
    Replies: 5
    Last Post: 18th February 2008, 10:43 PM
  3. How To Run Sims Registers With Pre Admissions Inc?
    By schoolbunny in forum MIS Systems
    Replies: 1
    Last Post: 4th July 2007, 06:08 PM
  4. How to Message Everyone on the Domain? (easily).
    By roland in forum How do you do....it?
    Replies: 6
    Last Post: 6th June 2007, 11:36 AM
  5. how to run a registry patch on shutdown/logoff
    By The_Traveller in forum Windows
    Replies: 13
    Last Post: 20th November 2006, 09:52 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
  •