Jump to content

issue in powershell command launch


Go to solution Solved by rudi,

Recommended Posts

I am adding some functions to my little swiss knife of this post, and because I find very annoying the fact that windows 11 keep me asking to change/set password of my local users, I want to disable this with a button.

I posted below an example, where with the same tecnique I launch 2 functions, the first rename the pc and works well, the second one disable psw expiration for my local user but it's not working.

The script has to be launched as non admin user and it will ask/require elevated powershell at runtime.

I am going crazy😵 figuring out why the function _Set_PswExp4LocalUser() doesn't work, also with no evident errors.

If you try this out of AutoIt,  on a non admin powershell prompt:

PS C:\Users\utente> start-process -verb runas 'powershell.exe' -argumentlist @('-executionpolicy unrestricted',' -command Set-LocalUser -Name utente -PasswordNeverExpires $true')
PS C:\Users\utente> LUSRMGR.MSC
PS C:\Users\utente>

IT's working ! And with LUSRMGR.MSC you can check the user "utente" has now NO expiration...

But it's not working from the code...

Someone has ideas?😅

 

 

_RenamePC("YourPreferredPcName")

_Set_PswExp4LocalUsers()


Func _Set_PswExp4LocalUsers() ;V.2.83

    ;many many tests....

    ;   Local $StartProcess = "start-process -verb runas 'powershell.exe' " & _
    ;           "-argumentlist @('-executionpolicy unrestricted',' -command Get-LocalUser | Set-LocalUser -PasswordNeverExpires " & $Enable & "')"  ; -Confirm:$false -PassThru')"

    ;Local $StartProcess = "start-process -verb runas 'powershell.exe' " & _
    ;"-argumentlist @('-executionpolicy unrestricted',' -File " & $Fexp & "')"          ; -Confirm:$false -PassThru')"
    ;Gollog($StartProcess)
    ;   ShellExecuteWait("powershell.exe", $StartProcess, "", "", @SW_SHOW)
    ;Gollog("start-process -verb runas 'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe' " & _
    ;       "-argumentlist @('-executionpolicy unrestricted',' -command Set-LocalUser -Name '" & @UserName & "' -PasswordNeverExpires $true')")

    ;ShellExecuteWait("C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe", "start-process -verb runas 'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe' " & _
    ;"-argumentlist @('-executionpolicy unrestricted',' -command Get-LocalUser | Set-LocalUser -PasswordNeverExpires " & $Fexp & "')", '', '', @SW_SHOW)
    ;ShellExecuteWait("powershell.exe", "start-process -verb runas 'powershell.exe' " & _
    ;       "-argumentlist @('-executionpolicy unrestricted',' -command Set-LocalUser -Name " & @UserName & " -PasswordNeverExpires $true')", '', '', @SW_SHOW)

    ;last test:
    ShellExecuteWait("powershell.exe", "start-process -verb runas 'powershell.exe' " & _
            "-argumentlist '-executionpolicy unrestricted -command Set-LocalUser -Name " & @UserName & " -PasswordNeverExpires $true'", "", "", @SW_SHOW)
EndFunc   ;==>_Set_PswExp4LocalUsers

;EXAMPLE
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_SHOW)
EndFunc   ;==>_RenamePC

 

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

×
×
  • Create New...