UE_morf_boon Posted July 20, 2022 Posted July 20, 2022 Hi! I have a program that has a specific function that renames the computer. The entire program should be executed only on behalf of the current user, because some registry keys in the HKCU are being changed. The current user does not have administrator rights, so #Requireadmin is not suitable as a solution. The administrator accounts on the computers are different, so "RunAs" is not suitable. Is there a way to trigger a UAC, when running a function? The function code, if you need: Func _RenamePC($Input2) Local $Name = GUICtrlRead($Input2) $objWMIService = ObjGet("winmgmts:\root\cimv2") For $objComputer In $objWMIService.InstancesOf("Win32_ComputerSystem") $oReturn = $objComputer.rename($Name) Next EndFunc
Solution UE_morf_boon Posted July 20, 2022 Author Solution Posted July 20, 2022 (edited) Nevermind, solved the problem via "powershell". Solution code: Func _RenamePC($Name) ShellExecuteWait("C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe", "start-process -verb runas 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe' "& _ "-argumentlist '$compcname = get-wmiobject win32_computersystem; foreach($comp in $compcname){$oreturn = "& _ "$comp.rename(''"&$Name&"'')}"& _ "'", "", "", @SW_HIDE) EndFunc Edited July 21, 2022 by UE_morf_boon Fix solution t0nZ 1
t0nZ Posted August 3, 2022 Posted August 3, 2022 Interesting ! I was searching a method to execute a powershell script as Admin from a non admin AutoIT script, and so I adapted your example this way: Func _executeElevatedPS() ShellExecuteWait("powershell.exe", "start-process -verb runas 'powershell.exe' "& _ "-argumentlist '-executionpolicy unrestricted -File C:\temp\wp.ps1'", "", "", @SW_HIDE) EndFunc
t0nZ Posted August 4, 2022 Posted August 4, 2022 Adding this: Func _Set_Network_Private() ShellExecuteWait("powershell.exe", "start-process -verb runas 'powershell.exe' " & _ "-argumentlist @('-executionpolicy unrestricted',' -command Get-NetConnectionProfile -InterfaceAlias Ethernet | Set-NetConnectionProfile -NetworkCategory Private -Confirm:$false -PassThru')", '', '', @SW_SHOW) EndFunc from this post It's the same logic, but executing multiple powershell instructions without an external .ps1 file
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