2014-02-28 125 views
0

我們有一個登錄腳本,用於在通過組策略部署的用戶桌面上設置默認快捷方式。這個腳本被用在我們以前的Windows XP環境中。問題是,設置此人的人將快捷方式複製到%ALLUSERSPROFILE $ \ Desktop。現在我們在Windows 7中,我試圖將快捷方式移動到%USERPROFILE%\ Desktop,並且當我嘗試通過vbscript刪除快捷方式時,我得到權限被拒絕。我可以手動刪除快捷方式,UAC提示符出現,但它可以工作。嘗試通過vbscript刪除文件時,權限被拒絕

三問出來的這個:

1)在什麼情況下用戶不會從GPO運行時,腳本運行?

2)當我從命令行運行腳本並以管理員身份運行命令提示符時,腳本在運行時運行的用戶上下文中?

3)有沒有辦法在我的情況下通過VBScript刪除這些?

在此先感謝您的幫助。


我嘗試使用以下通過GP部署的腳本作爲啓動腳本無濟於事。

'Startup Script 

' Force explicit variable declaration. 
Option Explicit 

On Error Resume Next 

Const sPhoneLnk = "Phone_List.lnk" 
Const sDesktop = "\Desktop\" 

Dim g_oShell, g_oFSO, sAllUsrPrf, sPhoneLink 

Set g_oShell = CreateObject("Wscript.Shell") 
Set g_oFSO = CreateObject("Scripting.FileSystemObject") 

sAllUsrPrf = g_oShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%") 
sPhoneLink = sAllUsrPrf & sDesktop & sPhoneLnk 

If g_oFSO.FileExists (sPhoneLink) Then 
' wscript.echo sPhoneLnk & " Found." 
    g_oFSO.DeleteFile (sPhoneLink) 
' wscript.echo sPhoneLnk & " Deleted." 
Else 
' wscript.echo sPhoneLnk & " Not found." 
End if 

我也嘗試在命令提示符下運行上述腳本,因爲UAC管理員關閉並接收到訪問被拒絕。

回答

0

1)從GPO運行腳本時,腳本運行在哪個用戶上下文中?

登錄腳本激活時登錄的用戶的安全性。

2)當我從命令行運行腳本並以管理員身份運行命令提示符時,腳本在運行時運行的用戶上下文中?

腳本以本地計算機上的管理員身份運行。

3)有沒有辦法在我的情況下通過VBScript刪除這些?

是的。但是你應該考慮,你需要多長時間安裝這個腳本?它是暫時的還是永久的。如果是暫時的,你應該寫一個simple computer startup script which remotes the shortcut links under the all users directory on boot.這樣它就不會綁定到用戶帳戶。

如果您絕對要繞過所有用戶帳戶的安全性,並在用戶登錄時執行操作,無論如何。您可以使用domain logon based vbscript

' ====================================================================== 
'| name : DSMoveAs.vbs 
'| author: Remco Simons [nl] 2007 
'| 
'| (http://www.petri.co.il/forums/showthread.php?t=18003) 
' ====================================================================== 
' 
' this script accepts Credentials from command-line 
' Usage with GPO: 
' Scripts/LogonScript/scriptName  -> scriptname.vbs 
' Scripts/LogonScript/ScriptParameters -> /u:"domain\user" /p:"password" 
'(this user does not nessecarily have to be a member of the Domain Admins group, you can just delegate control over the OU's to it. 
' 
' this script can move computer objects in active directory 
' you have to copy 'dsmove.exe' to a central share 


Set objSysInfo = CreateObject("ADSystemInfo") 
strComputerDN = objSysInfo.ComputerName 
strComputerRDN = split(strComputerDN,",")(0) 
strCurrentOU = Replace(strComputerDN, strComputerRDN & ",","") 
strCurrentSite = UCase(objSysInfo.SiteName) 

'tool 
pathDSMOVE = "\\domain.local\sysvol\domain.local\scripts\Dsmove.exe" 

'Alternate Credentials 
Set Named = WScript.Arguments.Named 'Read script parameters 
    strUser = Empty 
    strSecret = Empty 
If Named.Exists("u") Then 
    strUser = Named.Item("u") 
If Named.Exists("p") Then _ 
    strSecret = Named.Item("p") 
End If 
altCredentials = " -u """ & strUser & """ -p """ & strSecret & """" 

'variables 
strSiteName1 = UCase("New-York") 
strSiteName2 = UCase("washington") 

'conditional run 
If (strCurrentSite = strSiteName1) Then 
    strNewOU = "CN=computers,DC=domain,dc=Local" 
    If Not UCase(strCurrentOU) = Ucase(strNewOU) Then 
    call MoveObject(pathDSMOVE, strComputerDN, strNewOU, altCredentials) 
    End If 
ElseIf (strCurrentSite = strSiteName2) Then 
    strNewOU = "ou=workstations,DC=domain,dc=Local" 
    If Not UCase(strCurrentOU) = Ucase(strNewOU) Then 
    call MoveObject(pathDSMOVE, strComputerDN, strNewOU, altCredentials) 
    End If 
End If 


Sub MoveObject(pathDsmove, strComputerDN, targetOU, credentials) 
With Wscript.CreateObject("WScript.Shell") 
    strCommand = pathDsmove & " """ & strComputerDN & """ " _ 
       & "-newparent """ & targetOU & """ " _ 
       & credentials 
    .Run "%comspec% /c @call " & strCommand,0,True 
End With 
End Sub 
+0

看來,儘管我在本地運行腳本(用於測試),但仍然收到Access拒絕UAC阻止請求。有沒有辦法繞過這個? –

0

我推薦使用Group Policy Preferences修改桌面快捷方式。登錄腳本始終在用戶登錄的上下文中運行。該用戶可能具有或不具有從「所有用戶」桌面刪除快捷方式的足夠權限。

相關問題