Sign in to follow this  
Followers 0
caramen

How to execut a *REG with admin right ?

2 posts in this topic

i toook very lon gtime to make a script that working perfectly now...

but the only thing is when i am executing the code everything work but autoit does not execute a reg file same way than a cmd file look at this code :

Case $Num_PC

                  Local $MyNum_PC = InputBox("Nump_PC", "Que voulez vous comme numéro de pc?"&@CRLF &"Pour Planitec 2.0")

                  Local Const $NumPCPath = "C:\Num_PC.reg"
                  _FileCreate ( $NumPCPath )
                  Local $hFileOpen = FileOpen($NumPCPath, $FO_APPEND)

                        If $hFileOpen = -1 Then
                              MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.")
                        Return False
                        EndIf

                  FileOpen ($NumPCPath)

                  FileWriteLine($hFileOpen, "Windows Registry Editor Version 5.00")
                  FileWriteLine($hFileOpen, @CRLF)
                  FileWriteLine($hFileOpen, "[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]")
                  FileWriteLine($hFileOpen,@CRLF)
                  FileWriteLine($hFileOpen,'"NUM_PC"="999"')

                     ShellExecute (@ScriptDir & "\NUM-PC.bat")

                  FileClose ($NumPCPath)

                  FileDelete ($NumPCPath)

ShellExecute (@ScriptDir & "NUM-PC.bat") =

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"
:--------------------------------------


C:\Num_PC.reg

The reg is not applied.

Share this post


Link to post
Share on other sites



Solved with C:\Windows\System32\cmd.exe /k %windir%System32reg.exe Import Num_PC.reg

insteed of c:num_pc

in the batch file of course

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