Jump to content

Regedit / RunAs / Current User Key


Recommended Posts

Hey Everyone

Figured i would edit this into proper english, i was in a real rush when i wrote it, and figured someone may be able to help.

I have installed a piece of software onto the Computer Labs on the school i work for, and as usual, have copied the profile of the user i installed it as, into the Default User profile, so that certain software settings follow.

However, when the program first runs for a user, it writes information to the HKCU\Software\ of the registry.

Student accounts do not have permission to write to the registry, so this prevents the software from running.

I have a list of all the keys which i need to create, and create an AutoIT script with a "RegWrite()" statement for each key, when ran as myself (i have admin rights) it creates the keys correctly.

If i add a RunAsSet("Administrator", @computername, "password"), The keys fail to show up, my best guess is that they are writing the the HCKU\Software registry entry for the user "Administrator" instead of the Currently Logged in User. (i have attempted this with all three possible flags, all have the same result)

My Next idea was to RuAs admin, and then:

Run("Regedit.exe /s c:\RegistryKey.reg")

Running the Regedit command with the switches via a Run prompt directly works fine, however, calling it from AutoIT in this manner fails in all cases, there is no error, the command runs, but it does not actually produce an effect, the registry information does not get added.

Anyone have any other ideas on this? anyway to elevate the currently logged in user to admin for the purpose of adding the info then removing that user from admin?

/tAK

Edited by tAKTelapis
Link to comment
Share on other sites

  • 1 month later...
  • Developers

What about:

- check if user has admin rights

- if not: added the current user to the Administrators group, do what needs to be done after which you remove the user id from the administrators group.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Ok, sounds easy.

But how can I add an user to the local admin group with autoit?

I've found on autoit site some code, but there is no way to add the user to the admin group

Simple way is to run these commands because you can easily run it with an Account that has admin rights :

Net Localgroup Administrators "Domain\UserID" /Add

Net Localgroup Administrators "Domain\UserID" /Delete

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

problem is that the program will be running on a pc without the admin rights.

so the AD user who is working on that machine doesn't have any rights (unless the right to work :P)

He can start my script to change the placesbar. Everything works fine if the user had local admin rights.

If I try your example with net localgroup ...

if receive system error 5 has occured

acces is denied

but maybe I have to run this line as administrator?

"You cannot solve a problem with the mind that created it" (Albert Einstein)

Link to comment
Share on other sites

  • Developers

problem is that the program will be running on a pc without the admin rights.

so the AD user who is working on that machine doesn't have any rights (unless the right to work :P)

He can start my script to change the placesbar. Everything works fine if the user had local admin rights.

If I try your example with net localgroup ...

if receive system error 5 has occured

acces is denied

but maybe I have to run this line as administrator?

Isn't that what I said ? :D

You do:

RunAsSet("admin","Domain", "Password")

RunWait(@ComSpec & " /c Net Localgroup Administrators "Domain\UserID" /Add")

RunAsSet()

RunWait("regedit.....")

RunWait(@ComSpec & " /c Net Localgroup Administrators "Domain\UserID" /Delete")

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

i tried to put it all together in an script and come up with this error

the code i have for this thing

RunAsSet("adminuser", @ComputerName, "adminpass")

run("net localgroup Administrator "domain\user" /add"

RunAsSet()

maybe i' doing something wrong? I think I surely do something wrong

Sorry, didn't see that you already post something. My mistake. I will give it a try.

post-16598-1167301253_thumb.jpg

Edited by Steven Vandenhoute

"You cannot solve a problem with the mind that created it" (Albert Einstein)

Link to comment
Share on other sites

  • Developers

i tried to put it all together in an script and come up with this error

the code i have for this thing

maybe i' doing something wrong? I think I surely do something wrong

Multiple errors in this line : run("net localgroup Administrator "domain\user" /add"

- Missing closing bracket ...(thats the error reported.

- Missing @comspec

- Should be runWait

- Wrong " mix

RunWait(@comspec & ' /c net localgroup Administrator "domain\user" /add',"",@sw_Hide)

:P

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

how can I use this command with a variable?

I tried to use it like this

$adminuser="user"

$adminpass="pass"

$domainuser="domain\"&@username

RunAsSet($adminuser,@ComputerName, $adminpass)

RunWait(@ComSpec & ' /c Net Localgroup Administrators $domainuser /Add')

RunAsSet()

;RunWait("regedit.....")

;RunWait(@ComSpec & " /c Net Localgroup Administrators "" /Delete")

but it would not work.

Am I doing something wrong?

Edited by Steven Vandenhoute

"You cannot solve a problem with the mind that created it" (Albert Einstein)

Link to comment
Share on other sites

  • Developers

how can I use this command with a variable?

I tried to use it like this

but it would not work.

Am I doing something wrong?

Looks to me you need some basic training here ....

Concatenation of literals and variables ...

RunWait(@ComSpec & ' /c Net Localgroup Administrators ' & $domainuser & ' /Add')

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Ok, I know what I was doing wrong. I had coded also the " before and after the domain\user and it seems that that is not necessary.

only thing what i have to find now is a way to activate the user as admin without an logoff (user is in admin group, but is not activated)

"You cannot solve a problem with the mind that created it" (Albert Einstein)

Link to comment
Share on other sites

  • 2 weeks later...

Hi Steven,

i've programmed this today and it worked for me. It's based on the hint from JdeB.

You can additionally use the $AdminDomain variable for the net command.

(I've forgot this one :P )

greets

Sundance

#include <string.au3>

$AdminPWD       = _StringEncrypt(0,"xxxxxxxxxxxx","xxxxx")
$AdminName      = "Admin"
$AdminDomain    = "domain"
RunAsSet($AdminName,$AdminDomain,$AdminPWD)
RunWait(@ComSpec & " /c net localgroup administrators 'domain\" & @UserName & "' /add")
RunAsSet()
RunWait(@ComSpec & " /c reg import " & @ScriptDir & "\somereg.reg")
RunAsSet($AdminName,$AdminDomain,$AdminPWD)
RunWait(@ComSpec & " /c net localgroup administrators 'domain\" & @UserName & "' /delete")
Edited by Sundance
Link to comment
Share on other sites

  • 3 weeks later...

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