顯示具有 Windows 標籤的文章。 顯示所有文章
顯示具有 Windows 標籤的文章。 顯示所有文章

2026-06-11

[PS]因為某些失誤不小心把系統環境變數Path全部刪除刪除

環境變數分為使用者變數與系統變數,以下為新增系統變數Path,並且可以放到GPO的版本
  • 因為放到GPO當重覆不能重覆新增
  • 原本有的Path內容,不會被覆蓋
  • 如果Path內容,有參數問題,也不會造成判斷錯誤,例如%Windows%
  • 大小寫不會判斷錯誤
$regPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"

# 1. 讀取目前「活著」的原始 PATH(如果完全沒有,則給予空字串,防止 Null 崩潰)
$currentPath = ""
if (Get-ItemProperty -Path $regPath -Name PATH -ErrorAction SilentlyContinue) {
    $currentPath = (Get-ItemProperty -Path $regPath -Name PATH).PATH
}

# 2. 定義系統核心路徑與應用程式路徑
$essentialPaths = @(
    "%SystemRoot%\system32",
    "%SystemRoot%",
    "%SystemRoot%\System32\Wbem",
    "%SystemRoot%\System32\WindowsPowerShell\v1.0\",
    "%SystemRoot%\System32\OpenSSH\",
    "C:\Program Files (x86)\Microsoft\Edge\Application",
    "C:\Program Files (x86)\Common Files\Oracle\Java\java8path",
    "C:\Program Files (x86)\Common Files\Oracle\Java\javapath"
)

# 3. 將目前現有的 PATH 切開成陣列,統一轉小寫並剔除結尾斜線
$currentPathArray = $currentPath -split ';' | ForEach-Object { $_.Trim().ToLower().TrimEnd('\') }

# 3.5 額外產生一個「已經把 %SystemRoot% 換成 C:\Windows」的現有路徑陣列,用來雙重防禦
$expandedCurrentPathArray = $currentPathArray | ForEach-Object { 
    [Environment]::ExpandEnvironmentVariables($_).ToLower().TrimEnd('\') 
}

# 4. 用來累積存放「目前漏掉、需要補上去」的路徑購物車
$pathsToAppend = @()

foreach ($path in $essentialPaths) {
    # 將我們要檢查的路徑,分別製作「未展開小寫」與「已展開小寫」兩種版本
    $cleanPath = $path.ToLower().TrimEnd('\')
    $expandedPath = [Environment]::ExpandEnvironmentVariables($path).ToLower().TrimEnd('\')
    
    # 【核心修正】:如果現有的 PATH 裡面,既沒有原始變數格式,也沒有展開後的 C:\ 格式,才允許加入!
    if ($currentPathArray -notcontains $cleanPath -and $expandedCurrentPathArray -notcontains $expandedPath) {
        $pathsToAppend += $path
    }
}

# 5. 如果有發現缺少的路徑,才進行更新
if ($pathsToAppend.Count -gt 0) {
    
    # 判斷原本的 PATH 是不是空的
    if ([string]::IsNullOrWhiteSpace($currentPath)) {
        $newPath = $pathsToAppend -join ";"
    } else {
        # 確保原本使用者自己裝的軟體路徑完全不會被動到
        $newPath = $currentPath.Trim(';') + ";" + ($pathsToAppend -join ";")
    }
    
    # 6. 強制指定以 ExpandString (REG_EXPAND_SZ) 寫入,保護 %SystemRoot% 變數不變死字串
    Set-ItemProperty -Path $regPath -Name PATH -Value $newPath -Type ExpandString
    
    Write-Host "成功!已保留原本的所有路徑,並補上缺少的:($($pathsToAppend -join ', '))" -ForegroundColor Green
    
    # 7. 通知 Windows 系統更新環境變數(免重開機立即生效)
    $signature = '[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);'
    $win32 = Add-Type -MemberDefinition $signature -Name "Win32" -Namespace "Env" -PassThru
    $result = [UIntPtr]::Zero
    $win32::SendMessageTimeout([IntPtr]0xffff, 0x001A, [UIntPtr]::Zero, "Environment", 2, 5000, [ref]$result) | Out-Null

} else {
    Write-Host "檢查完畢:所有核心路徑與指定路徑已存在(包含變數展開檢查),未重複新增。" -ForegroundColor Yellow
}
補充其他系統變數的Path
npm 與node 無法執行要加入C:\Program Files\nodejs
choco無法執行要加入C:\ProgramData\chocolatey\bin

2017-12-26

[Windows]備份指令Copy運用

備份資料單一檔案到指定位置 備份Windows 內建排程設定.xml(匯出匯入用) 抓取Windows 內建排程設定.csv(取得目前相關資料,報告用)
REM 年、月、日
SET TodayYear=%date:~0,4%
SET TodayMonthP0=%date:~5,2%
SET TodayDayP0=%date:~8,2%

        MD D:\SQBACKUP\%TodayYear%%TodayMonthP0%%TodayDayP0%_SCH
        copy "C:\inetpub\wwwroot\Smart-Query\sch.xml" D:\SQBACKUP\%TodayYear%%TodayMonthP0%%TodayDayP0%_SCH

        MD D:\SQBACKUP\%TodayYear%%TodayMonthP0%%TodayDayP0%_WINSCH
        schtasks /query /XML > D:\SQBACKUP\%TodayYear%%TodayMonthP0%%TodayDayP0%_WINSCH\all_tasks.xml  
        schtasks /query /FO CSV /V > D:\SQBACKUP\%TodayYear%%TodayMonthP0%%TodayDayP0%_WINSCH\sched_tasks.csv
補充: 備份目錄:20171208_SCH、20171208_WINSCH 備份單一檔案要使用copy,備份目錄使用xcopy

2013-07-05

[Windows]HP 5200 無法自動選紙之設定

 1.請至「印表機」資料夾 — 按一下「開始」 -> 「設定」 -> 「印表機」。

   2.右鍵按一下印表機,然後至「內容」。
   3.至「NT Forms」標籤。
   4.按一下「Clear All」鈕。
   5.若要儲存變更並結束,請按一下「OK」鈕

2012-05-21

[Windows]你已經使用暫存設定檔登入

資料來源

http://social.technet.microsoft.com/Forums/zh-TW/windowsvistazhcht/thread/4d79cd40-e8f4-419b-a48d-70f9e0a6ec60
 http://support.microsoft.com/kb/2008385/en-us

刪除機碼
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionProfileList

因為公司有網域,所以我就都底下的砍光光,原因是無法分辨對應帳號
---------------------------------------------------------------------------------------------------------------------------------------------------

砍光後出現Windows 7專業版為非法使用者XD

Method C: Add Registry Key
1. Copy the below entry as is on a notepad and save the text file to Profilelist.reg
2. Merge profilelist.reg
3. Reboot the server and now try to activate , it should work fine.
---------------------------------------------------------------------------------------------------------------------------------------------------
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionProfileListS-1-5-18]
"Flags"=dword:0000000c
"State"=dword:00000000
"RefCount"=dword:00000001
"Sid"=hex:01,01,00,00,00,00,00,05,12,00,00,00
"ProfileImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,
  00,6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
  5c,00,63,00,6f,00,6e,00,66,00,69,00,67,00,5c,00,73,00,79,00,73,00,74,00,65,
  00,6d,00,70,00,72,00,6f,00,66,00,69,00,6c,00,65,00,00,00
[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionProfileListS-1-5-19]
"ProfileImagePath"=hex(2):43,00,3a,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,
  00,73,00,5c,00,53,00,65,00,72,00,76,00,69,00,63,00,65,00,50,00,72,00,6f,00,
  66,00,69,00,6c,00,65,00,73,00,5c,00,4c,00,6f,00,63,00,61,00,6c,00,53,00,65,
  00,72,00,76,00,69,00,63,00,65,00,00,00
"Flags"=dword:00000000
"State"=dword:00000000
[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionProfileListS-1-5-20]
"ProfileImagePath"=hex(2):43,00,3a,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,
  00,73,00,5c,00,53,00,65,00,72,00,76,00,69,00,63,00,65,00,50,00,72,00,6f,00,
  66,00,69,00,6c,00,65,00,73,00,5c,00,4e,00,65,00,74,00,77,00,6f,00,72,00,6b,
  00,53,00,65,00,72,00,76,00,69,00,63,00,65,00,00,00
"Flags"=dword:00000000
"State"=dword:00000000

2011-12-14

[Windows]建立指定大小的空白檔案

fsutil file createnew  
當中的是檔案名,而是檔案大小(以kilo-byte為單位)。
1個1KB的檔案是 1 x 1024 = 1024
1個1MB的檔案是 1 x 1024 x 1024 = 1048576
1個100MB的檔案是 10 x 1024 x 1024 = 104857600
1個1GB的檔案是 1 x 1024 x 1024 x 1024 = 1073741824

資料來源:http://www.foolegg.com/computer-tutorials/how-to-create-a-empty-file-of-a-specific-size/

2011-11-30

[Windows]XP系統無法讀取超過137G以上隨身碟

將下面檔案存成副檔名reg或直接修改登錄碼
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesatapiParameters]
"EnableBigLba"=改為16進位1

2011-11-25

[Windows]這項作業因電腦上作用中的限制而取消。請連絡你的系統管理員

  1. 重新設定 Internet Explorer
  2.  [開始]、[控制台]、[程式集]、[預設程式],點選 [設定程式存取和電腦預設值]檢查IE是否為預設
  3. 刪除下面機碼
    HKEY_CURRENT_USERSoftwareClasses.html

    HKEY_CURRENT_USERSoftwareClasses.htm
  4. 到”regedit”的”HKEY_CLASSES_ROOT .html”,更改預設值為”htmlfile”

2011-11-03

[Windows]Win7右下角輸入法不見了~~

  1. 控制台已經找過相關選項還是無法啟動
  2. 發現輸入法是啟動ctfmon.exe
  3. 發現處理程式沒有ctfmon.exe程式
參考別台電腦把他手動加入登錄檔的Run