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

2011年11月29日 星期二

HowTo - 在 Windows 7 、Vista 忘記 Administrator 密碼


To reset a forgotten administrator password, follow these steps:

  1. Boot from Windows PE or Windows RE and access the command prompt.
  2. Find the drive letter of the partition where Windows is installed. In Vista and Windows XP, it is usually C:, in Windows 7, it is D: in most cases because the first partition contains Startup Repair. To find the drive letter, type C: (or D:, respectively) and search for the Windows folder. Note that Windows PE (RE) usually resides on X:.
  3. Type the following command (replace “c:” with the correct drive letter if Windows is not located on C:):
    copy c:\windows\system32\sethc.exe c:\
    This creates a copy of sethc.exe to restore later.
  4. Type this command to replace sethc.exe with cmd.exe:
    copy /y c:\windows\system32\cmd.exe c:\windows\system32\sethc.exeReboot your computer and start the Windows installation where you forgot the administrator password.
  5. After you see the logon screen, press the SHIFT key five times.
  6. You should see a command prompt where you can enter the following command to reset the Windows password (see screenshot above):
    net user your_user_name new_password
    If you don’t know your user name, just type net user to list the available user names.
  7. You can now log on with the new password.
I recommend that you replace sethc.exe with the copy you stored in the root folder of your system drive in step 3. For this, you have to boot up again with Windows PE or RE because you can’t replace system files while the Windows installation is online. Then you have to enter this command:
copy /y c:\sethc.exe c:\windows\system32\sethc.exe

2011年9月12日 星期一

「sudo」 for Windows PowerShell

相信有許多 Unix-like 的愛用者,
對於 sudo 帶來的便利性及安全性,
都有很高的依賴性及倚靠性,
在 Windows 的世界,雖然有個「以系統管理員身分執行」的玩意兒,
但是在習慣使用文字介面如 cmd, vim, PowerShell 的人們來說,
倘若遇到需要系統管理員權限的設定檔或文字檔,
往往就是一句「XXX」之後,還要到開始功能表尋找到 cmd 或 PowerShell,
然後再用滑鼠點右鍵選擇「以系統管理員身分執行」,然後再 cd 到剛剛的資料夾,再用編輯器開啟、編輯、blah blah....

一來一往,往往費神又費時,
今天介紹在 PowerShell 使用時,
可以輸入 Unix-like 中的 sudo (或使用者自己取)
後面再帶 vim 或 notepad 指令,接著被修改的設定檔或文字檔,
便可以系統管理員權限開啟該設定檔或文字檔,以便進行編修!

一、首先「以系統管理員身分執行」開啟 PowerShell,
預設沒錯的話,您會在您的家目錄,如:C:\Users\XXXXXXX

二、輸入指令以便新增 scripts 資料夾:

New-Item -ItemType directory $HOME\Documents\Scripts


三、使用編輯器如 vim 或 notepad 開啟 PowerShell 之 Profile 檔:
(預設為 WindowsPowerShell\Microsoft.PowerShell_profile.ps1)

notepad.exe $PROFILE

四、新增如下文字於該檔中:

New-PSDrive -name script -PSProvider FileSystem -Root $HOME\Documents\Scripts


五、存檔並離開。

六、重啟你的 PowerShell ,你將發現上面所新增的資料夾被 mount 起來,可以繼續進行:

cd script:


七、進入 script 槽後,用慣用的編輯器開啟新增 sudo.ps1 script檔:

notepad.exe sudo.ps1


八、加入 sudo script 如下:

param(
        [switch]$ps,            # Switch for running args as powershell script
        [string]$file,             # Script/Program to run
        [string]$arguments = $args # Arguments to program/script
     )

# Find our powershell full path
$powershell = (get-command powershell).definition

# Get current directory
$dir = get-location

#If we're running this as a elevated powershell script
if ($ps){

        # Script verification
        if([System.IO.File]::Exists("$(get-location)\$file")) {

                # Set the $script to full path of the ps script
                $script = (get-childitem $file).fullname
        }

        # Create a powershell process
        $psi = new-object System.Diagnostics.ProcessStartInfo $powershell

        $psi.WorkingDirectory = Get-Location

        # Combine the script and its arguments
        $sArgs = $script + " " + $arguments

        # Set the arguments to be the ps script and it's arguments
        $psi.Arguments = "-noexit -command set-location $dir; $sArgs"

        # Magic to run as elevated
        $psi.Verb = "runas";
}

# We're running something other than a powershells script
else {

        # File verification
        if([System.IO.File]::Exists("$(get-location)\$file")) {

                # Get full path
                $file = (get-childitem $file).fullname
        }

        # Same as above, create proccess/working directory/arguments/runas
        $psi = new-object System.Diagnostics.ProcessStartInfo $file
        $psi.Arguments = $arguments
        $psi.Verb = "runas"
}

# Start the process
[System.Diagnostics.Process]::Start($psi)


九、存檔並離開!

十、再次開啟 PowerShell 的 Profile 設定檔:

notepad.exe $PROFILE


十一、新增關聯指令:

New-Alias -Name sudo 'script:\sudo.ps1'

注意這裡的紅色字 sudo 可以改成任何你想要的字,只要不跟內建指令撞名即可!

十二、重啟 PowerShell,你可以使用:

sudo notepad C:\Windows\System32\drivers\etc\hosts



sudo vim $PROFILE

就會以系統管理員權限開啟,當然 Windows 的 UAC 會開啟並問你是或否,此時按「是」,
便會開啟具有系統管理員權限的視窗了!

Reference To: http://techha.us/2010/05/sudo-for-powershell/
                      http://www.ainotenshi.org/710/%E2%80%98sudo%E2%80%99-for-powershell-sorta

2011年8月22日 星期一

Windows 7「此電腦上的安全性原則已設定為顯示有關最後一個互動式登入的資訊。Windows 無法抓取此資訊。請連絡您的網路系統管理員,以取得協助。」解決方法

通常會發生這種狀況可能是您的 Windows 7 螢幕保護程式啟動後自動鎖定電腦,或使用者自行鎖定電腦( by Win+L 或開始選單→關機→鎖定 )後,欲輸入帳號密碼已解除工作站鎖定時,發生「此電腦上的安全性原則已設定為顯示有關最後一個互動式登入的資訊。Windows 無法抓取此資訊。請連絡您的網路系統管理員,以取得協助。」的殘念狀態。

首先,請先確認您的 Windows 7 是否有加入網域(廢話!沒加入網域哪會遇到這種鬼事),再來請確認貴公司或貴單位之網域是否為 Windows Server 2008 等級,倘若不是,請開啟您的控制台,並於右上方搜尋「原則」,做人不能沒原則,做電腦更是要有原則,進入「編輯群組原則」後,依序進入:

電腦設定→系統管理範本→Windows 元件→Windows 登入選項→於使用者登入期間顯示有關上次登入的資訊

不管它是尚未設定還是已啟用,給他關掉!





事後再鎖定貴電腦,您應該就可以看得到藍天了XD