為全體使用者自動修改“我的文件”、“桌面”、“臨時目錄”的路徑
阿新 • • 發佈:2019-02-12
'*********************************************************************************
' 使用者登入指令碼
' 在使用者目錄下建立以使用者名稱命名的目錄, 再分別建立MyDocuments與Desktop、Temp目錄
' 對使用者目錄進行授予使用者獨佔的許可權
' 更改使用者的文件路徑、桌面路徑、Temp環境變數的路徑
' write by: tanxiancheng.blog.163.com 譚仙成 2006-8-31
'*********************************************************************************
Const USER_HOME = "D:/Home"
Dim arrEnvironment, strUserName
Dim objShell, objFileSystem
Set objShell = CreateObject("Wscript.Shell")
Set arrEnvironment = objShell.Environment("Process") '程序的環境變數
strUserName = arrEnvironment("USERNAME") '取使用者名稱
Set objFileSystem = CreateObject("Scripting.FileSystemObject" )
If Not objFileSystem.FolderExists(USER_HOME & "/" & strUserName) Then '建立使用者主目錄
objFileSystem.CreateFolder(USER_HOME & "/" & strUserName)
'對使用者的主目錄授予使用者完全的許可權及超級使用者組完全的許可權
objShell.Exec("yes.bat | cacls.exe " & USER_HOME & "/" & strUserName & " /T /G " & strUserName & ":F Administrators:F" )
End If
If Not objFileSystem.FolderExists(USER_HOME & "/" & strUserName & "/My Documents") Then '建立使用者文件目錄
objFileSystem.CreateFolder(USER_HOME & "/" & strUserName & "/My Documents")
End If
If Not objFileSystem.FolderExists(USER_HOME & "/" & strUserName & "/My Documents/My Pictures") Then '建立使用者圖片目錄
objFileSystem.CreateFolder(USER_HOME & "/" & strUserName & "/My Documents/My Pictures")
End If
If Not objFileSystem.FolderExists(USER_HOME & "/" & strUserName & "/My Documents/My Music") Then '建立使用者音樂目錄
objFileSystem.CreateFolder(USER_HOME & "/" & strUserName & "/My Documents/My Music")
End If
If Not objFileSystem.FolderExists(USER_HOME & "/" & strUserName & "/My Documents/My Video") Then '建立使用者影視目錄
objFileSystem.CreateFolder(USER_HOME & "/" & strUserName & "/My Documents/My Video")
End If
If Not objFileSystem.FolderExists(USER_HOME & "/" & strUserName & "/Desktop") Then '建立使用者桌面目錄
objFileSystem.CreateFolder(USER_HOME & "/" & strUserName & "/Desktop")
End If
If Not objFileSystem.FolderExists(USER_HOME & "/" & strUserName & "/Temp") Then '建立使用者臨時目錄
objFileSystem.CreateFolder(USER_HOME & "/" & strUserName & "/Temp")
End If
'更改使用者桌面、我的文件、臨時目錄的路徑
Const REG_SHELL_FOLDER = "HKEY_CURRENT_USER/SoftWare/Microsoft/Windows/CurrentVersion/Explorer/User Shell Folders"
Const REG_ENVIRONMENT = "HKEY_CURRENT_USER/Environment"
objShell.RegWrite REG_SHELL_FOLDER & "/Personal", USER_HOME & "/" & strUserName & "/My Documents"
objShell.RegWrite REG_SHELL_FOLDER & "/My Pictures", USER_HOME & "/" & strUserName & "/My Documents/My Pictures"
objShell.RegWrite REG_SHELL_FOLDER & "/My Music", USER_HOME & "/" & strUserName & "/My Documents/My Music"
objShell.RegWrite REG_SHELL_FOLDER & "/My Video", USER_HOME & "/" & strUserName & "/My Documents/My Video"
objShell.RegWrite REG_SHELL_FOLDER & "/Desktop", USER_HOME & "/" & strUserName & "/Desktop"
objShell.RegWrite REG_ENVIRONMENT & "/Temp", USER_HOME & "/" & strUserName & "/Temp"
objShell.RegWrite REG_ENVIRONMENT & "/Tmp", USER_HOME & "/" & strUserName & "/Temp"
Set objFileSystem = Nothing
Set objShell = Nothing
WScript.Quit(0)
' 使用者登入指令碼
' 在使用者目錄下建立以使用者名稱命名的目錄, 再分別建立MyDocuments與Desktop、Temp目錄
' 對使用者目錄進行授予使用者獨佔的許可權
' 更改使用者的文件路徑、桌面路徑、Temp環境變數的路徑
' write by: tanxiancheng.blog.163.com 譚仙成 2006-8-31
'*********************************************************************************
Const USER_HOME = "D:/Home"
Dim arrEnvironment, strUserName
Dim objShell, objFileSystem
Set objShell = CreateObject("Wscript.Shell")
Set arrEnvironment = objShell.Environment("Process") '程序的環境變數
strUserName = arrEnvironment("USERNAME") '取使用者名稱
Set objFileSystem = CreateObject("Scripting.FileSystemObject"
If Not objFileSystem.FolderExists(USER_HOME & "/" & strUserName) Then '建立使用者主目錄
objFileSystem.CreateFolder(USER_HOME & "/" & strUserName)
'對使用者的主目錄授予使用者完全的許可權及超級使用者組完全的許可權
objShell.Exec("yes.bat | cacls.exe " & USER_HOME & "/" & strUserName & " /T /G " & strUserName & ":F Administrators:F"
End If
If Not objFileSystem.FolderExists(USER_HOME & "/" & strUserName & "/My Documents") Then '建立使用者文件目錄
objFileSystem.CreateFolder(USER_HOME & "/" & strUserName & "/My Documents")
End If
If Not objFileSystem.FolderExists(USER_HOME & "/" & strUserName & "/My Documents/My Pictures") Then '建立使用者圖片目錄
objFileSystem.CreateFolder(USER_HOME & "/" & strUserName & "/My Documents/My Pictures")
End If
If Not objFileSystem.FolderExists(USER_HOME & "/" & strUserName & "/My Documents/My Music") Then '建立使用者音樂目錄
objFileSystem.CreateFolder(USER_HOME & "/" & strUserName & "/My Documents/My Music")
End If
If Not objFileSystem.FolderExists(USER_HOME & "/" & strUserName & "/My Documents/My Video") Then '建立使用者影視目錄
objFileSystem.CreateFolder(USER_HOME & "/" & strUserName & "/My Documents/My Video")
End If
If Not objFileSystem.FolderExists(USER_HOME & "/" & strUserName & "/Desktop") Then '建立使用者桌面目錄
objFileSystem.CreateFolder(USER_HOME & "/" & strUserName & "/Desktop")
End If
If Not objFileSystem.FolderExists(USER_HOME & "/" & strUserName & "/Temp") Then '建立使用者臨時目錄
objFileSystem.CreateFolder(USER_HOME & "/" & strUserName & "/Temp")
End If
'更改使用者桌面、我的文件、臨時目錄的路徑
Const REG_SHELL_FOLDER = "HKEY_CURRENT_USER/SoftWare/Microsoft/Windows/CurrentVersion/Explorer/User Shell Folders"
Const REG_ENVIRONMENT = "HKEY_CURRENT_USER/Environment"
objShell.RegWrite REG_SHELL_FOLDER & "/Personal", USER_HOME & "/" & strUserName & "/My Documents"
objShell.RegWrite REG_SHELL_FOLDER & "/My Pictures", USER_HOME & "/" & strUserName & "/My Documents/My Pictures"
objShell.RegWrite REG_SHELL_FOLDER & "/My Music", USER_HOME & "/" & strUserName & "/My Documents/My Music"
objShell.RegWrite REG_SHELL_FOLDER & "/My Video", USER_HOME & "/" & strUserName & "/My Documents/My Video"
objShell.RegWrite REG_SHELL_FOLDER & "/Desktop", USER_HOME & "/" & strUserName & "/Desktop"
objShell.RegWrite REG_ENVIRONMENT & "/Temp", USER_HOME & "/" & strUserName & "/Temp"
objShell.RegWrite REG_ENVIRONMENT & "/Tmp", USER_HOME & "/" & strUserName & "/Temp"
Set objFileSystem = Nothing
Set objShell = Nothing
WScript.Quit(0)