rictirse 發表於 2012-9-4 10:38

Windows 預設路徑修改器

本帖最後由 rictirse 於 2015-5-29 12:09 編輯

Windows 預設路徑修改器
適用 xp vista w7
#include <GUIConstants.au3>

Const $cnt = 18
Global $Input[$cnt],$BUT_1[$cnt],$BUT_2[$cnt],$BUT_3[$cnt]
Global $i,$Var
Global $Height = ,$Width =
Global $x = +20,$Width+$Width+25,$Width+$Width+$Width+30,$Width+$Width+$Width+$Width+35],$y = 30
Global $FormWidth =$x+65, $FormHeight = 43+($cnt*$y)
Global $FormName = "修改路徑"
Global $GUI_BUT_Text = ["...","Apply","Default"]
Global $RegName[$cnt] = [ "AppData", "Cache", "Cookies", "Desktop", "Favorites", "History", "Local AppData", "Local Settings", "My Pictures", "NetHood", "Personal", "PrintHood", "Programs","Recent", "SendTo", "Start Menu", "Startup", "Templates"]
Global $DefaultRoute[$cnt] = ["%USERPROFILE%\Application Data", "%USERPROFILE%\Local Settings\Temporary Internet Files", "%USERPROFILE%\Cookies", "%USERPROFILE%\桌面", "%USERPROFILE%\Favorites", "%USERPROFILE%\Local Settings\History", "%USERPROFILE%\Local Settings\Application Data", "%USERPROFILE%\Local Settings", "%USERPROFILE%\My Documents\My Pictures", "%USERPROFILE%\NetHood", "%USERPROFILE%\My Documents", "%USERPROFILE%\PrintHood", "%USERPROFILE%\「開始」功能表\程式集", "%USERPROFILE%\Recent", "%USERPROFILE%\SendTo", "%USERPROFILE%\「開始」功能表", "%USERPROFILE%\「開始」功能表\程式集\啟動", "%USERPROFILE%\Templates"]
GUICreate ( $FormName, $FormWidth, $FormHeight, Default, Default,1)

For $i=0 to $cnt-1
      GUICtrlCreateLabel ( $RegName[$i],$x, 13+($i*$y), $Width, $Height)
      $Input[$i] = GUICtrlCreateInput ( RegRead ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", $RegName[$i]), $x, 10+($i*$y), $Width, $Height)
      $BUT_1[$i] = GUICtrlCreateButton ( $GUI_BUT_Text, $x, 7+($i*$y), $Width, $Height)
      $BUT_2[$i] = GUICtrlCreateButton ( $GUI_BUT_Text, $x, 7+($i*$y), $Width, $Height)
      $BUT_3[$i] = GUICtrlCreateButton ( $GUI_BUT_Text, $x, 7+($i*$y), $Width, $Height)
Next

GUISetState (@SW_SHOW)
WinSetOnTop ( $FormName, "", 1)


While 1
      $nMsg = GUIGetMsg()
      For $i = 0 To $cnt-1
                If $nMsg = $BUT_1[$i] Then
                        SelectFolder($i)
                EndIf
                If $nMsg = $BUT_2[$i] Then
                        apply($i)
                EndIf
                If $nMsg = $BUT_3[$i] Then
                        ReDefault($i)
                EndIf
      Next
      
      Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
      EndSwitch
WEnd


Func SelectFolder($i)
      WinSetOnTop ( $FormName, "", 0)
      $Var = FileSelectFolder ( "請選擇目錄", "", 1, RegRead ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", $RegName[$i]))
      WinWaitClose ( "瀏覽資料夾", "請選擇目錄")
      WinSetOnTop ( $FormName, "", 1)
      If $Var = "" Then
                Error1()
                GUICtrlSetData ( $Input[$i], RegRead ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", $RegName[$i]))
      Else
                If FileExists ($Var) = 1 Then
                        GUICtrlSetData ( $Input[$i], $Var)
                Else
                        Error2()
                EndIf
      EndIf
EndFunc

Func apply($i)
      If FileExists ($Var) = 1 Then
                RegWrite ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", $RegName[$i],"REG_SZ", GUICtrlRead ($Input[$i]))
      Else
                Error2()
                Return
      EndIf
      Reboot()
EndFunc

Func ReDefault($i)
      RegWrite ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", $RegName[$i], "REG_SZ", $DefaultRoute[$i])
      Reboot()
EndFunc

Func Reboot()
      GUISetState (@SW_HIDE)
      IfMsgBox ( 36, $FormName,"已修改完成"&@CR&"重新啟動電腦後才會生效"&@CR&"是否馬上重新啟動") = 6 Then
                Shutdown (2)
      Else
                Exit
      EndIf
EndFunc

Func Error1()
      If @OSVersion = "WIN_VISTA" Or @OSVersion = "WIN_7" Then
                ToolTip (@CR&"    取消    "&@CR&" ")
      Else
                ToolTip (@CR&"    取消    "&@CR)
      EndIf
      Sleep (1500)
      ToolTip ( "")
EndFunc

Func Error2()
      If @OSVersion = "WIN_VISTA" Or @OSVersion = "WIN_7" Then
                ToolTip (@CR&"    路徑錯誤    "&@CR&" ")
      Else
                ToolTip (@CR&"    路徑錯誤    "&@CR)
      EndIf
      Sleep (1500)
      ToolTip ( "")
EndFunc

gary8349 發表於 2013-1-29 00:14

請問噹噹超版,如何將右上角的XX加上去
或是在下面新增一個結束按鈕
謝謝囉~

rictirse 發表於 2013-2-1 13:10

gary8349 發表於 2013-1-29 00:14 static/image/common/back.gif
請問噹噹超版,如何將右上角的XX加上去
或是在下面新增一個結束按鈕
謝謝囉~ ...

#include <GUIConstants.au3>

Const $cnt = 18
Global $Input[$cnt],$BUT_1[$cnt],$BUT_2[$cnt],$BUT_3[$cnt]
Global $i,$Var
Global $Height = ,$Width =
Global $x = +20,$Width+$Width+25,$Width+$Width+$Width+30,$Width+$Width+$Width+$Width+35],$y = 30
Global $FormWidth =$x+60, $FormHeight = 10+($cnt*$y)
Global $FormName = "修改路徑"
Global $GUI_BUT_Text = ["...","Apply","Default"]
Global $RegName[$cnt] = [ "AppData", "Cache", "Cookies", "Desktop", "Favorites", "History", "Local AppData", "Local Settings", "My Pictures", "NetHood", "Personal", "PrintHood", "Programs","Recent", "SendTo", "Start Menu", "Startup", "Templates"]
Global $DefaultRoute[$cnt] = ["%USERPROFILE%\Application Data", "%USERPROFILE%\Local Settings\Temporary Internet Files", "%USERPROFILE%\Cookies", "%USERPROFILE%\桌面", "%USERPROFILE%\Favorites", "%USERPROFILE%\Local Settings\History", "%USERPROFILE%\Local Settings\Application Data", "%USERPROFILE%\Local Settings", "%USERPROFILE%\My Documents\My Pictures", "%USERPROFILE%\NetHood", "%USERPROFILE%\My Documents", "%USERPROFILE%\PrintHood", "%USERPROFILE%\「開始」功能表\程式集", "%USERPROFILE%\Recent", "%USERPROFILE%\SendTo", "%USERPROFILE%\「開始」功能表", "%USERPROFILE%\「開始」功能表\程式集\啟動", "%USERPROFILE%\Templates"]
GUICreate ( $FormName, $FormWidth, $FormHeight)

For $i=0 to $cnt-1
      GUICtrlCreateLabel ( $RegName[$i],$x, 13+($i*$y), $Width, $Height)
      $Input[$i] = GUICtrlCreateInput ( RegRead ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", $RegName[$i]), $x, 10+($i*$y), $Width, $Height)
      $BUT_1[$i] = GUICtrlCreateButton ( $GUI_BUT_Text, $x, 7+($i*$y), $Width, $Height)
      $BUT_2[$i] = GUICtrlCreateButton ( $GUI_BUT_Text, $x, 7+($i*$y), $Width, $Height)
      $BUT_3[$i] = GUICtrlCreateButton ( $GUI_BUT_Text, $x, 7+($i*$y), $Width, $Height)
Next

GUISetState (@SW_SHOW)
WinSetOnTop ( $FormName, "", 1)


While 1
      $nMsg = GUIGetMsg()
      For $i = 0 To $cnt-1
                If $nMsg = $BUT_1[$i] Then
                        SelectFolder($i)
                EndIf
                If $nMsg = $BUT_2[$i] Then
                        apply($i)
                EndIf
                If $nMsg = $BUT_3[$i] Then
                        ReDefault($i)
                EndIf
      Next

      Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
      EndSwitch
WEnd


Func SelectFolder($i)
      WinSetOnTop ( $FormName, "", 0)
      $Var = FileSelectFolder ( "請選擇目錄", "", 1, RegRead ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", $RegName[$i]))
      WinWaitClose ( "瀏覽資料夾", "請選擇目錄")
      WinSetOnTop ( $FormName, "", 1)
      If $Var = "" Then
                Error1()
                GUICtrlSetData ( $Input[$i], RegRead ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", $RegName[$i]))
      Else
                If FileExists ($Var) = 1 Then
                        GUICtrlSetData ( $Input[$i], $Var)
                Else
                        Error2()
                EndIf
      EndIf
EndFunc

Func apply($i)
      If FileExists ($Var) = 1 Then
                RegWrite ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", $RegName[$i],"REG_SZ", GUICtrlRead ($Input[$i]))
      Else
                Error2()
                Return
      EndIf
      Reboot()
EndFunc

Func ReDefault($i)
      RegWrite ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", $RegName[$i], "REG_SZ", $DefaultRoute[$i])
      Reboot()
EndFunc

Func Reboot()
      GUISetState (@SW_HIDE)
      IfMsgBox ( 36, $FormName,"已修改完成"&@CR&"重新啟動電腦後才會生效"&@CR&"是否馬上重新啟動") = 6 Then
                Shutdown (2)
      Else
                Exit
      EndIf
EndFunc

Func Error1()
      If @OSVersion = "WIN_VISTA" Or @OSVersion = "WIN_7" Then
                ToolTip (@CR&"    取消    "&@CR&" ")
      Else
                ToolTip (@CR&"    取消    "&@CR)
      EndIf
      Sleep (1500)
      ToolTip ( "")
EndFunc

Func Error2()
      If @OSVersion = "WIN_VISTA" Or @OSVersion = "WIN_7" Then
                ToolTip (@CR&"    路徑錯誤    "&@CR&" ")
      Else
                ToolTip (@CR&"    路徑錯誤    "&@CR)
      EndIf
      Sleep (1500)
      ToolTip ( "")
EndFunc

bear1alex1 發表於 2015-6-1 09:11

rictirse 發表於 2015-6-1 09:54

bear1alex1 發表於 2015-6-1 09:11
rictirse版大,這個程式碼看起來,僅僅寫入regedit吧?並沒有幫忙把檔案給複製過去,能否也把檔案給複製過 ...

對這只是一個改路徑 owner 跟 robocopy 或 xcopy 那也只是一兩行的function而已修改起來不困難..

bear1alex1 發表於 2015-6-1 10:18

rictirse 發表於 2015-6-1 10:34

bear1alex1 發表於 2015-6-1 10:18
可是小弟遇到的重點是
1. 如果要遷移的帳號目錄是登入使用中的系統管理員的話, 則必需建立及登入使用另一 ...

使用中user 的 file會被lock是正常的
你現在要做的事情我還是不太懂
可以條列式的詳細敘述嗎?
你想達到什麼,目前使用什麼方法

bear1alex1 發表於 2015-6-1 10:49

頁: [1]
查看完整版本: Windows 預設路徑修改器