Remove a known file from Current User desktop (VBS)

Purpose: Remove a predefined file from every actual user profile folder in a workstation.

In a scenario where you have delivered files to every or some user profiles of a workstation, you need to iterate through the C:\Users\Public\ -subfolders to reach your files. Of course this can be used as well against something that you have not delivered at all. These scenarios can be faulty application shortcuts directly in user desktop, user based configuration files in AppData -folders or similar.

Usage: cscript.exe IT_OSD_VBS_RemoveAFileFromEveryUserProfile.vbs (no parameters exist)
Configuration: You need to insert the file that you want to remove to strFolderPathLocal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
' *********************************************************************************
' ** Script Name: IT_OSD_VBS_RemoveAFileFromEveryUserProfile.vbs
' ** Created on: 08.01.2013
' ** Author: Jyri Lehtonen / http://it.peikkoluola.net
' **
' ** Purpose: Remove a predefined file from every user profile
' ** Usage: IT_OSD_VBS_RemoveAFileFromEveryUserProfile.vbs (no parameters exist)
' **
' ** License: This program is free software: you can redistribute it and/or modify
' ** it under the terms of the GNU General Public License as published by
' ** the Free Software Foundation, either version 3 of the License, or
' ** (at your option) any later version.
' **
' ** This program is distributed in the hope that it will be useful,
' ** but WITHOUT ANY WARRANTY; without even the implied warranty of
' ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' ** GNU General Public License for more details.
' ** 
' ** History: 
' ** 1.0 / Jyri Lehtonen / 01.08.2013 / Initial version.
' *********************************************************************************
 
    '********************************************************************************************
    '******** DELETE A FILE *********************************************************************
    '********************************************************************************************
    Set oWshell = CreateObject("WScript.Shell")
    Set oFileSystem = CreateObject("Scripting.FileSystemObject")
    Set strUsersFolder = oFileSystem.GetFolder("C:\Users\")
    Set strSubFolders = strUsersFolder.SubFolders
 
    For Each subfolder in strSubFolders
        if subfolder.name = "Default" or subfolder.name = "Default User" Then
            Else :
                    strFolderPathLocal = "c:\Users\" & subfolder.name & "\Desktop\Shortcut.lnk"
                    if oFileSystem.FileExists(strFolderPathLocal) Then
                        oFileSystem.DeleteFile strFolderPathLocal
                    End if
        End if
 
    Next
' *********************************************************************************
' ** Script Name: IT_OSD_VBS_RemoveAFileFromEveryUserProfile.vbs
' ** Created on: 08.01.2013
' ** Author: Jyri Lehtonen / http://it.peikkoluola.net
' **
' ** Purpose: Remove a predefined file from every user profile
' ** Usage: IT_OSD_VBS_RemoveAFileFromEveryUserProfile.vbs (no parameters exist)
' **
' ** License: This program is free software: you can redistribute it and/or modify
' ** it under the terms of the GNU General Public License as published by
' ** the Free Software Foundation, either version 3 of the License, or
' ** (at your option) any later version.
' **
' ** This program is distributed in the hope that it will be useful,
' ** but WITHOUT ANY WARRANTY; without even the implied warranty of
' ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' ** GNU General Public License for more details.
' ** 
' ** History: 
' ** 1.0 / Jyri Lehtonen / 01.08.2013 / Initial version.
' *********************************************************************************

	'********************************************************************************************
	'******** DELETE A FILE *********************************************************************
	'********************************************************************************************
	Set oWshell = CreateObject("WScript.Shell")
	Set oFileSystem = CreateObject("Scripting.FileSystemObject")
	Set strUsersFolder = oFileSystem.GetFolder("C:\Users\")
	Set strSubFolders = strUsersFolder.SubFolders

	For Each subfolder in strSubFolders
		if subfolder.name = "Default" or subfolder.name = "Default User" Then
			Else :
					strFolderPathLocal = "c:\Users\" & subfolder.name & "\Desktop\Shortcut.lnk"
					if oFileSystem.FileExists(strFolderPathLocal) Then
						oFileSystem.DeleteFile strFolderPathLocal
					End if
		End if

	Next

Leave a Reply

Your email address will not be published. Required fields are marked *


one + = five

Post Navigation