hendrikhe Posted August 18, 2017 Share Posted August 18, 2017 Hello, I need to RegWrite running the script with a different (admin) account (shift right click -> run as different user).But it is not working. $root = "c:\Data" $RegSID = "S-1-5-21-3798503727-2312606340-957070891-1013" $username = "test" $RegSIDpath = "HKEY_USERS\" & $RegSID & "\SOFTWARE\Microsoft\OneDrive\Tenants\18f52f13-d6e1-47e9-801f-xxxxx\" $OneDriveDefault = $root & '\' & $Username & '\'& "OneDrive - Default" RegWrite($RegSIDpath, "DefaultRootDir", "REG_SZ",$OneDriveDefault) MsgBox(0, '', $username) MsgBox(0, '', $RegSID) MsgBox(0, '', $RegSIDpath) Link to comment Share on other sites More sharing options...
Trong Posted August 19, 2017 Share Posted August 19, 2017 Try: #RequireAdmin Global $root = "C:\Data" Global $username = @UserName;"test" Global $RegSID = _GetSidAccount($username);"S-1-5-21-3798503727-2312606340-957070891-1013" Global $RegSIDpath = "HKEY_USERS\" & $RegSID & "\SOFTWARE\Microsoft\OneDrive\Tenants\18f52f13-d6e1-47e9-801f-xxxxx\" Global $OneDriveDefault = $root & '\' & $Username & '\'& "OneDrive - Default" ConsoleWrite($username&@CRLF) ConsoleWrite($RegSID&@CRLF) ConsoleWrite($RegSIDpath&@CRLF) Global $RegWriteReturn = RegWrite($RegSIDpath, "DefaultRootDir", "REG_SZ",$OneDriveDefault) ConsoleWrite($RegWriteReturn&@CRLF) MsgBox(Null, "RegWrite()", $RegWriteReturn ? "OK" : "ERROR") Func _GetSidAccount($sAccount = @UserName, $sSystem = "") Local $tData = DllStructCreate("byte SID[256]") Local $sCall = DllCall("advapi32.dll", "bool", "LookupAccountNameW", "wstr", $sSystem, "wstr", $sAccount, "struct*", $tData, "dword*", DllStructGetSize($tData), "wstr", "", "dword*", DllStructGetSize($tData), "int*", 0) If @error Or Not $sCall[0] Then Return SetError(@error, @extended, "") Local $pSID = DllStructGetPtr($tData, "SID") Local $iCall = DllCall("advapi32.dll", "bool", "IsValidSid", "struct*", $pSID) If @error Or Not $iCall[0] Then Return SetError(@error, @extended, "") Local $dCall = DllCall("advapi32.dll", "bool", "ConvertSidToStringSidW", "struct*", $pSID, "ptr*", 0) If @error Or Not $dCall[0] Then Return SetError(@error, @extended, "") Local $pStringSid = $dCall[2] Local $aLen = DllCall("kernel32.dll", "int", "lstrlenW", "struct*", $pStringSid) Local $sSID = DllStructGetData(DllStructCreate("wchar Text[" & $aLen[0] + 1 & "]", $pStringSid), "Text") DllCall("kernel32.dll", "handle", "LocalFree", "handle", $pStringSid) Return SetError(0, 0, $sSID) EndFunc ;==>_GetSidAccount Regards, Link to comment Share on other sites More sharing options...
hendrikhe Posted August 19, 2017 Author Share Posted August 19, 2017 (edited) Thank you for reply: Works if I run with current user, but I need to run with different user that has admin rights (shift right click Run as diferent user): Message: ERROR user: test RegSID: S-1-5-21-3798503727-2312606340-957070891-1013 RegSIDpath: HKEY_USERS\S-1-5-21-3798503727-2312606340-957070891-1013\SOFTWARE\Microsoft\OneDrive\Tenants\18f52f13-d6e1-47e9-801f-xxxxx\ Everything looks right, besides ERROR Edited August 22, 2017 by hendrikhe Link to comment Share on other sites More sharing options...
Developers Jos Posted August 19, 2017 Developers Share Posted August 19, 2017 Have you considered x86/x64 with this as you likely run the script in 32 bits mode. By the way: you never responded to the other thread with your runas challenge. Jos 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 More sharing options...
hendrikhe Posted August 20, 2017 Author Share Posted August 20, 2017 Hey Jos, I compiled this script in x86. Computers that I will run script are x64. Do I have to make any changes? PS: will check other thread soon. I am short in time 😓 Link to comment Share on other sites More sharing options...
Developers Jos Posted August 20, 2017 Developers Share Posted August 20, 2017 The thing is that a x86 compiled script will handle the registry as x86 not x64! From the helpfile: Quote When running on 64-bit Windows if you want to read a value specific to the 64-bit environment you have to suffix the HK... with 64 i.e. HKLM64. Jos 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 More sharing options...
hendrikhe Posted August 23, 2017 Author Share Posted August 23, 2017 Thanks, chaged script to if @OSArch = "X64" or @OSArch = "IA64" then $RegSIDpath = "HKEY_USERS64\" & $RegSID & "\SOFTWARE\Microsoft\OneDrive\Tenants\18f52f13-d6e1-47e9-801f-xxxx\" Else $RegSIDpath = "HKEY_USERS\" & $RegSID & "\SOFTWARE\Microsoft\OneDrive\Tenants\18f52f13-d6e1-47e9-801f-xxxx\" EndIf 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