Jump to content

Can't import REG file - Windows 7


Recommended Posts

First of all, I have read countless forum topics, and no luck. I'm trying to write to:

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionMMDevicesAudioRender{00000000-0000-0000-0000-000000000000}FxProperties]

(zeroes are random number which my script determines and replaces).

I've tried to import REG file. I've tried to use RegWrite. I've tried to add #RequireAdmin to my script. I've compiled script to EXE and added admin manifest. I've turned off UAC. And still I can't write there.

Yet when I double click REG file, everything is importing properly.

It seems my script is lacking some permissions, but with all I have already tried - I have no idea just what the hell else does Windows 7 want. Anyone has any idea? And more importantly - how can I add it to my script.

My script (the ONLY problematic part is the very bottom line):

#notrayicon
#Include <_RegSearch.au3>
$s = _RegSearchValue("Realtek System Effect", "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render", 0, 0)
If $s = "" Then
$s = _RegSearchValue("Realtek System Effect", "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render", 0, 0)
EndIf
$stripped = StringReplace($s, "\FxProperties", "")

$pos1 = StringInStr($stripped,@CRLF,0,-1)
$1 = StringTrimRight($stripped,StringLen($stripped) - $pos1)
$pos2 = StringInStr($1,'}',0,-2)
$2 = StringTrimRight($1,StringLen($1) - $pos2)

$pos3 = StringInStr($stripped,@CRLF,0,-1)
$3 = StringTrimLeft($stripped,StringLen($stripped) - $pos3)
$pos4 = StringInStr($3,'}',0,-2)
$4 = StringTrimRight($3,StringLen($3) - $pos4)

FileCopy(@ScriptDir & '\Data\Equalizer.reg', @TempDir & '\Equalizer.reg', 1)

$szFile = (@TempDir & '\Equalizer.reg')
$szText = FileRead($szFile,FileGetSize($szFile))
$szText = StringReplace($szText, "{00000000-0000-0000-0000-000000000000}", $2, 1)
$szText = StringReplace($szText, "{00000000-0000-0000-0000-000000000000}", $4, 2)
FileDelete($szFile)
FileWrite($szFile,$szText)

Run("REGEDIT /S " & @TempDir & "\Equalizer.reg")
Edited by supraspecies
Link to comment
Share on other sites

Have you tried it with HKLM64 instead? (if running on a 64 bit OS)

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

Link to comment
Share on other sites

Have you tried it with HKLM64 instead? (if running on a 64 bit OS)

Yes I have. Tried using RegWrite to HKLM64 too, still nothing. Besides, when you import a REG file, OS architecture shouldn't matter as far as I know - Windows will redirect it to a proper branch.

Another observation is that I tried importing that REG file with BAT. When I clicked on BAT manually, it imported. When I set my script to execute BAT - nothing. Definitely looks like a permission issue, but I can't figure out where. UAC is off, and when I run my script as admin it should have the same privileges as I do. Weird.

P.S. Not the first time I'm seeing this issue, either. Happens when you try to write to some "important" system keys (with the lack of better word...).

Edited by supraspecies
Link to comment
Share on other sites

Afraid not. Didn't work. I've tried different commands as well, along with direct import and RegWrite. It depends on where you import. I'm importing to where Windows stores driver settings, and apparently it doesn't like it. I guess I'd be better off asking on Microsoft forums, but I figured someone around here must have stumbled into this at one time or another.

Is there any way I can edit registry writing permissions via script then?

Edited by supraspecies
Link to comment
Share on other sites

Afraid not. Didn't work. I've tried different commands as well, along with direct import and RegWrite. It depends on where you import. I'm importing to where Windows stores driver settings, and apparently it doesn't like it. I guess I'd be better off asking on Microsoft forums, but I figured someone around here must have stumbled into this at one time or another.

Is there any way I can edit registry writing permissions via script then?

I had a quick look at the key in question on my Windows 7 Ultimate machine and the permissions are set that "Administrators" group can query and set the value but not delete or a few other things, im not sure exactly how regedit works when importing/modifying existing data and whether it would go about removing the old key in order to create a new key (if it does then the permissions on that key section would explain the block there).

It also looks as though there are no permissions to create a subkey in that area if that is relevant?

To check permissions i suppose you would have to take ownership of the key and add the Administrator permissions as Full Control (or tick the permissions previously not granted) unless there is anyway to run the program under the TrustedInstaller user since it seems to be the only one with permissions to fully control that area

Link to comment
Share on other sites

If it was a permissions issue I cant believe that double clicking the reg file would have worked. Have you tried taking redirection off?

Happens when you try to write to some "important" system keys (with the lack of better word...)

makes me think system32/syswow64 issues.

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

makes me think system32/syswow64 issues.

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)

You were right! Now it works! So... a little more info what this does? I can see it disables redirection, but for how long? While the script is running? Disables it only for the script, or system-wide? Edited by supraspecies
Link to comment
Share on other sites

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365743(v=vs.85).aspx

Disables file system redirection for the calling thread.

--so i am assuming it affects only the script, for the duration of the script.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

So, for example, if i make it like this:

*importing reg file here*

DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)

*importing reg file here*

first one will go into 32-bit branch, while second one will go to 64-bit branch?

---------------------

Yeah, just tested, looks like that's how it works. With this type of code it seems I'll be able to import regardless of OS architecture. Thank you very much.

Edited by supraspecies
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...