Sign in to follow this  
Followers 0
lil754boy

Elevate a portion of script to use domain username and password when logged on local

6 posts in this topic

Is there a way or how can i elevate a portion of my auto it script to elevate and use domain username and password for a portion of the script. The code below has to be run as a domain administrator. The script is a script used in the unattended portion of the script after the machine joins. I am trying complete make the image a zero touch for user. If i can do this, the image will be complete with zero touch by admin and the user can login. I could image machines from my desk and once it comes up to the login screen the user can login.

I have tried to create a separate .exe and use RunAs but have not been able to make it work, please help.

If $sPCType = "Laptop" OR $strChassisType = 13 Then

$sMember_dn = "CN=" & @computerName & ",OU=Laptops,DC=apsk12,DC=org"

$strGroupDN = "CN=Wireless Clients,OU=Security Groups,DC=apsk12,DC=org"

MsgBox(0, "Domain:", $strGroupDN, 2)

$objGroup = ObjGet("LDAP://" & $strGroupDN)

MsgBox(0, "Domain:", $objGroup, 2)

$objSysInfo = ObjCreate("ADSystemInfo")

$strComputerDN = $objSysInfo.ComputerName

MsgBox(0, "Domain:", $strComputerDN, 2)

$objComputer = ObjGet("LDAP://" & $strComputerDN)

;MsgBox(0, "Domain:", $objComputer)

If ($objGroup.IsMember($objComputer.ADsPath) = False) Then

$objGroup.Add($objComputer.ADsPath)

EndIf

EndIf

Share this post


Link to post
Share on other sites



You could have a look at my Active Directory UDF (for download please see my signature). To add the user to a group use function _AD_UserToGroup. The required credentials can be passed with function _AD_Open.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I am new to autoit, I look at the UDF's but still not sure how to add them to my script and make them work.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Have a look at the example scripts which come with the UDF or the Wiki.

Your script could look like:

#include <AD.au3> ; Store the AD UDF in @ProgramFilesDir & AutoI3Include, a user defined Include directory or the directory where your script resides

_AD_Open()
If @error Then MsgBox(16, "Error", "Error connecting to Active Directory. @error: " & @error & ", @extended: " & @extended)
If $sPCType = "Laptop" Or $strChassisType = 13 Then
    $strGroupDN = "CN=Wireless Clients,OU=Security Groups,DC=apsk12,DC=org"
    If Not _AD_IsMemberOf($strGroupDN, @ComputerName & "$") Then
        _AD_AddUserToGroup($strGroupDN, @ComputerName & "$")
        If @error Then MsgBox(16, "Error", "Error occurred adding '" & @ComputerName & "' to AD group '" & $strGroupDN & "'. @error: " & @error & ", @extended: " & @extended)
    EndIf
EndIf
_AD_Close()
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I get the attached error when runninig.

#include <AD.au3>

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <EditConstants.au3>

#include <WindowsConstants.au3>

$logon_flags = 0

$striCount =0

$sWMIService = "winmgmts:\\" & @ComputerName & "\root\CIMV2"

$objWMIService = ObjGet($sWMIService)

$colChassis = $objWMIService.ExecQuery("Select * from Win32_SystemEnclosure")

For $objChassis in $colChassis

For $strChassisType in $objChassis.ChassisTypes

Select

Case $strChassisType = 1

MsgBox(0, "Chassis: ", "Other", 2)

$sPCtype = "Desktop"

Case $strChassisType = 2

MsgBox(0, "Chassis: ", "Unknown", 2)

$sPCtype = "Desktop"

Case $strChassisType = 3

MsgBox(0, "Chassis: ", "Desktop", 2)

$sPCtype = "Desktop"

Case $strChassisType = 4

MsgBox(0, "Chassis: ", "Low Profile Desktop", 2)

$sPCtype = "Desktop"

Case $strChassisType = 5

MsgBox(0, "Chassis: ", "Pizza Box" 2)

$sPCtype = "Desktop"

Case $strChassisType = 6

MsgBox(0, "Chassis: ", "Mini Tower", 2)

$sPCtype = "Desktop"

Case $strChassisType = 7

MsgBox(0, "Chassis: ", "Tower", 2)

$sPCtype = "Desktop"

Case $strChassisType = 8

MsgBox(0, "Chassis: ", "Portable", 2)

$sPCtype = "Laptop"

Case $strChassisType = 9

MsgBox(0, "Chassis: ", "Laptop", 2)

$sPCtype = "Laptop"

Case $strChassisType = 10

MsgBox(0, "Chassis: ", "Notebook", 2)

$sPCtype = "Laptop"

Case $strChassisType = 11

MsgBox(0, "Chassis: ", "Handheld", 2)

$sPCtype = "Laptop"

Case $strChassisType = 12

MsgBox(0, "Chassis: ", "Docking Station", 2)

$sPCtype = "Laptop"

Case $strChassisType = 13

MsgBox(0, "Chassis: ", "All-in-One", 2)

$sPCtype = "Laptop"

Case $strChassisType = 14

MsgBox(0, "Chassis: ", "Sub-Notebook", 2)

$sPCtype = "Laptop"

Case $strChassisType = 15

MsgBox(0, "Chassis: ", "Space Saving", 2)

$sPCtype = "Desktop"

Case $strChassisType = 16

MsgBox(0, "Chassis: ", "Lunch Box", 2)

$sPCtype = "Desktop"

Case $strChassisType = 17

MsgBox(0, "Chassis: ", "Main System Chassis", 2)

$sPCtype = "Desktop"

Case $strChassisType = 18

MsgBox(0, "Chassis: ", "Expansion Chassis", 2)

$sPCtype = "Desktop"

Case $strChassisType = 19

MsgBox(0, "Chassis: ", "Sub-Chassis", 2)

$sPCtype = "Desktop"

Case $strChassisType = 20

MsgBox(0, "Chassis: ", "Bus Expansion Chassis", 2)

$sPCtype = "Desktop"

Case $strChassisType = 21

MsgBox(0, "Chassis: ", "Peripheral Chassis", 2)

$sPCtype = "Desktop"

Case $strChassisType = 22

MsgBox(0, "Chassis: ", "Storage Chassis", 2)

$sPCtype = "Desktop"

Case $strChassisType = 23

MsgBox(0, "Chassis: ", "Rack Mount Chassis", 2)

$sPCtype = "Desktop"

Case $strChassisType = 24

MsgBox(0, "Chassis: ", "Sealed-Case PC", 2)

$sPCtype = "Desktop"

Case Else

MsgBox(0, "Chassis: ", "Unknown", 2)

$sPCtype = "Desktop"

EndSelect

Next

Next

MsgBox(0, "Desktop or laptop: ", $sPCtype, 2)

#cs

If _AD_Open($strUser, $strUser, $SDNSDomain, $SHostServer, $SConfiguration) Then

MsgBox(64, "Active Directory Functions", "Logon was succcessful!")

ElseIf @error <= 8 Then

MsgBox(16, "Active Directory Functions", "The logon was not succcessful!" & @CRLF & @CRLF & "@error: " & @error & ", @extended: " & @extended)

Else

MsgBox(16, "Active Directory Functions", "The logon was not succcessful!" & @CRLF & @CRLF & "@error: " & @error & ", @extended: " & @extended & _

@CRLF & @CRLF & "Extended error information will be displayed")

Global $aError = _AD_GetLastADSIError()

_ArrayDisplay($aError)

EndIf

#ce

_AD_Open()

If @error Then MsgBox(16, "Error", "Error connecting to Active Directory. @error: " & @error & ", @extended: " & @extended)

If $sPCType = "Laptop" Or $strChassisType = 13 Then

$strGroupDN = "CN=Wireless Clients,OU=Security Groups,DC=*******,DC=org"

If Not _AD_IsMemberOf($strGroupDN, @ComputerName & "$") Then

_AD_AddUserToGroup($strGroupDN, @ComputerName & "$")

If @error Then MsgBox(16, "Error", "Error occurred adding '" & @ComputerName & "' to AD group '" & $strGroupDN & "'. @error: " & @error & ", @extended: " & @extended)

EndIf

EndIf

_AD_Close()

post-71785-0-93862400-1347985779_thumb.p

Share this post


Link to post
Share on other sites

Which version of the AD UDF did you download? Which vesion of AutoIt do you run?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0