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 & "*.*")

Re: problems delete files and folders from desktop for domain user by Franz

Franz
Mon Jul 23 17:26:40 CDT 2007

Computerguy 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 & "*.*")

uh uh... someone is missing a "\" ;)

objFSO.DeleteFile (DesktopPath & "\*.*")







Re: problems delete files and folders from desktop for domain user by Owen

Owen
Mon Jul 23 18:10:44 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 & "*.*")

I am confused. If the users have their profile paths under user.domain
\desktop then %UserProfile% should expand and point you to the right
directory. You should not have to "add" anything to make it work,
just resolve the user profile path.

What am I missing?

Owen


Re: problems delete files and folders from desktop for domain user by Owen

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


Re: problems delete files and folders from desktop for domain user by Franz

Franz
Tue Jul 24 14:54:53 CDT 2007

Owen Gilmore wrote:
> 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 & "*.*")
>
> I am confused. If the users have their profile paths under
> user.domain \desktop then %UserProfile% should expand and point you
> to the right directory. You should not have to "add" anything to
> make it work, just resolve the user profile path.
>
> What am I missing?

The basics of syntax :D (just kidding)

By the way, try this:

Set Shell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
DesktopPath = Shell.SpecialFolders("Desktop")

msgbox DesktopPath & "*.*" ,16,"Wrong !!!"
msgbox DesktopPath & "\*.*" ,64,"Correct :)"