簡體   English   中英

嘗試通過vbscript刪除文件時權限被拒絕

[英]Permission denied when trying to delete file via vbscript

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

由此產生三個問題:

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並收到拒絕訪問的信息。

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

登錄腳本會隨着用戶登錄的安全性而激活。

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

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

3)在我的情況下,有沒有辦法通過vbscript刪除這些文件?

是。 但是您應該考慮,您需要將該腳本安裝多長時間? 是臨時的還是永久的。 如果是臨時的,則應編寫一個簡單的計算機啟動腳本,該腳本在啟動時將所有用戶目錄下的快捷方式鏈接遠程化。 這樣,它就不會與用戶帳戶綁定。

如果您絕對想繞過所有用戶帳戶的安全性,無論如何都對用戶登錄執行操作。 您可以使用基於域登錄的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

我建議使用組策略首選項來修改桌面快捷方式。 登錄腳本始終在用戶登錄的上下文中運行。該用戶可能具有或沒有足夠的特權,可以從“所有用戶”桌面刪除快捷方式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM