Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > AutoIt
You last visited: Today at 15:16

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



The script does not work

Discussion on The script does not work within the AutoIt forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Nov 2008
Posts: 12
Received Thanks: 0
The script does not work

HTML Code:
#RequireAdmin
; CreateAdminWinPE.au3
; AutoIt script to create an Administrator account on the installed (offline) Windows from Win10PE
; Method: place a batch in the target Windows\System32 and register it under HKLM\SOFTWARE\...\RunOnce of the offline hive.

Opt("MustDeclareVars", 1)
#include <MsgBoxConstants.au3>
#include <Array.au3>
#include <File.au3>

Func RunCmd($sCmd, ByRef $sOut = "")
    Local $iPID = Run(@ComSpec & " /c " & $sCmd, @SystemDir, @SW_HIDE, $STDOUT_CHILD)
    If $iPID = 0 Then Return SetError(1, 0, "")
    $sOut = ""
    While 1
        Local $s = StdoutRead($iPID)
        If @error Then ExitLoop
        $sOut &= $s
    WEnd
    ProcessWaitClose($iPID)
    Return 0
EndFunc

Local $aWindowsPaths[0]
For $drive = Asc("C") To Asc("Z")
    Local $sDrive = Chr($drive) & ":\"
    If DriveExists($sDrive) Then
        Local $sCheck = $sDrive & "Windows\System32\config\SOFTWARE"
        If FileExists($sCheck) Then
            _ArrayAdd($aWindowsPaths, $sDrive & "Windows")
        EndIf
    EndIf
Next

If UBound($aWindowsPaths) = 0 Then
    MsgBox($MB_ICONERROR, "wrong", "windows is not installed in current partitions.")
    Exit
EndIf

Local $sTargetWin
If UBound($aWindowsPaths) = 1 Then
    $sTargetWin = $aWindowsPaths[0]
Else
   ; Display a choice to the user if multiple systems are present.
    Local $sList = ""
    For $i = 0 To UBound($aWindowsPaths)-1
        $sList &= ($i+1) & " - " & $aWindowsPaths[$i] & @CRLF
    Next
    Local $sChoice = InputBox("Choose to install Windows", "Multiple installations were found. Select the installation number you want to modify:" & @CRLF & $sList, "1")
    If @error Then Exit
    If Not StringIsDigit($sChoice) Then Exit
    Local $iChoice = Number($sChoice)-1
    If $iChoice < 0 Or $iChoice >= UBound($aWindowsPaths) Then
        MsgBox($MB_ICONERROR, "wrong", "choice is not correct.")
        Exit
    EndIf
    $sTargetWin = $aWindowsPaths[$iChoice]
EndIf

; --- 2) Read username and password ---
Local $sUser = InputBox("Create an admin account (Offline)", "Enter your new username:", "NewAdmin")
If @error Or StringStripWS($sUser, 8) = "" Then Exit
Local $sPass = InputBox("Create an admin account (Offline)", "Enter your account password:", "P@ssw0rd")
If @error Or StringStripWS($sPass, 8) = "" Then Exit

If MsgBox($MB_YESNO, "confirmation", "The account will be created at: " & $sTargetWin & @CRLF & "username: " & $sUser & @CRLF & "Do you want to continue?") = $IDNO Then Exit

; --- 3) Create the batch inside the System32 folder of the target Windows ---
Local $sSys32 = $sTargetWin & "\System32"
Local $sBatchPath = $sSys32 & "\create_admin.bat"
Local $sBatch =
'@echo off' & @CRLF & _
'REM create_admin.bat - created by CreateAdminWinPE' & @CRLF & _
'chcp 65001 >nul' & @CRLF & _
'echo Creating user %USERNAME% >nul' & @CRLF & _
'net user "' & $sUser & '" "' & $sPass & '" /add' & @CRLF & _
'net localgroup Administrators "' & $sUser & '" /add' & @CRLF & _
'REM try to disable password expiry (if allowed)' & @CRLF & _
'wmic useraccount where name^="' & $sUser & '" set PasswordExpires=False >nul 2>&1' & @CRLF & _
'REM remove the RunOnce entry (RunOnce should auto-remove but we try cleanup)' & @CRLF & _
'reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v CreateAdmin /f >nul 2>&1' & @CRLF & _
'REM delete this batch' & @CRLF & _
'del "%~f0" >nul 2>&1' & @CRLF & _
'exit /b 0' & @CRLF

; attempt to write file (may require elevated rights in WinPE)
If Not DirCreate($sSys32) And Not FileExists($sSys32) Then
    MsgBox($MB_ICONERROR, "wrong", "The folder cannot be accessed: " & $sSys32)
    Exit
EndIf

Local $h = FileOpen($sBatchPath, $FO_OVERWRITE + $FO_CREATEPATH)
If $h = -1 Then
    MsgBox($MB_ICONERROR, "wrong", "File creation failed:" & $sBatchPath)
    Exit
EndIf
FileWrite($h, $sBatch)
FileClose($h)

; --- 4) load hive software for windows target to HKLM\OFFLINE ---
Local $sHive = $sTargetWin & "\System32\config\SOFTWARE"
Local $sOut = ""
RunCmd('reg load HKLM\OFFLINE "' & $sHive & '"', $sOut)
If StringInStr($sOut, "The operation completed successfully") Or StringInStr($sOut, "done") Or @error = 0 Then
    ; continue
Else
   ; reg load often does not print text but may return zero; we check for presence
EndIf

; Check that the key exists or that the load has been completed.
Local $sTestOut = ""
RunCmd('reg query "HKLM\OFFLINE\Microsoft\Windows\CurrentVersion" /v ""', $sTestOut)
If StringInStr($sTestOut, "ERROR") Then
   ; Attempt to disassemble and error condition
    RunCmd('reg unload HKLM\OFFLINE')
    MsgBox($MB_ICONERROR, "wrong", "hive software loading failed or path is invalid: " & $sHive & @CRLF & "Outputs:" & @CRLF & $sTestOut)
    Exit
EndIf

; --- 5) Add a RunOnce value to point to the batch on the next boot ---
Local $sRunOnceKey = 'HKLM\OFFLINE\Microsoft\Windows\CurrentVersion\RunOnce'
Local $sCmdAdd = 'reg add "' & $sRunOnceKey & '" /v CreateAdmin /t REG_SZ /d "' & 'C:\Windows\System32\create_admin.bat' & '" /f'
Local $sAddOut = ""
RunCmd($sCmdAdd, $sAddOut)

; Check success
If StringInStr($sAddOut, "The operation completed successfully") Or StringInStr($sAddOut, "done") Or $sAddOut = "" Then
   ;reg may not return text when successful — we'll read the key to make sure.
    Local $sCheck = ""
    RunCmd('reg query "' & $sRunOnceKey & '" /v CreateAdmin', $sCheck)
    If StringInStr($sCheck, 'CreateAdmin') Then
        MsgBox($MB_ICONINFORMATION, "done", "The batch is created and registered under RunOnce for Windows installation." & @CRLF & "Patch location: " & $sBatchPath)
    Else
        MsgBox($MB_ICONWARNING, "warning", "The RunOnce value may not have been registered successfully. Review the command output:" & @CRLF & $sAddOut)
    EndIf
Else
    MsgBox($MB_ICONERROR, "fail", "Failed to add RunOnce value. Output:" & @CRLF & $sAddOut)
EndIf

; --- 6) Unload the hive ---
Local $sUnloadOut = ""
RunCmd('reg unload HKLM\OFFLINE', $sUnloadOut)

MsgBox($MB_ICONINFORMATION, "finish", "The script has finished. Reboot your device and look for the account when you log in to the installed system.")
Exit
please help me. when i run this script in winpe automatically appear error message.

autoit error
line 11
func runcmd($scmd,ByRef $sout="")
error :badly formatted "func" statement
boy25 is offline  
Reply


Similar Threads Similar Threads
How does it work? Does anyone know?
02/03/2017 - Silkroad Online - 0 Replies
Through SMC, or database or server?
S4 League Xigncode bypass (Not completed) (Does not work without compiling)
02/14/2016 - S4 League Hacks, Bots, Cheats & Exploits - 1 Replies
Before anybody plug this into Cheat Engine, please know this will NOT work. It needs more work to be done. I believe it needs to be compiled into .dll, and there needs to be a method where it can be injected faster then the game can detect xigncode not working. I am only sharing this, hoping that another individual can solve these problem for me. I would like it compiled into c++ .dll, and hopefully if everything works out, we can inject the .dll to bypass xigncode. This code is basically...
birthday package in wilcoins does not work what to do to work
03/31/2014 - Seafight - 0 Replies
:confused: birthday package in wildcoins does not work what to do to work
[HELP] Account does not exist upon first click then does on second
12/28/2011 - Shaiya Private Server - 3 Replies
I have tried searching the forums for this issue but all I find is problems with starting the server, I have mine all set up and "semi" public but when I or anyone else logs in we get a message saying account does not exist but if you click ok and re-enter your password it logs in, does anyone know what the problem is?
Free lab does not work after patch 4302
03/27/2006 - Conquer Online 2 - 21 Replies
I noticed that free lab stoped working for me after patch 4302, when I relog after the portal, I appear at the wind spell place where I have teleported out of the lab...weird; anyone noticed the same problem?



All times are GMT +1. The time now is 15:16.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.