Jump to content

How to change a registry key?


z0rr0
 Share

Recommended Posts

Hi,

Easy, hm? RegWrite? But I cannot write in registry without administrator's priviliges :nuke:

I already tried RunAsSet but it seems to work only with the subsequent command Run/runwait, so I tired this:

RunAsSet ("Id", "computer", "password")

runwait ("regedit.exe")

RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4D36E96D-E325-11CE-BFC1-08002BE10318}\0002", "UserInit", "REG_SZ", "+CGDCONT=1,{ascii 34}IP{ascii 34}")

And still does not work :P

Help anyone? Would appreciate.

P.S. Key value contains several quotation marks {"}:

+CGDCONT=1, "IP", "internet"

I don't know how to put them into code- I always get error

Link to comment
Share on other sites

Add this to your script. Add values to $user, $domain and $password. Have your own code in the main part of the script as usual. Compile it and running the script should make it restart with admin privilages. No need to call this function as AutoIt will look for it first and execute the code within.

; Your code here

Exit

; AutoRun "Script.exe" as Admin
Func OnAutoItStart()
    ; Add User name
    Local $user = ''
    ; Add Domain name
    Local $domain = ''
    ; Add Password
    Local $password = ''
    ;
    ; Check incoming parameters
    If Not $CMDLINE[0] Then
        ; No parameters then restart as admin
        RunAsSet($user, $domain, $password)
        Run('"' & @ScriptFullPath & '" /admin')
        RunAsSet()
        Exit
    ElseIf $CMDLINE[1] <> '/admin' Then
        ; Exit script with exit code 1
        Exit 1
    EndIf
EndFunc
Link to comment
Share on other sites

You could always give yourself admin rights. Then take them off later.

_RunDOS("net user administrators YOURUSERNAME /ADD")
;Or, if youve a pass:
_RunDOS("net user administrators YOURUSERNAME  YOURPASSWORD /ADD")

EDIT::

Actually, dont do this, because, then, You wont be able to take off the admin rights, lol. Well, you probly can, but it never works when I try.

Edited by AzKay
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

Just updated the UDF. If you are using the latest AutoIt v3.2.0.1, then you can use this code which will work with an Au3 file also.

; Your code here

Exit

; AutoRun "Script.exe" as Admin
Func OnAutoItStart()
    ; Add User name
    Local $user = ''
    ; Add Domain name
    Local $domain = ''
    ; Add Password
    Local $password = ''
    ;
    ; Check incoming parameters
    If Not $CMDLINE[0] Then
        ; No parameters then restart as admin
        RunAsSet($user, $domain, $password)
        Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /admin')
        RunAsSet()
        Exit
    ElseIf $CMDLINE[1] <> '/admin' Then
        ; Exit script with exit code 1
        Exit 1
    EndIf
EndFunc
Link to comment
Share on other sites

Thanks for feedback,

As I understand that requires restart of the system and thats what I want to avoid. The script is supposed to change the registry entry so I could connect to internet through the special APN that allows me to receive corporate e-mails. That requires changing registry key. Now I can do it if I open IE with administrators privilidges through .reg files but it would work but I don't how to execute .reg files through AutoIt ;-(

P.S. Any idea how to incorporate quotation mark into key value?

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