Sign in to follow this  
Followers 0
Klexen

RegWrite Remote write to @computername?

10 posts in this topic

I have several computers I need to make registry changes to, and I want to do it while the user is logged in. The logged in users do not have write access to "HKEY_LOCAL_MACHINE". So I'm trying to "Remote" write to their registry by doing

$computer_name = @ComputerName
RegWrite("\\" & $computer_name & "\" & "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\SuperSocketNetLib", "ProtocolOrder", "REG_MULTI_SZ", $inputBox)

This doesn't work from the local machine, however it does work remotely, as it should.

I was able to successfully write to the c:\ drive as a normal logged in user, by

$computer_name = @ComputerName
ShellExecute("\\" & $computer_name & "\c$")

then automating the local admin login to that box. Once I do that, I'm able to write to the C drive as an admin. I assumed that since these credentials exist for me to access the computers, C$, it would also let me write to the registry as admin too. Sadly, it doesn't work that way.

Is there a way to make what I'm trying to do work?

Share this post


Link to post
Share on other sites



@computername returns the name of the computer the script is being run on, you can't get a remote computer's name that way unless you're running the script on that computer.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Hi, Klexen. As BrewMan pointed out, @ComputerName is not what you want in this scenario. If it is just a few machines, consider looping through their names with something like this:

Local $pcs[3]

$pcs[0] = "Computer1"
$pcs[1] = "Computer2"
$pcs[2] = "Computer3"

   For $element in $pcs
      RegWrite("" & $element & "" & "HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSSQLServerClientSuperSocketNetLib", "ProtocolOrder", "REG_MULTI_SZ", $inputBox)
   Next

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I know @ComputerName is used to use the local computers name. The thing is, I need to visit each of these machines to automate other things while they're logged in. The way it is now, I have to remotely write this registry setting and then go to their box locally to do the other things. I was hoping I could avoid the two step process, and fool the computer into thinking I was remotely writing to the registry, locally, by using that computers network name. Just like I do to have admin write access to their C drive, even though they're logged in as a normal user. This I do, by having my script access ComputerNamec$ at which point it prompts for the admin info for that box. I automate those credentials, and once "logged in" I'm able to have admin access to the C drive, even though they're logged in as standard users. I guess my question is, can this trickery work with the registry as well?

I hope that makes sense!

Edited by Klexen

Share this post


Link to post
Share on other sites

When you are running the script locally on the machine, is it running under admin credentials? Also, what is the OS you are running the script on?

Adam

Share this post


Link to post
Share on other sites

I just tried using regwrite with the computer namekey (like how it says in the help file) and I was able to write to HKLM and HKCR, didn't test anything else.

I was logged in to both machines with my account, which is an admin. Whats the @error from your code? Are you trying to do this on machines where the account you are running the script with does not have admin rights on the remote box?


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

If you include the command #RequireAdmin at the top of your script, you can run your script as an admin once you put in the correct credentials. This should eliminate having to do the "remote" regwrites.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I just tried using regwrite with the computer namekey (like how it says in the help file) and I was able to write to HKLM and HKCR, didn't test anything else.

I was logged in to both machines with my account, which is an admin. Whats the @error from your code? Are you trying to do this on machines where the account you are running the script with does not have admin rights on the remote box?

Yeah, the remote registry write works locally, if the account that executes the script is an admin, but not when you execute the script as a standard user, which is what I need to do. I'm trying to avoid having the "standard" user log off, so that I can login locally as admin to run the script.

If you include the command #RequireAdmin at the top of your script, you can run your script as an admin once you put in the correct credentials. This should eliminate having to do the "remote" regwrites.

The operating system is Windows XP, and if the #RequireAdmin uses the same thing as "Right clicking on a program, and doing RUN AS, then inputting those credentials, that won't work. I get an error when I try to do that manually. I think I just learned why too, reading http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/windows_security_runas.mspx?mfr=true

I'm thinking that "secondary login service" is not running. I'll have to look into that.

Share this post


Link to post
Share on other sites

You will need to have the script re-execute itself as an admin, if it is not admin. There are multiple was to do this.

Adam

Share this post


Link to post
Share on other sites

If you need to write to the registry as an admin, when the script is running under a non-admin account, you will need to use RunAs() to execute a separate script (or rerun the same script) as an administrator. The drawback is that you will have to embed the administrative credentials into the script. (not recommended, but occasionally done out of pure neccessity).

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