Jump to content

Help With Automation Program - (Moved)


Recommended Posts

Hi, hope all is well.

So I wrote some PowerShell command lines that goes in and changes a bunch of settings, installs programs etc on a PC. I am trying to create a GUI that I can check the changes I want and then hit run to execute the command lines.

I'm having a hard time wrapping my head around the project, especially the functionality on the AutoIT side.

$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
$Name = "PCNAME"
Set-ItemProperty $RegPath "DefaultDomain" -Value "$Name" -type String
Rename-Computer -NewName "$Name" -restart
#Region Rename PC
Global $sPCName = GUICtrlCreateInput("PC01", 285, 65, 155, 20)
Global $bRename = GUICtrlCreateButton("Rename PC", 305, 95, 115, 30)
Global $sNewName = GUICtrlRead($sPCName)
#EndRegion

I am probably going to need a bunch of assistance before I start to comprehend what I'm really doing, but right now I am trying to enter the new name in the input $sPCName and then when I click the $bRename button I would like to run the powershell portion

 

 

Edited by Em4gdn1m
Too much useless code making it hard to help with the actual question at hand.
Link to comment
Share on other sites

So I can't get any program to run with the press of the button

#include <GUIConstantsEx.au3>

Global $hGUI = GUICreate("Windows Setup", 450, 325)
Global $bRun = GUICtrlCreateButton("RUN", 305, 95, 115, 30)
Global $msg

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $msg = $bRun
            Run("C:\Users\mikesysadm\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Notepad.exe")
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Edited by Em4gdn1m
Link to comment
Share on other sites

I really don't love guigetmsg and switch and case..

This would be how i do it.

#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
Global $hGUI = GUICreate("Windows Setup", 450, 325)
Global $bRun = GUICtrlCreateButton("RUN", 305, 95, 115, 30)
GUICtrlSetOnEvent($bRun, 'Go')
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState(@SW_SHOW)
;=============================================================================
While 1
Sleep(100)
WEnd
;=============================================================================
Func Go()
    MsgBox(64 + 262144, 'Go', 'Run') ;Test button
    Run("C:\Users\mikesysadm\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Notepad.exe")
EndFunc
;=============================================================================
Func Close()
    Exit
EndFunc

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

7 minutes ago, careca said:

I really don't love guigetmsg and switch and case..

This would be how i do it.

#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
Global $hGUI = GUICreate("Windows Setup", 450, 325)
Global $bRun = GUICtrlCreateButton("RUN", 305, 95, 115, 30)
GUICtrlSetOnEvent($bRun, 'Go')
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState(@SW_SHOW)
;=============================================================================
While 1
Sleep(100)
WEnd
;=============================================================================
Func Go()
    MsgBox(64 + 262144, 'Go', 'Run') ;Test button
    Run("C:\Users\mikesysadm\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Notepad.exe")
EndFunc
;=============================================================================
Func Close()
    Exit
EndFunc

 

Hmm, so when the line reads Run("notepad.exe") it works, but if it says Run("C:\Users\mikesysadm\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Notepad.exe") it doesn't.

Link to comment
Share on other sites

Try ShellExecute, that link you posted is a shortcut and not the executable.

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Well spotted, it's a .lnk

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

1 hour ago, BrewManNH said:

Try ShellExecute, that link you posted is a shortcut and not the executable.

 

Nice. I am able to open powershell now with

Run("C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe")

Now what I am trying to do is read the string in $sPCName and use the string as the variable in my powershell command.

$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
$Name = "$sPCName"
Set-ItemProperty $RegPath "DefaultDomain" -Value "$Name" -type String
Rename-Computer -NewName "$Name" -restart
Func Go()
    Run("C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe")
    Send("$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" Set-ItemProperty $RegPath "DefaultDomain" -Value "$sPCName" -type String Rename-Computer -NewName "$sPCName" -restart")
EndFunc

the Send line is giving me syntax errors (no surprise with all those quotes in there)

Edited by Em4gdn1m
Link to comment
Share on other sites

1 hour ago, careca said:

I really don't love guigetmsg and switch and case..

This would be how i do it.

#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
Global $hGUI = GUICreate("Windows Setup", 450, 325)
Global $bRun = GUICtrlCreateButton("RUN", 305, 95, 115, 30)
GUICtrlSetOnEvent($bRun, 'Go')
GUICtrlSetOnEvent($bClear, "_Adjust_All")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GUISetState(@SW_SHOW)
;=============================================================================
While 1
Sleep(100)
WEnd
;=============================================================================
Func Go()
    MsgBox(64 + 262144, 'Go', 'Run') ;Test button
    Run("C:\Users\mikesysadm\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Notepad.exe")
EndFunc
;=============================================================================
Func Close()
    Exit
EndFunc

 

I was trying to run with your idea here with the GUISetOnEvent command, but ran into an issue when I tried to put back some of my other working code back in

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bClear
            _Adjust_All(False)
            GUICtrlSetData($sPCName, "")
        Case $msg = $bRename
            Run("C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe")
    EndSwitch
WEnd

Case $bClear _Adjust_All had a (False) flag (probably not the correct term) attached to it which made my function uncheck all the checkboxes in the $cTV array $aItems and cleared the $sPCName box. How do I do this with the GUISetOnEvent command?

Func _Adjust_All($bState = True)
    For $i = 0 To UBound($aItems) - 1
        _GUICtrlTreeView_SetChecked($cTV, $aItems[$i][0], $bState)
        $aItems[$i][1] = $bState
    Next
EndFunc

 

Link to comment
Share on other sites

Try this line

Send('$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" Set-ItemProperty '& $RegPath &" DefaultDomain -Value "&$sPCName&" -type String Rename-Computer -NewName "&$sPCName&" -restart")

As for the above post, im not sure, because i don't see any code with checkboxes, and then in the code you posted you have a treeview function.

The general idea is fine, but i don't know what the _adjust_all function is.

You could simply run the unckeck function with a button. Need more info to be able to move forward.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

20 hours ago, careca said:

Try this line

Send('$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" Set-ItemProperty '& $RegPath &" DefaultDomain -Value "&$sPCName&" -type String Rename-Computer -NewName "&$sPCName&" -restart")

As for the above post, im not sure, because i don't see any code with checkboxes, and then in the code you posted you have a treeview function.

The general idea is fine, but i don't know what the _adjust_all function is.

You could simply run the unckeck function with a button. Need more info to be able to move forward.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <Array.au3>
#include <StaticConstants.au3>
#RequireAdmin
Global $bState, $iItemIndex, $msg, $hGUI, $sFile, $hTVItemSelected, $aItems, $cTV, $bRun, $bClear, $sPCName, $bRename, $aItems[24][3]
#Region GUI
Opt("GUIOnEventMode", 1)
$hGUI = GUICreate("Windows Setup", 450, 325)
$sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & "\Wow6432Node" & "\AutoIt v3\AutoIt", "InstallDir") & "\icons\Varex.ico"
GUISetIcon($sFile)
GUISetBkColor(0x333333)
#EndRegion

#Region Treeview
$hTVItemSelected = False
$cTV = GUICtrlCreateTreeView(10, 10, 265, 265, BitOR($TVS_CHECKBOXES, $TVS_LINESATROOT, $TVS_HASLINES, $TVS_HASBUTTONS), $WS_EX_CLIENTEDGE)
$bRun = GUICtrlCreateButton("Run", 30, 285, 100, 30)
$bClear = GUICtrlCreateButton("Clear", 155, 285, 100, 30)
$aItems[0][2]  = GUICtrlCreateTreeViewItem("Update Windows",                    $cTV)
$aItems[1][2]  = GUICtrlCreateTreeViewItem("Install Programs",                  $cTV)
$aItems[2][2]  = GUICtrlCreateTreeViewItem("Office",                            $aItems[1][2])
$aItems[3][2]  = GUICtrlCreateTreeViewItem("Ninite",                            $aItems[1][2])
$aItems[4][2]  = GUICtrlCreateTreeViewItem("UltraVNC",                          $aItems[1][2])
$aItems[5][2]  = GUICtrlCreateTreeViewItem("BGinfo",                            $aItems[1][2])
$aItems[6][2]  = GUICtrlCreateTreeViewItem("Computer Settings",                 $cTV)
$aItems[7][2]  = GUICtrlCreateTreeViewItem("Add 'anyuser'",                     $aItems[6][2])
$aItems[8][2]  = GUICtrlCreateTreeViewItem("Admin Access",                      $aItems[7][2])
$aItems[9][2]  = GUICtrlCreateTreeViewItem("Auto Login",                        $aItems[7][2])
$aItems[10][2] = GUICtrlCreateTreeViewItem("Enable Remote Desktop",             $aItems[6][2])
$aItems[11][2] = GUICtrlCreateTreeViewItem("Change Group Policy",               $aItems[6][2])
$aItems[12][2] = GUICtrlCreateTreeViewItem("Enable .NET 3.5",                   $aItems[6][2])
$aItems[13][2] = GUICtrlCreateTreeViewItem("Disable TCP/IPv6",                  $aItems[6][2])
$aItems[14][2] = GUICtrlCreateTreeViewItem("Change Power Options",              $aItems[6][2])
$aItems[15][2] = GUICtrlCreateTreeViewItem("Set Time",                          $aItems[6][2])
$aItems[16][2] = GUICtrlCreateTreeViewItem("Show Hidden Files",                 $aItems[6][2])
$aItems[17][2] = GUICtrlCreateTreeViewItem("Allow VNC Firewall Ports",          $aItems[6][2])
$aItems[18][2] = GUICtrlCreateTreeViewItem("Change Windows Search Settings",    $aItems[6][2])
$aItems[19][2] = GUICtrlCreateTreeViewItem("Disable OneDrive",                  $aItems[6][2])
$aItems[20][2] = GUICtrlCreateTreeViewItem("Join Domain",                       $cTV)
$aItems[21][2] = GUICtrlCreateTreeViewItem("102",                               $aItems[20][2])
$aItems[22][2] = GUICtrlCreateTreeViewItem("EVL",                               $aItems[20][2])
$aItems[23][2] = GUICtrlCreateTreeViewItem("FPVL",                              $aItems[20][2])
#EndRegion

#Region Rename PC
$sPCName = GUICtrlCreateInput("", 285, 65, 155, 20)
$bRename = GUICtrlCreateButton("Rename PC", 305, 95, 115, 30)
#EndRegion

For $i = 0 To UBound($aItems) - 1
    $aItems[$i][1] = False
    $aItems[$i][0] = GUICtrlGetHandle($aItems[$i][2])
Next
GUICtrlSetOnEvent($bRename, '_Rename')
GUICtrlSetOnEvent($bClear, "_Adjust_All")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
HotKeySet("{ESC}", "_Close")
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
;$aInfo = GUIGetCursorInfo($hGUI)
;If $aInfo[2] Then
    ;If $aInfo[4] = $sPCName Then GUICtrlSetData($sPCName, "")
;EndIf
If $hTVItemSelected Then
    $bState = _GUICtrlTreeView_GetChecked($cTV, $hTVItemSelected)
    $iItemIndex = _ArraySearch($aItems, $hTVItemSelected)
    If $aItems[$iItemIndex][1] <> $bState Then
    $aItems[$iItemIndex][1] = $bState
    _Adjust_Children($hTVItemSelected, $bState)
    EndIf
        $hTVItemSelected = 0
EndIf
WEnd

Func _Rename()
    Run("PowerShell.exe")
    WinWaitActive ("[CLASS:ConsoleWindowClass]", "", 0)
    ;RegWrite("HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultDomain", $sPCName)
    Send(StringFormat("Rename-Computer -NewName %s -restart", $sPCName))
EndFunc

Func _Close()
    Exit
EndFunc

Func _Adjust_All($bState = True)
    ; Loop through items
    For $i = 0 To UBound($aItems) - 1
        ; Adjust item
        _GUICtrlTreeView_SetChecked($cTV, $aItems[$i][0], $bState)
        ; Adjust array
        $aItems[$i][1] = $bState
    Next
EndFunc   ;==>_Adjust_All

Func _Adjust_Children($hPassedItem, $bState = True)
    Local $iIndex
    ; Get the handle of the first child
    Local $hChild = _GUICtrlTreeView_GetFirstChild($cTV, $hPassedItem)
    If $hChild = 0 Then Return
    ; Loop through children
    While 1
        ; Adjust the array
        $iIndex = _ArraySearch($aItems, $hChild)
        If @error Then Return
        $aItems[$iIndex][1] = $bState
        ; Adjust the child
        _GUICtrlTreeView_SetChecked($cTV, $hChild, $bState)
        ; And now do the same for the generation beow
        _Adjust_Children($hChild, $bState)
        ; Now get next child
        $hChild = _GUICtrlTreeView_GetNextChild($cTV, $hChild)
        ; Exit the loop if no more found
        If $hChild = 0 Then ExitLoop
    WEnd
EndFunc   ;==>_Adjust_Children
Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
    Local $tStruct = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;" & _
            "uint Action;struct;uint OldMask;handle OldhItem;uint OldState;uint OldStateMask;" & _
            "ptr OldText;int OldTextMax;int OldImage;int OldSelectedImage;int OldChildren;lparam OldParam;endstruct;" & _
            "struct;uint NewMask;handle NewhItem;uint NewState;uint NewStateMask;" & _
            "ptr NewText;int NewTextMax;int NewImage;int NewSelectedImage;int NewChildren;lparam NewParam;endstruct;" & _
            "struct;long PointX;long PointY;endstruct", $lParam)
    Local $hWndFrom = DllStructGetData($tStruct, "hWndFrom")
    If $hWndFrom = GUICtrlGetHandle($cTV) Then
        Switch  DllStructGetData($tStruct, "Code")
            Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
                Local $hItem = DllStructGetData($tStruct, "NewhItem")
                If $hItem Then $hTVItemSelected = $hItem
        EndSwitch
    EndIf
EndFunc

Here is the complete code thus far. I figure might as well give you too much info than not enough info.

I am working on line 83 where it says

Send(StringFormat("Rename-Computer -NewName %s -restart", $sPCName))

There's some kind of formatting error or something because everytime it sends the string "Rename-Computer -NewName 30 -restart"

I'm not sure where the 30 keeps coming from, but it never changes. I want it to be the string typed into the input named $sPCName

Link to comment
Share on other sites

Oh i see now, the 30 is the inputbox ID, you never read the value from the box anywhere, so it goes as the control ID.

Also, i think you dont need the string format..

Send('"Rename-Computer -NewName '& GUICtrlRead($sPCName) &' -restart"')

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

On 4/30/2020 at 5:06 PM, careca said:

Oh i see now, the 30 is the inputbox ID, you never read the value from the box anywhere, so it goes as the control ID.

Also, i think you dont need the string format..

Send('"Rename-Computer -NewName '& GUICtrlRead($sPCName) &' -restart"')

 

Genius! but actually the quotes are unneeded as well

Send('Rename-Computer -NewName '& GUICtrlRead($sPCName) &' -restart')

 

Now I'm having issues trying to send multiple lines to powershell (not using enter but a newline command of some sort)

I would love to be able to send this to the powershell and THEN hit enter, but they need to be sent on different lines.

Install-Module -Name PSWindowsUpdate -Force
Get-Package -Name PSWindowsUpdate
Set-ExecutionPolicy Unrestricted -Scope CurrentUser
Import-Module PSWindowsUpdate
Get-Command -Module PSWindowsUpdate
Get-WindowsUpdate
Install-WindowsUpdate

I've tried @CRLF in a bunch of syntax formats but no luck. I can get them to send all on the same line, just not separated with a new line.

 

Both

Send('Install-Module -Name PSWindowsUpdate -Force' "{LCTRL} + {ENTER}" 'Get-Package -Name PSWindowsUpdate')



Send('Install-Module -Name PSWindowsUpdate -Force')
    Send("{LCTRL} + {ENTER}")
    Send('Get-Package -Name PSWindowsUpdate')

aren't working correctly

Link to comment
Share on other sites

The internet says the pipe | in between commands should work as a link, also the parentesis can make it work as one big command.

Run("PowerShell.exe")
WinWaitActive ("[CLASS:ConsoleWindowClass]", "", 0)
Send('Install-Module -Name PSWindowsUpdate -Force | Get-Package -Name PSWindowsUpdate')
Send("{ENTER}")

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

16 hours ago, careca said:

The internet says the pipe | in between commands should work as a link, also the parentesis can make it work as one big command.

Run("PowerShell.exe")
WinWaitActive ("[CLASS:ConsoleWindowClass]", "", 0)
Send('Install-Module -Name PSWindowsUpdate -Force | Get-Package -Name PSWindowsUpdate')
Send("{ENTER}")

 

hmm that doesn't seem to work either. it's just sending it as a large string with | between which isn't recoginized as a new line in powershell.

with this command and with " " instead of ' ' both just run the Install-Module -Name PSWindowsUpdate -Force command and not the Get-Package -Name PSWindowsUpdate command. it does send the enter key though.

 

Edit: hmm interesting.

Send('powercfg.exe -x -monitor-timeout-ac 0 | powercfg.exe -x -monitor-timeout-dc 0 | powercfg.exe -x -disk-timeout-ac 0 | powercfg.exe -x -disk-timeout-dc 0 | powercfg.exe -x -standby-timeout-ac 0 | powercfg.exe -x -standby-timeout-dc 0 | powercfg.exe -x -hibernate-timeout-ac 0 | powercfg.exe -x -hibernate-timeout-dc 0')
Send("{ENTER}")

This command seems to accpet all the lines and implement the settings, but the windows update stuff doesn't seem to like it.

Edited by Em4gdn1m
Link to comment
Share on other sites

it's very rare when you really need to use powershell.  most powershell stuff can be converted over to just AutoIt pretty easily.

on those occasions when I must use powershell, I just write .ps1 files out on the fly and use that directly and retrieve the results.  that way you don't have to figure out all the switches.  Just write a .ps1 file as you want and populated with variables as it's written.

$sPowerShell = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell", "Path")
    
    $sArguments = "" ;Full path to the .ps1 file that is created on the fly using filewrite() opened with FileOpen("", 10)
    
    $iPIDps = Run($sPowerShell & ' -ExecutionPolicy ByPass -File "' & $sArguments & '"', "", @SW_HIDE, 2)
    If @error Then  ConsoleWrite("Error encountered on Run" & @CRLF)
    ProcessWaitClose($iPIDps)

    $sOutRead = StdoutRead($iPIDps)
    ConsoleWrite($sOutRead)

 

Link to comment
Share on other sites

19 hours ago, BigDaddyO said:

it's very rare when you really need to use powershell.  most powershell stuff can be converted over to just AutoIt pretty easily.

on those occasions when I must use powershell, I just write .ps1 files out on the fly and use that directly and retrieve the results.  that way you don't have to figure out all the switches.  Just write a .ps1 file as you want and populated with variables as it's written.

$sPowerShell = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell", "Path")
    
    $sArguments = "" ;Full path to the .ps1 file that is created on the fly using filewrite() opened with FileOpen("", 10)
    
    $iPIDps = Run($sPowerShell & ' -ExecutionPolicy ByPass -File "' & $sArguments & '"', "", @SW_HIDE, 2)
    If @error Then  ConsoleWrite("Error encountered on Run" & @CRLF)
    ProcessWaitClose($iPIDps)

    $sOutRead = StdoutRead($iPIDps)
    ConsoleWrite($sOutRead)

 

hmmmm. I'm going to have to explore this. from your experience and knowledge, do you think most of those settings I am trying to accomplish are doable straight in AutoIT without using PowerShell?

Link to comment
Share on other sites

for all the registry edits, just look up RegWrite in the help file.

I always use a google search before I ever post a question on the Forum:  AutoIt what I want to do

 

Or, just use the AutoIt forum search.  powercfg.exe found this:  

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...