编写自己需要的小软件——Autoit简单脚本[04]

每当我们重装系统,C盘的我的文档,收藏夹之类就会消失
于是现在很多人都把我的文档,收藏夹放在别的盘做备份
但每当重装系统一次,就要重新设置一次,这样对于经常帮人装系统的人甚感麻烦
使用Autoit,抱定的目标是,没有最懒只有更懒,能自动化的绝不手动,
自己编一个简单的注册表配置程序,就可以简单的实现文件夹迁移

首先,通过百度,我们知道,收藏夹、我的文档的位置在注册表的这个地方
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
其中的
Favorites,就是收藏夹
Personal,就是我的文档
重点介绍的是
AppData,很多应用程序的配置文件都储存在这里,
迁移这个文件夹可以达到重装软件不用重新配置的目的
Cache浏览器缓存
Cookies 浏览器cookies
History 浏览器历史
迁移这三个文件夹,可以达到重装系统后不用重新登录论坛,不丢失浏览记录的目的

于是我们可以写脚本
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","AppData","REG_SZ","你要迁移的路径")
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Favorites","REG_SZ","你要迁移的路径")
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Cache","REG_SZ","你要迁移的路径")
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Cookies","REG_SZ","你要迁移的路径")
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","History","REG_SZ","你要迁移的路径")
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal","REG_SZ","你要迁移的路径")

一个自己用的文件夹迁移工具就这样完成了

复杂点,我们可以用autoit的gui设计工具,为它加个gui


#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseAnsi=y
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$appd=RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","AppData")
$favo=RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Favorites")
$cach=RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Cache")
$cook=RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Cookies")
$hist=RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","History")
$docu=RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal")

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("系统文件夹迁移工具", 633, 586, 193, 125)
$Button1 = GUICtrlCreateButton("全部读取", 32, 16, 145, 49, 0)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("全部保存", 244, 16, 145, 49, 0)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button3 = GUICtrlCreateButton("退出", 456, 16, 145, 49, 0)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label1 = GUICtrlCreateLabel("Application Data", 32, 80, 104, 22)
GUICtrlSetFont(-1, 10, 400, 0, "Comic Sans MS")
$Input1 = GUICtrlCreateInput($appd, 32, 112, 385, 21)
$Button4 = GUICtrlCreateButton("浏览", 432, 100, 81, 33, 0)
$Button5 = GUICtrlCreateButton("保存", 520, 100, 81, 33, 0)
$Label2 = GUICtrlCreateLabel("收藏夹", 32, 152, 52, 22)
GUICtrlSetFont(-1, 10, 400, 0, "Comic Sans MS")
$Input2 = GUICtrlCreateInput($favo, 32, 184, 385, 21)
$Button6 = GUICtrlCreateButton("浏览", 432, 172, 81, 33, 0)
$Button7 = GUICtrlCreateButton("保存", 520, 172, 81, 33, 0)
$Label3 = GUICtrlCreateLabel("Internet Files 浏览器缓存", 32, 224, 172, 22)
GUICtrlSetFont(-1, 10, 400, 0, "Comic Sans MS")
$Input3 = GUICtrlCreateInput($cach, 32, 256, 385, 21)
$Button8 = GUICtrlCreateButton("浏览", 432, 244, 81, 33, 0)
$Button9 = GUICtrlCreateButton("保存", 520, 244, 81, 33, 0)
$Label4 = GUICtrlCreateLabel("Cookies", 32, 296, 50, 22)
GUICtrlSetFont(-1, 10, 400, 0, "Comic Sans MS")
$Input4 = GUICtrlCreateInput($cook, 32, 328, 385, 21)
$Button10 = GUICtrlCreateButton("浏览", 432, 316, 81, 33, 0)
$Button11 = GUICtrlCreateButton("保存", 520, 316, 81, 33, 0)
$Label5 = GUICtrlCreateLabel("历史文件夹", 32, 368, 84, 22)
GUICtrlSetFont(-1, 10, 400, 0, "Comic Sans MS")
$Input5 = GUICtrlCreateInput($hist, 32, 400, 385, 21)
$Button12 = GUICtrlCreateButton("浏览", 432, 388, 81, 33, 0)
$Button13 = GUICtrlCreateButton("保存", 520, 388, 81, 33, 0)
$Label6 = GUICtrlCreateLabel("我的文档", 32, 440, 68, 22)
GUICtrlSetFont(-1, 10, 400, 0, "Comic Sans MS")
$Input6 = GUICtrlCreateInput($docu, 32, 472, 385, 21)
$Button14 = GUICtrlCreateButton("浏览", 432, 460, 81, 33, 0)
$Button15 = GUICtrlCreateButton("保存", 520, 460, 81, 33, 0)
$Button16 = GUICtrlCreateButton("读取推荐值", 104, 520, 129, 49, 0)
$Button17 = GUICtrlCreateButton("保存推荐值", 360, 520, 129, 49, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$s1=$appd
$s2=$favo
$s3=$cach
$s4=$cook
$s5=$hist
$s6=$docu

While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
    Case $GUI_EVENT_CLOSE
      Exit

    Case $Button1
      $appd=RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","AppData")
      $favo=RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Favorites")
      $cach=RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Cache")
      $cook=RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Cookies")
      $hist=RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","History")
      $docu=RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal")
      GUICtrlSetData($Input1,$appd)
      GUICtrlSetData($Input2,$favo)
      GUICtrlSetData($Input3,$cach)
      GUICtrlSetData($Input4,$cook)
      GUICtrlSetData($Input5,$hist)
      GUICtrlSetData($Input6,$docu)

    Case $Button2
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","AppData","REG_SZ",GUICtrlRead($Input1))
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Favorites","REG_SZ",GUICtrlRead($Input2))
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Cache","REG_SZ",GUICtrlRead($Input3))
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Cookies","REG_SZ",GUICtrlRead($Input4))
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","History","REG_SZ",GUICtrlRead($Input5))
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal","REG_SZ",GUICtrlRead($Input6))

      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","AppData","REG_SZ",GUICtrlRead($Input1))
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","Favorites","REG_SZ",GUICtrlRead($Input2))
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","Cache","REG_SZ",GUICtrlRead($Input3))
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","Cookies","REG_SZ",GUICtrlRead($Input4))
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","History","REG_SZ",GUICtrlRead($Input5))
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","Personal","REG_SZ",GUICtrlRead($Input6))

    Case $Button3
      Exit

;~ 选择按钮开始
    Case $Button4
      $s1=FileSelectFolder("选择文件夹", "",7,$appd)
      If @error=1 Then
      Else
        GUICtrlSetData($Input1,$s1)
      EndIf

    Case $Button5
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","AppData","REG_SZ",GUICtrlRead($Input1))

    Case $Button6
      $s2=FileSelectFolder("选择文件夹", "",7,$favo)
      If @error=1 Then
      Else
        GUICtrlSetData($Input2,$s2)
      EndIf

    Case $Button7
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Favorites","REG_SZ",GUICtrlRead($Input2))

    Case $Button8
      $s3=FileSelectFolder("选择文件夹", "",7,$cach)
      If @error=1 Then
      Else
        GUICtrlSetData($Input3,$s3)
      EndIf

    Case $Button9
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Cache","REG_SZ",GUICtrlRead($Input3))

    Case $Button10
      $s4=FileSelectFolder("选择文件夹", "",7,$cook)
      If @error=1 Then
      Else
        GUICtrlSetData($Input4,$s4)
      EndIf

    Case $Button11
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Cookies","REG_SZ",GUICtrlRead($Input4))

    Case $Button12
      $s5=FileSelectFolder("选择文件夹", "",7,$hist)
      If @error=1 Then
      Else
        GUICtrlSetData($Input5,$s5)
      EndIf

    Case $Button13
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","History","REG_SZ",GUICtrlRead($Input5))

    Case $Button14
      $s6=FileSelectFolder("选择文件夹", "",7,$docu)
      If @error=1 Then
      Else
        GUICtrlSetData($Input6,$s6)
      EndIf

    Case $Button15
      RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal","REG_SZ",GUICtrlRead($Input6))
;~ 结束6组按钮

    Case $Button16
      $found=IniRead ( "system.ini", "config","Appdate", 3 )
      If $found =3 Then
        MsgBox(0,"没有找到文件","没有找到,请先保存推荐值")
      Else
        $s1=IniRead(@ScriptDir&"\system.ini","config","Appdate",3)
        $s2=IniRead(@ScriptDir&"\system.ini","config","Favorites",3)
        $s3=IniRead(@ScriptDir&"\system.ini","config","Cache",3)
        $s4=IniRead(@ScriptDir&"\system.ini","config","Cookies",3)
        $s5=IniRead(@ScriptDir&"\system.ini","config","History",3)
        $s6=IniRead(@ScriptDir&"\system.ini","config","My Document",3)
        GUICtrlSetData($Input1,$s1)
        GUICtrlSetData($Input2,$s2)
        GUICtrlSetData($Input3,$s3)
        GUICtrlSetData($Input4,$s4)
        GUICtrlSetData($Input5,$s5)
        GUICtrlSetData($Input6,$s6)
      EndIf

    Case $Button17
      IniWrite(@ScriptDir&"\system.ini","config","Appdate",GUICtrlRead($Input1))
      IniWrite(@ScriptDir&"\system.ini","config","Favorites",GUICtrlRead($Input2))
      IniWrite(@ScriptDir&"\system.ini","config","Cache",GUICtrlRead($Input3))
      IniWrite(@ScriptDir&"\system.ini","config","Cookies",GUICtrlRead($Input4))
      IniWrite(@ScriptDir&"\system.ini","config","History",GUICtrlRead($Input5))
      IniWrite(@ScriptDir&"\system.ini","config","My Document",GUICtrlRead($Input6))

  EndSwitch
WEnd

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据