aerilus

regwrite()will not write to hklm tried all standard solutions

14 posts in this topic

#1 ·  Posted (edited)

I need to write to a key in HKLM64SOFTWAREMicrosoftWindows NTCurrentVersionPrintPrinters eventually the code will look like this

While 1
    $msg2 = GUICtrlRead($Account)
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Lexmark Universal v2 XL\PrinterDriverData", "AccountTrackAccountNumber", "REG_SZ", $msg2)
WEnd

but right now i am just trying to get reg write to work under hklm I hope I am diong something obviously stupid

this is what I am testing with

#RequireAdmin
DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)
RegWrite("HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers", "test2", "REG_sz", "Hello this is a test2")
RegWrite("HKCU\Software\Test", "TestKey2", "REG_SZ", "Hello this is a test2")
MsgBox(0, "", @error)

ive added the first two lines after reading the forum it still returns a 0 error. Ive stopped the print spooler, tried various locations HKLM as well as HKCC. I can write to HKCU just fine but i change two letters and it doesn't work. my personal user is an admin and "the" administrator account is active. Ive tried it under both. I've tried hklm and hklm64. importing from a reg works fine the admin group has full control over the key. I really don't think using reg add will do what I need since i need a variable in the function, ive tried new keys as well as existing keys. is there some kind of force overwrite?

Edited by aerilus

Share this post


Link to post
Share on other sites



Did you add #requireadmin to the top of you script?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

yes in the testing script i've tried with and without

Share this post


Link to post
Share on other sites

Have you searched the Forum extensively? As this subject comes up time and time again. Do you have an antivirus program? Is it enabled? Is it disabled?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Printers are only setup under users, not in local machine.

Share this post


Link to post
Share on other sites

yes pretty extensively all the other individuals with problems were returning helpful error codes. the other solutions was to try #requireadmin, hklm 64, and to disable redirection with 

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

. I tested with antivirus disabled. this is a driver configuration registry entry. I tried to put the key under hkcu to see if the print driver would look there before going to hklm but the driver just looks at the hklm registry key.

Share this post


Link to post
Share on other sites

What does @error return?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

0

Share this post


Link to post
Share on other sites

Printers are only setup under users, not in local machine.

Not when deployed to a machine account via GPO

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

#RequireAdmin

$MyVar = 15
Run('reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Lexmark Universal v2 XL\PrinterDriverData" /v AccountTrackAccountNumber /t REG_SZ /d ' & $MyVar, @ScriptDir)

But i do not know with 64

Edited by GordonFreeman

Share this post


Link to post
Share on other sites

Not all registry keys are redirected. The print registry key is a shared key. No redirection is done so X86 or X64 is of no concern. See MSDN for details of which registry keys are redirected here.

This is not tested from GPO and it is your test script with modification on inserting comments

#RequireAdmin

; this is for the file system redirection so no good for registry
;~ DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)

; the print key is shared thus not redirected so HKLM64 is incorrect to use
;~ RegWrite("HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers", "test2", "REG_sz", "Hello this is a test2")

; i chose this one and tested as working
RegWrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers", "test2", "REG_sz", "Hello this is a test2")

; this key is user writable and shared so expect to work
;~ RegWrite("HKCU\Software\Test", "TestKey2", "REG_SZ", "Hello this is a test2")

MsgBox(0, "", @error)

@error returns 0 and the entry is written. If it still fails for you then some permission issue or other issue may be the problem.

Share this post


Link to post
Share on other sites

thanks for the help. while i could not get it to write the entry using the test script. It did work after compiling to an exe. I don't know whats going on with that my permissions should be good and uac is turned off. if it will work in the larger script when compiled that is all I need. I was also thinking about using reg add command with arguments as an alternative if anyone else is having trouble that might be the way to go something like ShellExecutewait("reg add"............

Share this post


Link to post
Share on other sites

#13 ·  Posted

#RequireAdmin
#include <WinAPIFiles.au3>


Global $sHKLMRoot
If @OSArch = "x64" Then
    $sHKLMRoot = "HKLM64"
Else
    $sHKLMRoot = "HKLM"
EndIf



If @OSArch = "x64" Then
                DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 1) ;~ Turns On 64 Bit Redirection

Regwrite($sHKLMRoot&' \system\currentcontrolset\services\tcpip\parameters /v "SearchList" /d "domain1.com,domain2.com" /f')

        DllCall("kernel32.dll", "boolean", "Wow64DisableWow64FsRedirection", "boolean", 0) ;~ Turns Off 64 Bit Redirection
    Else


Regwrite($sHKLMRoot&' \system\currentcontrolset\services\tcpip\parameters /v "SearchList" /d "domain1.com,domain2.com" /f')



EndIf

i am trying to write dns suffixes (domain1.com, domain2.com)  however wont write with code above

 

the DOS command   prompt below does work

reg add HKLM\system\currentcontrolset\services\tcpip\parameters /v "SearchList" /d "domain1.com,domain2.com" /f

Share this post


Link to post
Share on other sites

#14 ·  Posted

Resolved here:

 

1 person likes this

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