' 常量 const APP_TITLE = "设置“打开”对话框的位置条" const REG_PLACESBAR = "HKCU\Software\Microsoft\Windows\ CurrentVersion\Policies\ComDlg32\Placesbar\" Dim place ' 位置编号 Dim canContinue ' 逻辑开关 ' 获取待设置的位置编号 canContinue = True While canContinue place = InputBox("输入位置编号 (0到4)", APP_TITLE, 0) ' 点击了“取消”按钮... If place = "" Then WScript.Quit End If
If place > 4 Then MsgBox "位置编号错误,请指定0-4之间的位置编号!", 16, APP_TITLE Else ' 位置编号合法,从注册表读取信息 ChangePlace place End If Wend ' 修改指定的位置 Sub ChangePlace (place) Dim shell, curPath, buf, rc, newPath, theType
Set shell = CreateObject("WScript.Shell") On Error Resume Next curPath = shell.RegRead(REG_PLACESBAR & "Place" & place) On Error Goto 0 ' 默认值 If curPath = "" Then curPath = "默认值" buf = "" buf = buf & "位置" & place & "当前被设置为" & _ Chr(34) & curPath & Chr(34) & vbCrLf & vbCrLf & _ "点击“是”指定一个普通文件夹" & vbCrLf & _ "点击“否”指定一个系统文件夹" & vbCrLf & _ "点击“取消”退出程序"
rc = MsgBox(buf, 3, APP_TITLE) ' YES=6, NO=7, CANCEL=2 If rc = vbCancel Then Exit Sub
' 修改位置 Select Case rc Case vbYes newPath = InputBox("输入新的文件夹路径", APP_TITLE, curPath) If newPath = "" Then Exit Sub theType = "REG_SZ" Case vbNo buf = "" buf = buf & "选择新的文件夹." & vbCrLf & vbCrLf & _ "5 - 我的文档" & vbCrLf & _ "6 - 收藏" & vbCrLf & _ "17 - 我的电脑" & vbCrLf & _ "18 - 网上邻居" & vbCrLf & _ "36 - Windows系统目录" & vbCrLf & _ "34 - 历史" newPath = InputBox(buf, APP_TITLE, curPath) If newPath = "" Then Exit Sub theType = "REG_Dword" End Select
shell.RegWrite REG_PLACESBAR & "Place" & place, newPath, theType End Sub