Jump to content

How to execut a *REG with admin right ?


Go to solution Solved by caramen,

Recommended Posts

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.

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

  • Solution

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

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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...