Morthawt Posted October 16, 2014 Share Posted October 16, 2014 (edited) I am trying to write a program to restore the user directory location to it's correct local location upon a change having happened in the location that needs fixing. But every time I try, even though it "appears" that it should work, I always get an error code 2 from RegWrite The key looks something like this: HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionProfileListS-1-5-21-5567327821-1832712073-2531187684-1000 The value I need to change the data for is "ProfileImagePath" which by default contains something like c:usersUserNameHere I have tried to figure this out for the past 30 minutes without success. I have tried checking permissions in the registry, trying compiling as 32 bit, 64 bit, using HKLM64. Nothing appears to be working. expandcollapse popup#NoTrayIcon #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseUpx=y #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Run_Tidy=y #AutoIt3Wrapper_Run_Au3Stripper=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Global $SearchKey = 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList', $FinalPath, $FinalValue = 'ProfileImagePath' GatherUserSpecifics() NormalizeProfile() Func NormalizeProfile() ConsoleWrite($FinalPath & @CRLF & $FinalValue & @CRLF) If @Compiled Then RegWrite($FinalPath, $FinalValue, 'REG_EXPAND_SZ', @HomeDrive & '\Users\' & @UserName) If @error Then MsgBox(0, @error, @extended) EndFunc ;==>NormalizeProfile Func GatherUserSpecifics() $keys = GetAllRegKeys(0, $SearchKey) For $a In $keys $value = RegRead($SearchKey & '\' & $a, $FinalValue) $sections = StringSplit($value, '\', 2) If @UserName = $sections[UBound($sections) - 1] Then $FinalPath = $SearchKey & '\' & $a EndIf Next EndFunc ;==>GatherUserSpecifics Func GetAllRegKeys($_mode, $_input) Local $RegKeySearchPosition = 1, $_results[0], $_chosenmode = RegEnumKey If $_mode = 1 Then $_chosenmode = RegEnumVal While 1 $initiallist = $_chosenmode($_input, $RegKeySearchPosition) If @error Then ExitLoop EndIf ReDim $_results[UBound($_results) + 1] $_results[UBound($_results) - 1] = $initiallist $RegKeySearchPosition += 1 WEnd If UBound($_results) < 1 Then Return SetError(1, 0, '') Return $_results EndFunc ;==>GetAllRegKeys Can you see something wrong with what I have so far? I have verified I am able to write the value and data to one key backwards to the ProfileList key, but when I try and write the correct path to the correct value in the correct key it fails every time. I would appreciate a fresh set of eyeballs on this problem. It may be something really stupid, but I am just at a loss. Thanks. Edited October 16, 2014 by Morthawt Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
jguinch Posted October 16, 2014 Share Posted October 16, 2014 It works for me. But I don't really understand the goal of your script. You want to change the profile location, in order to have c:users<username> instead of the existing path ? Don't you thing that you will have some acl problems ? If it can help you, here is a function to create a profile for the specified SID and user/folder name. Func _WinAPI_CreateProfile($sUserSid, $sUserName) Local $ret = DllCall("Userenv.dll", "long", "CreateProfile", "wstr", $sUserSid, "wstr", $sUserName, "wstr", "", "dword", 255) If @error Then Return SetError(1, @extended, @error) Return $ret[3] EndFunc Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Morthawt Posted October 16, 2014 Author Share Posted October 16, 2014 It works for me. But I don't really understand the goal of your script. You want to change the profile location, in order to have c:users<username> instead of the existing path ? Don't you thing that you will have some acl problems ? If it can help you, here is a function to create a profile for the specified SID and user/folder name. Func _WinAPI_CreateProfile($sUserSid, $sUserName) Local $ret = DllCall("Userenv.dll", "long", "CreateProfile", "wstr", $sUserSid, "wstr", $sUserName, "wstr", "", "dword", 255) If @error Then Return SetError(1, @extended, @error) Return $ret[3] EndFunc I have been trying my script the whole time in VMware. You are saying it was working for you? How come I am receiving an error code of 2? Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
Morthawt Posted October 16, 2014 Author Share Posted October 16, 2014 (edited) It works for me. But I don't really understand the goal of your script. You want to change the profile location, in order to have c:users<username> instead of the existing path ? Don't you thing that you will have some acl problems ? If it can help you, here is a function to create a profile for the specified SID and user/folder name. Func _WinAPI_CreateProfile($sUserSid, $sUserName) Local $ret = DllCall("Userenv.dll", "long", "CreateProfile", "wstr", $sUserSid, "wstr", $sUserName, "wstr", "", "dword", 255) If @error Then Return SetError(1, @extended, @error) Return $ret[3] EndFunc I just tried it on my actual computer and it did not alter the path and I also saw the error informing me that RegWrite errored with code 2. Edit: I think I may have gotten too excited about my new usage of functions being first class objects and forgotten to actually add the function which makes the other choice... lol. I will investigate this. EDIT Ok. I was originally planning to use one function for both gathering keys and values but realised since there was only 1 value I cared about that was not worth the time. The problem was the remote directory I was testing did not have the full username exactly. Once I altered the code to check for the existence of the username then it worked. Thanks. Edited October 16, 2014 by Morthawt Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now