IT漫步

技术生活札记©Yaohui

[Powershell] Create folder, copy file and verify file hash, regex usage

Method #1: $hashPattern = "^MD5\s+(\w+)\s+"; $sourceFile = "C:\temp\6372241e-591e-4063-b15d-8aa34ae1ac63.txt"; $destFolder = "C:\app\social space\data\scp"; $destFileName = "test.txt"; $destFile = Join-Path -Path $destFolder -ChildPath $destFileName; New-Item -ItemType Directory -Force -Path $destFolder | Out-Null; Copy-Item $sourceFile -Destination $destFile -Force | Out-Null; Get-FileHash $destFile -Algorithm MD5 | Out-String -Stream | Select-String -Pattern $hashPattern | % {$_.matches.Groups[1]} | % {$_.Value}; Key …


Create a custom Application icon on Ubuntu

Create text file like below: [Desktop Entry] Type=Application Encoding=UTF-8 Name=MyApplication Comment=My fancy new application Exec=my_application Icon=my_application.png Terminal=false Name it as YOUR_APP_NAME.desktop, and then put it into /usr/share/applications for anyone; or put it into ~/.local/share/applications for current user only. Then you will see it in the Applications list Ref: https://askubuntu.com/questions/1026528/adding-custom-programs-to-favourites-of-ubuntu-dock


Install nvidia-340 driver on Ubuntu 20.04.3 LTS

在一台旧PC上安装了Ubuntu 20.04.3 LTS, 显卡是”微星N240GT-MD 暴雪512/D5″, 芯片是 Nvidia Geforce GT240, 需要安装显卡驱动 》 先是从nvidia官方网站根据显卡型号下载了NVIDIA-Linux-x86_64-340.108.run 安装过程中提示: asm/kmap_types.h: No such file or directory 没有找到有效解决办法 》 google一番后尝试直接安装nvidia-340驱动 sudo apt install nvidia-340 也是安装失败, 主要的错误是: dpkg: error: version ‘-‘ has bad syntax: revision number is empty Setting up lib32gcc-s1 (10.3.0-1ubuntu1~20.04) ... Setting up vdpau-driver-all:amd64 (1.3-1ubuntu2) ... Setting up nvidia-340 (340.108-0ubuntu5.20.04.2) ... dpkg: …






Run application as whatever user called it (non-administrator) on Windows 10 (Supressing UAC Prompts)

cmd min C set __COMPAT_LAYER=RunAsInvoker && start "" %1 For example: @echo off set __COMPAT_LAYER=RunAsInvoker start "" XXX.exe exit /b 0 ref https://stackoverflow.com/questions/37878185/what-does-compat-layer-actually-do



Methods to start process in C# and powershell

private int StartProcess(SoftwareSvr swSvr, string workingDir) { Process proc = new Process(); proc.StartInfo.UseShellExecute = true; proc.StartInfo.WorkingDirectory = workingDir; proc.StartInfo.FileName = swSvr.Command; if (swSvr.Args != null && swSvr.Args.Any()) { proc.StartInfo.Arguments = string.Join(' ', swSvr.Args); } bool started = proc.Start(); if (started) { return proc.Id; } else { return -1; } } private int StartProcessByPs(SoftwareSvr swSvr, string …

Proudly powered by WordPress