Jump to content

Auto Script to Cache network Credentials


Recommended Posts

I am trying to utilize a script that will provide a GUI that remote users can enter their domain user and password to cache their credentials during a OS deployment. Long story shot during the deployment a processes launches the company's VPN and establishes a network connection and joins the system to the domain, then reboots and once more establishes a network connection to the domain and I need users to be prompted to enter their AD creds to cache their creds since these a remote users. I had a script that I used many years ago but am running into errors and was looking for some help. Thank You

Attached is the script and below is the errors the that I encounter. 

 
>C:\Program Files (x86)\AutoIt3\SciTE\..\au3check.exe "C:\Users\administrator\Desktop\CacheCredentials.au3"
AutoIt3 Syntax Checker 
C:\Users\Administrator\Desktop\CacheCredentials.au3(35,11) : ERROR: _UserForm(): undefined function.
_UserForm()
~~~~~~~~~~^
C:\Users\Administrator\Desktop\CacheCredentials.au3(82,72) : ERROR: RunAs(): undefined function.
 RunAs($uname, $domain, $pword, 1, "ipconfig.exe", @SystemDir, @SW_HIDE)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Users\administrator\Desktop\CacheCredentials.au3 - 2 error(s), 0 warning(s)
>Exit code: 2    Time: 0.237

 

CacheCredentials.au3

Link to comment
Share on other sites

Ok here is the original .au3 file that I am attempting to use. I need to change it to join a remote machine in the same context as in my first post, so I need to change it to join systems to my test domain which is corp.viamonstra.com instead of the current PHYSIO domain. I have change the domain name and recompiled the code but it does not work .....

Any idea all, I would really appreciate it as I need this to work. Thanks. 

CacheCredentials_.au3

Link to comment
Share on other sites

I'm still not sure what you want?? 

The script you posted has the function _UserForm

 It runs for me but I have no way to test it for your particular circumstance??

it has been merged with au3stripper not that it matters

Here is a simpler script for you to look at. it needs converted to use 

_Crypt_EncryptData and _Crypt_DecryptData

 

this script does not run for me

Link to comment
Share on other sites

What the script does is launch a box for the user to enter there credentials during a Offline media OS deployment while there is a VPN connection to the domain so that it caches there profile so that they can log into their system with their cached Cred once the OS deployment is complete. Screen shots of the process below. 

1.PNG

2.PNG

Link to comment
Share on other sites

I'm perfectly cognizant of what it does and I ran the program to see that very same screenshot 

What does 

Quote

it does not work .....

mean??

I stripped out all the BS in the script you posted and Updated it to the latest Autoit

Make the changes you think you want and come back with how it doesn't work

and be very concise not being a scripter doesn't make you unable to communicate

#Region
    #AutoIt3Wrapper_Icon=C:\Program Files\AutoIt3\Icons\Dell.ico
    #AutoIt3Wrapper_OutFile=CacheCredentials.exe
    #AutoIt3Wrapper_UseUpx=n
    ;#AutoIt3Wrapper_UseAnsi=y
    #AutoIt3Wrapper_Res_Comment=Creates local profile and caches credentials
    #AutoIt3Wrapper_Res_Description=Caches user credentials locally on the Windows machine
    #AutoIt3Wrapper_Res_Fileversion=1.0.0.0
    #AutoIt3Wrapper_Res_LegalCopyright=Dell Inc.
    #AutoIt3Wrapper_Res_Language=1033
#EndRegion

Opt("MustDeclareVars", 1)


#include <File.au3>
#Include <Array.au3>

#include <GuiButton.au3>
#include <GuiEdit.au3>
#include <GuiComboBoxEx.au3>

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $omyerror = ObjEvent("AutoIt.Error", "ComError")


Global Const $wm_mbuttondblck = 521

Global Const $__editconstant_ws_vscroll = 2097152
Global Const $__editconstant_ws_hscroll = 1048576

Global Const $cbes_ex_pathwordbreakproc = 4
Global Const $__comboboxconstant_ws_vscroll = 2097152

Global $ss_notify, $uname, $domain, $pword, $daddrive
$domain = "PHYSIO"
Global $logfile = @ScriptDir & "\CacheCredentials.Log"
Global $modulename = "CacheCredentials"
Global $statuscode = 0
Global $statusmessage = $modulename & " completed successfully"

Global $retcode

_filewritelog($logfile, "Start " & @ScriptFullPath)
_activatewindows()
_userform()
_cachecreds()

Func _stopdad()
    Local $retcode = FileExists("dae.txt")
    If $retcode = 0 Then
        _filewritelog($logfile, "DAE.txt flag not found, will stop DAE, DAEUI and StartDAD processes for updates to take affect")
        #Region ### START Koda GUI section ### Form=p:\profile\my documents\dell dad stuff\autoit code\makeitstop\source code\daeui_form.kxf
            Local $form1_1 = GUICreate("", 1024, 768, -1, -1, BitOR($ws_maximizebox, $ws_popup, $ws_tabstop), 0)
            Local $pic1 = GUICtrlCreatePic("DAEUI.JPG", 0, 0, 1024, 768, BitOR($ss_notify, $ws_group, $ws_clipsiblings))
            GUISetState(@SW_SHOW)
        #EndRegion ### END Koda GUI section ###
        _filewritelog($logfile, "Creating DAE.txt flag to prevent stopping service again after task is rerun")
        Local $daefile = FileOpen("dae.txt", 2)
        FileClose($daefile)
        _deldaefromrunkey()
        _filewritelog($logfile, "Stopping StartDAD.exe")
        ProcessClose("StartDAD.exe")
        _filewritelog($logfile, "Stopping DAE.exe")
        ProcessClose("DAE.exe")
        _filewritelog($logfile, "Stopping DAEUI.exe")
        ProcessClose("DAEUI.exe")
        _filewritelog($logfile, "Stopping Breakout.exe")
        ProcessClose("Breakout.exe")
        _userform()
    Else
        $retcode = FileExists("profileerror.txt")
        If $retcode = 0 Then
            $retcode = FileDelete("dae.txt")
            $statuscode = 0
            $statusmessage = "Successfully completed Profile Check"
            _writestatus()
        Else
            $retcode = FileDelete("dae.txt")
            $retcode = FileDelete("profileerror.txt")
            $statuscode = 2
            $statusmessage = "Error creating profile locally"
            _writestatus()
        EndIf
    EndIf
EndFunc

Func _deldaefromrunkey()
    _filewritelog($logfile, "Removing DAE from the Run key...")
    Local $returncode = RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "DAE")
    If $returncode = 0 Then _filewritelog($logfile, "DAE Run Key did not exist in registry")
    If $returncode = 1 Then _filewritelog($logfile, "Removed DAE Run Key from registry")
    If $returncode = 2 Then _filewritelog($logfile, "Error: Removing the DAE Run Key from registry")
EndFunc

Func _adddaetorunkey()
    Local $rundad
    _filewritelog($logfile, "Adding DAE back to the Run key...")
    $rundad = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\run", "DAE")
    If $rundad = "" Then
        local $addrundad = RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "DAE", "REG_SZ", "C:\distribution\engines\task\StartDAD.exe")
        _filewritelog($logfile, "Added StartDAD.exe to HKLM\SOFTWARE\Micrsoft\Windows\CurrentVersion\Run key with return code: " & $addrundad)
    Else
        _filewritelog($logfile, "DAE key already exists in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
    EndIf
EndFunc

Func _userform()
    HotKeySet("{Enter}", "_Submit")
    #Region ### START Koda GUI section ### Form=C:\Documents and Settings\dnolfo\Desktop\ASM\Scripts\forms\password_domain.kxf
        Local $form1_1 = GUICreate("Please enter your Username and Password", 362, 265, -1, -1, BitOR($ws_caption, $ws_popup, $ws_border, $ws_clipsiblings), BitOR($ws_ex_topmost, $ws_ex_windowedge))
        Local $unamecode = GUICtrlCreateInput("", 120, 96, 193, 21)
        Local $pwordcode = GUICtrlCreateInput("", 120, 136, 193, 21, BitOR($es_password, $es_autohscroll))
        Local $label1 = GUICtrlCreateLabel("Enter Username:", 32, 100, 80, 17)
        Local $label2 = GUICtrlCreateLabel("Enter Password:", 32, 141, 78, 17)
        Local $label4 = GUICtrlCreateLabel("Please enter your Physio Username and Password", 32, 24, 296, 17)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        Local $label5 = GUICtrlCreateLabel("to initialize your profile on your new PC.", 32, 48, 296, 17)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        Local $button1 = GUICtrlCreateButton("Submit", 136, 216, 75, 25, 0)
        GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    Local $nMsg
    While 1
        $nmsg = GUIGetMsg()
        If $nmsg = $button1 Then
            $uname = GUICtrlRead($unamecode)
            $pword = GUICtrlRead($pwordcode)
            If $uname = "" OR $pword = "" Then
                GUIDelete($form1_1)
                HotKeySet("{Enter}")
                MsgBox(48, "Blank value", "Username and Password cannot be blank" & @CRLF & "Click OK to re-enter")
                _filewritelog($logfile, "Blank username or password entered, prompt again")
                _userform()
            Else
                _filewritelog($logfile, "Username and password entered. About to validate credentials...")
                GUIDelete($form1_1)
                ExitLoop
            EndIf
        EndIf
    WEnd
    HotKeySet("{Enter}")
    _uservalidate($uname, $pword)
EndFunc

Func _uservalidate($username, $password)
    SplashTextOn("Dell Automated Deployment", "Verifying username and password, please wait...", -1, 20, -1, -1, 32, "", 12)
    Local $namespace = ObjGet("WinNT:")
    Local $ads_secure_authentication = 1
    Local $domobj = $namespace.opendsobject("WinNT://" & $domain, $username, $password, $ads_secure_authentication)
    $retcode = @error
    If $retcode = 0 Then
        _filewritelog($logfile, "Credentials were verified!")
        SplashOff()
        _cachecreds()
    Else
        SplashOff()
        _filewritelog($logfile, "Could not verify entered credentials, prompt to retry or cancel")
        $retcode = MsgBox(53, "", "Could not verify credentials" & @CRLF & "Click OK to Retry")
        If $retcode = 4 Then
            _filewritelog($logfile, "Retrying, prompt again")
            _userform()
        Else
            _filewritelog($logfile, "User cancelled, start DAD and fail task")
            _filewritelog($logfile, "Write profileerror.txt flag")
            Local $pferror = FileOpen("profileerror.txt", 2)
            FileClose($pferror)
            Exit
        EndIf
    EndIf
EndFunc

Func comerror()
    If IsObj($omyerror) Then
        Local $hexnumber = Hex($omyerror.number, 8)
        SetError($hexnumber)
    Else
        SetError(1)
    EndIf
    Return 0
EndFunc

Func _cachecreds()
    SplashTextOn("Dell Automated Deployment", "Creating local profile, please wait...", -1, 20, -1, -1, 32, "", 12)
    _filewritelog($logfile, "Caching credentials...")
    RunAs($uname, $domain, $pword, 1, "ipconfig.exe", @SystemDir, @SW_HIDE)
    $retcode = @error
    _filewritelog($logfile, "Return code = " & $retcode)
    If $retcode <> 0 Then
        _filewritelog($logfile, "Error caching credentials")
        SplashOff()
    Else
        ProcessWait("ipconfig.exe", 300)
        Sleep(1000)
        ProcessClose("ipconfig.exe")
        SplashOff()
        _filewritelog($logfile, "Credentials successfully cached!")
    EndIf
EndFunc

Func _startdad()
    SplashTextOn("Dell Automated Deployment", "Restarting DAD, please wait...", -1, 20, -1, -1, 32, "", 12)
    Sleep(1000)
    _adddaetorunkey()
    _filewritelog($logfile, "Restarting MOVEMOUSE.EXE...")
    $retcode = Run($daddrive & ":\Distribution\Data\Dell\MOVEMOUSE.EXE")
    _filewritelog($logfile, "Restarting Breakout.exe...")
    $retcode = Run($daddrive & ":\Distribution\Data\Dell\Breakout.exe")
    _filewritelog($logfile, "Restarting DAE.exe...")
    $retcode = Run($daddrive & ":\Distribution\Engines\DAE\DAE.exe")
    Sleep(5000)
    SplashOff()
    Exit
EndFunc

Func _findusb()
    Local $avarray = _arraycreate("C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "W", "X")
    Local $returncode
    For $i = 0 To 21
        $returncode = FileExists($avarray[$i] & ":\distribution\engines\task\dad.ini")
        If $returncode = 1 Then
            $daddrive = $avarray[$i]
            _filewritelog($logfile, "The DAD Container was located on drive: " & $avarray[$i])
        EndIf
        If $returncode = 1 Then ExitLoop
    Next
    If $returncode = 0 Then
        $statusmessage = "Unable to locate the distribution container"
        _filewritelog($logfile, "The DAD Container was not located")
        Exit
    EndIf
    Return $daddrive
EndFunc

Func _writestatus()
    Local $date = @MON & "-" & @MDAY & "-" & @YEAR
    Local $time = @HOUR & ":" & @MIN & ":" & @SEC
    #Region *** Creates a copy of what is about to be written to the status.xml file inside of the Module log file ***
        _filewritelog($logfile, "Gathered the following module information...")
        _filewritelog($logfile, "   ModuleName:               " & $modulename)
        _filewritelog($logfile, "   Execution Date:           " & $date)
        _filewritelog($logfile, "   Execution Time:           " & $time)
        _filewritelog($logfile, "   Execution Status Code:    " & $statuscode)
        _filewritelog($logfile, "   Execution Status Message: " & $statusmessage)
    #EndRegion *** Creates a copy of what is about to be written to the status.xml file inside of the Module log file ***
    _filewritelog($logfile, "_WriteStatus function has been started")
    Local $file = FileOpen($daddrive & ":\distribution\engines\dae\status.xml", 2)
    If $file = -1 Then
        _filewritelog($logfile, "Error opening status.xml")
        $statusmessage = "Can't open status.xml for writing"
    EndIf
    FileWrite($file, "<Build>" & @CRLF)
    FileWrite($file, "     <ID>" & $modulename & "</ID>" & @CRLF)
    FileWrite($file, "     <Date>" & $date & "</Date>" & @CRLF)
    FileWrite($file, "     <Time>" & $time & "</Time>" & @CRLF)
    FileWrite($file, "     <RetCode>" & $statuscode & "</RetCode>" & @CRLF)
    FileWrite($file, "     <RetStr>" & $statusmessage & "</RetStr>" & @CRLF)
    FileWrite($file, "     <Exit>0</Exit>" & @CRLF)
    FileWrite($file, "</Build>" & @CRLF)
    FileClose($file)
    Exit
EndFunc

Func _submit()
    $retcode = ControlClick("Please enter your Username and Password", "", "[CLASS:Button; TEXT:Submit; INSTANCE:1]")
EndFunc

Func _activatewindows()
    Local $cmd, $dir
    $dir = "C:\Windows\system32"
    $cmd = $dir & "\slmgr.vbs /ato"
    ;;;RunWait('cscript "' & $cmd & '"', $dir);Doubtful that this is needed 
EndFunc

Func _arraycreate($v_0, $v_1 = 0, $v_2 = 0, $v_3 = 0, $v_4 = 0, $v_5 = 0, $v_6 = 0, $v_7 = 0, $v_8 = 0, $v_9 = 0, $v_10 = 0, $v_11 = 0, $v_12 = 0, $v_13 = 0, $v_14 = 0, $v_15 = 0, $v_16 = 0, $v_17 = 0, $v_18 = 0, $v_19 = 0, $v_20 = 0)
    Local $av_array[21] = [$v_0, $v_1, $v_2, $v_3, $v_4, $v_5, $v_6, $v_7, $v_8, $v_9, $v_10, $v_11, $v_12, $v_13, $v_14, $v_15, $v_16, $v_17, $v_18, $v_19, $v_20]
    ReDim $av_array[@NumParams]
    Return $av_array
EndFunc

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...