Windows

Windows Management Tools

2022-02-16. Category & Tags: System, Windows, Management, Tools

Windows Task Scheduler (任务计划程序) #

Examples:

$action = New-ScheduledTaskAction -Execute 'pwsh.exe' -Argument '-NonInteractive -NoLogo -NoProfile -File "C:\MyScript.ps1"'
$trigger = New-ScheduledTaskTrigger -Once -At 3am
$settings = New-ScheduledTaskSettingsSet
$task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
Register-ScheduledTask -TaskName 'MySchedule' -InputObject $task -User 'username' -Password 'passhere'
ScheduledTask -TaskName 'MySchedule'
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' `
  -Argument '-NoProfile -WindowStyle Hidden -command "& {get-eventlog -logname Application -After ((get-date).AddDays(-1)) | Export-Csv -Path c:\fso\applog.csv -Force -NoTypeInformation}"'
$trigger = New-ScheduledTaskTrigger -Daily -At 0am
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "AppLog" -Description "Daily dump of Applog"
$action = New-ScheduledTaskAction -Execute 'C:\FreeFileSync\FreeFileSync.exe' -Argument 'C:\myBackup.ffs_batch'
$trigger = New-ScheduledTaskTrigger -Daily -At 0am
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "dailyBackup" -Description "Daily green & big files backup"

Note (by default):

...

Find and Kill a Process

2021-10-09. Category & Tags: Windows, Linux, Commands, Networking, Ports

see also: 鸟哥 Linux 私房菜 Basic Linux.

Linux #

find bound PID by port: fuser 8080/tcp
kill by port: fuser -k 8080/tcp
list by port: lsof -i:8080

using netstat: netstat -nlpte |grep :8080
or: ss -nlpt 'sport = :8080'

ref 1 & ref 2

Windows #

CMD find PID by port & kill by PID:

:: find pid first:
netstat -ano | findstr :8080
:: then the pid's task/process
tasklist | findstr "<the_PID>"
taskkill /PID <the_PID> /F

PS find for TCP & UDP:

...

Python GUI Frontend Options Comparison

2021-01-14. Category & Tags: Python, GUI, Desktop, Windows, Linux, Cross-Platfrom

Mainly for the (cross-platform) Python GUI frontend options.

  • CEF (Chromium Embedded Framework). Pro: can use the same way of MVC thinking (modern html5); build-in chromium browser. Con: someone said it may need a little c++.
  • PyQt (v5). Pro: big community, good doc (for c++). Con: c++ way of thinking, just the language is py (the official GUI tutorial lacks GUI screenshots!); pay for commercial usage; still often needs c++.
  • Tkinter. Pro: build-in w/ py, big community. Con: //TODO.
  • electron / nwjs (bad word of mouth) /javafx / swiftui / flutter : Pro: quick to develop. Con: using node.js, too slow to run and to learn. // though it is possible for experts to make VSCode using electron.
  • wxPython: Pro: small-to-middle-size community… Con: too new, few people.

ref: zhihu & youtube

...

Powershell PS In Case Of

2020-11-29. Category & Tags: Windows, Powershell, SSH, Ps

See also SSH.

Overview: for both server and client: enable remote manager on both sides; set the other side as trusted.

On both:

Enable-PSRemoting -SkipNetworkProfileCheck -Force
Set-Item wsman:\localhost\Client\TrustedHosts -value 192.168.1.*

On the client:

Enter-PSSession 192.168.xx.xx -Credential <server_computername>\<username>

Tip:

$Env:COMPUTERNAME  # for computername
$Env:USERNAME      # for username

[ref]

Powershell In Case Of

2018-02-09. Category & Tags: Powershell, Windows

Use Microsoft Terminal #

choco install -y microsoft-windows-terminal

Customizing PS Prompt (Use ConEmu) #

See more in [codeship].

install chocolatey (i.e. win pkg manager) #

option 1 [chocolatey official]: #

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) # install choco

choco install conemu -y

# Install PowerShell modules
Install-PackageProvider NuGet -MinimumVersion '2.8.5.201' -Force
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name 'posh-git'

option 2, with Git together codeship: #

# Set your PowerShell execution policy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force

# Install Chocolatey
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex

# Install Chocolatey packages
choco install git.install -y
choco install conemu -y

# Install PowerShell modules
Install-PackageProvider NuGet -MinimumVersion '2.8.5.201' -Force
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name 'posh-git'

config console emulator #

Run Start > ConEmu.
For the 1st time running, I choose the color theme “solarized”.
Follow codeship section “ConEmu” until before “PowerShell Profile”.

...