Owen
Mon Jul 23 18:16:55 CDT 2007
On Jul 20, 4:37 am, Computerguy <phil2...@gmail.com> wrote:
> We have a script that will delete files and folders from the desktop
> on login. However, the users logging in have their profiles as
> user.domain and not user so when the script runs it is deleting things
> from c:\documents and settings\user\desktop instead of c:\documents
> and settings\user.domain\desktop. I forget what to add. Part of the
> script is below. Thanks.
>
> strDesktop = objWSH.ExpandEnvironmentStrings("%UserProfile%\desktop\")
>
> '*******Delete Files and Folders from desktop*******
>
> Set Shell = CreateObject("WScript.Shell")
> Set objFSO = CreateObject("Scripting.FileSystemObject")
>
> DesktopPath = Shell.SpecialFolders("Desktop")
>
> objFSO.DeleteFile (DesktopPath & "*.*")
> objFSO.DeleteFile(strDesktop & "*.*")
>
> objFSO.DeleteFolder(strDesktop & "*.*")
Also I forgot to mention in my previous post that the SpecialFolder
method should point you to the correct desktop folder. I found this
on MSDN, hope it helps.
Owen
-----------------------------------------------------------------------
' For Windows 95 Windows Script Host must be installed.
' The following VBScript sample will delete a file called
Sample.txt and
' a folder called "Sample Folder" from the desktop.
' NOTE: To view the results of this script create a file called
' "Sample.txt" and a folder called "Sample Folder" on your desktop
' before you run the script.
'
----------------------------------------------------------------------
Dim WSHShell, DesktopPath
Set WSHShell = WScript.CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
' ON ERROR RESUME NEXT prevents error messages from appearing.
' Useful if the file or folder might have already been removed.
on error resume next
Icon = DesktopPath & "\sample.txt"
Folder = DesktopPath & "\sample folder"
Set fs = CreateObject("Scripting.FileSystemObject")
Set A = fs.GetFile(Icon)
A.Delete
set B = fs.GetFolder(folder)
B.Delete
WScript.Quit
http://support.microsoft.com/kb/197425