跳到主要內容

發表文章

How to remove a substring via batch command

Here is a tip to remove a substring via batch command For example: If I'd like to remove file extension name  from  Install .wim to  Install We can try below command: Test.cmd SET WINPE=%1 echo %WINPE% SET WINPE=%WINPE:.wim=% echo %WINPE% Input:  Test.cmd Install.wim Output:  Install REF: http://www.dostips.com/DtTipsStringManipulation.php

[Batch][loop] Recurse find specified file and do something

Assume you need to update many  Setting.xml  in the specified directory and they locate on different sub-folders. You can copy&past one-by-one if you have a lot of time to do this. Or you can try below batch script:  SET FileName ="C:\Users\Andy\Dropbox\ Setting.xml " FOR /F  "usebackq delims==" %%i IN (`dir /b /s Setting.xml `) DO COPY /Y  %FileName% "%%i"

[C#] FTP download sample code

If you'd like DL file through  WebRequestMethods, maybe you could try below sample code Input: filePath = "ftp://100.251.237.125/update.xml" targetPath  = update.xml public bool DwonlaodFileFromFTP( string filePath, string targetPath, out string errorMessage)         {             // initialize                      FtpWebRequest request = ( FtpWebRequest ) WebRequest .Create(filePath);             request.Credentials = new NetworkCredential (_user, _password);             request.Proxy = null ;             request.Method = WebRequestMethods . Ftp .DownloadFile;             request.UsePassive = false ; ...

[C#] FtpWebRequest failed

[C#] FtpWebRequest fails  I try to list files using FtpWebRequest but  it fails with a WebException 'The underlying connection was closed: An unexpected error occurred on a receive.'             string ftpPath = "ftp://" + this ._ip;                          FtpWebRequest request = ( FtpWebRequest ) WebRequest .Create(ftpPath);             request.Credentials = new NetworkCredential (_user, _password);             request.Proxy = null ;             request.Method = WebRequestMethods . Ftp .ListDirectory;              FtpWebResponse response = ( FtpWebResponse )request.GetResponse();            ...

[WPF]如何在程式中加入Hot key event

假設今天我想要讓使用者Hot key(如Alt) trigger程式做事情的時候 我們可以編寫UI的xaml 加入   PreviewKeyDown  事件的handler 並實作他 Step 1. Add event handler < Window         xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns : x ="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns : d ="http://schemas.microsoft.com/expression/blend/2008"         xmlns : mc ="http://schemas.openxmlformats.org/markup-compatibility/2006" mc : Ignorable ="d"         xmlns : conv ="clr-namespace:Solution.Converter"         x : Class ="Solution.MainWindow"          WindowState ="Maximized" WindowStyle ="None"         SnapsToDevicePixels ="True"         d : D...

[MFC] 進入桌面後自動執行程式

如果想要在進入桌面時 讓程式自動起來執行 基本上有兩種方法 1. 透過 Windows Task  scheduler 把程式叫起來 2. 在指定的 registry 路徑下註冊想要執行程式(這也本篇文章想要分享給各位的) 假設今天我想要每次進入桌面時,OS都會自動把APP.exe 叫起來執行的話 其實程式在安裝時可以在 registry的特定路徑Run底下寫入APP資訊如下   CRegKey keyReg;               CString strkey;      strkey.Format(_T( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run" ));   if (keyReg.SetStringValue(_T( "APP_EXE_RUN" ), _T( "C:\\APP.exe" )) != ERROR_SUCCESS)                 {                    //fail                                      }    keyReg.Close();

[C#] 如何偵測程式執行環境是否在WINPE

WINPE 簡單來說就是一個小型的OS 可以放在USB裡開機, 不須特別安裝 所以對於IT人員來說是非常方便的工具用來部屬系統 一般而言, WINPE 裡會提供專屬的工具讓我們呼叫 例如: WINPEUTIL Reboot 若程式執行的環境會在Destop 以及 WINPE底下時 則必須明確地知道自己的環境才不會使用錯的工具 以下是C# sample code 用來偵測是不是WINPE 環境 string strREG = @" SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinPE " ; RegistryKey regKey = Registry . LocalMachine . OpenSubKey ( strREG , true ) ; if ( regKey ! = null ) { // It's WINPE