VBScript to Delete file using Wise Variables
Hello guys,
I am trying to find a VBscript similar to the following:
I would like to Embed this code in a VBScript Custom Action. Now, the file I'd like to delete resides on the desktop of AllUsers. I was hoping to be able to swap out some hard coded paths with variables that Wise uses. Thing is, we have English and French OS's, so ideally, I'd like to delete something along the lines of
%ALLUSERSPROFILES%\Desktop and %ALLUSERSPROFILES%\Bureau. I'm not sure, does Wise use a Variable pointing directly to the desktop? I wasn't able to find it? And, how would one include this variable directly in this snippet of code?
I'll keep looking, but any help you may supply would greatly be appreciated.
Thanks all!
Stephane
I am trying to find a VBscript similar to the following:
' ------ SCRIPT CONFIGURATION ------
strFilePath = "<FilePath>" ' e.g. "d:\scripts\test.txt"
' ------ END CONFIGURATION ---------
set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(strFilePath)
WScript.Echo "Successfully deleted file"
I would like to Embed this code in a VBScript Custom Action. Now, the file I'd like to delete resides on the desktop of AllUsers. I was hoping to be able to swap out some hard coded paths with variables that Wise uses. Thing is, we have English and French OS's, so ideally, I'd like to delete something along the lines of
%ALLUSERSPROFILES%\Desktop and %ALLUSERSPROFILES%\Bureau. I'm not sure, does Wise use a Variable pointing directly to the desktop? I wasn't able to find it? And, how would one include this variable directly in this snippet of code?
I'll keep looking, but any help you may supply would greatly be appreciated.
Thanks all!
Stephane
0 Comments
[ + ] Show comments
Answers (11)
Please log in to answer
Posted by:
anonymous_9363
15 years ago
Posted by:
Fau
15 years ago
Hello sir!
You are indeed right. But i was under the impression that to use the RemoveFile table you needed to link your file to a Component first right?
Essentially, I'm trying to remove a shortcut from the All Users Desktop. I can't find the shortcut neither in Shortcuts, Shortcuts Table, Custom Action, no where. Hence why I've come to the resolve that removing it via script would solve the problem.
Since I can't find the shortcut in none of the Component's of my MSI, can I still use the RemoveFile Table even tough the file doesn't seem to be linked no where?
You are indeed right. But i was under the impression that to use the RemoveFile table you needed to link your file to a Component first right?
Essentially, I'm trying to remove a shortcut from the All Users Desktop. I can't find the shortcut neither in Shortcuts, Shortcuts Table, Custom Action, no where. Hence why I've come to the resolve that removing it via script would solve the problem.
Since I can't find the shortcut in none of the Component's of my MSI, can I still use the RemoveFile Table even tough the file doesn't seem to be linked no where?
Posted by:
anonymous_9363
15 years ago
Posted by:
turbokitty
15 years ago
What you may need to consider is that the file might be created there with a custom action or external process that takes place after the RemoveFile action. I agree that you should try the RemoveFile table first though.
This is one of my favorite sites on the internet:
http://www.cruto.com/resources/vbscript/vbscript-examples/vbscript-sitemap.asp
This is one of my favorite sites on the internet:
http://www.cruto.com/resources/vbscript/vbscript-examples/vbscript-sitemap.asp
Posted by:
Fau
15 years ago
Hello guys!
Ok, so here I am, on this problem again. I did as suggested by Ian, to no avail. I think I'm having exactly what TK implied: my shortcut is created after the RemoveFile action. Now, I tried circumventing this by copying the RemoveFile action from my custom action to Remove File 1 and placing it at the end of my custom actions list. However, this was not a success since other actions seem to depend upon this.
Which leaves me back to my initial solution: scripting a code and embedding it in a CA. (By the way, thanks TK, super site, bookmarked for future use!!!!).
So, is there a way i can map myself directly on the desktop in order to get something along the lines of:
strFilePath = %ALLUSERSPROFILES% & "\Desktop" (using Windows Variables) and/or,
strFilePath = [DesktopFolder] (using Wise Variables)
instead of
strFilePath = "C:\Documents and Settings\All Users\Desktop"
?
If at all possible, I'd like to avoid having to test for which language of XP is installed before setting my variable.
Anyway, Thanks for your continued help on the matter!
Stephane
Ok, so here I am, on this problem again. I did as suggested by Ian, to no avail. I think I'm having exactly what TK implied: my shortcut is created after the RemoveFile action. Now, I tried circumventing this by copying the RemoveFile action from my custom action to Remove File 1 and placing it at the end of my custom actions list. However, this was not a success since other actions seem to depend upon this.
Which leaves me back to my initial solution: scripting a code and embedding it in a CA. (By the way, thanks TK, super site, bookmarked for future use!!!!).
So, is there a way i can map myself directly on the desktop in order to get something along the lines of:
strFilePath = %ALLUSERSPROFILES% & "\Desktop" (using Windows Variables) and/or,
strFilePath = [DesktopFolder] (using Wise Variables)
instead of
strFilePath = "C:\Documents and Settings\All Users\Desktop"
?
If at all possible, I'd like to avoid having to test for which language of XP is installed before setting my variable.
Anyway, Thanks for your continued help on the matter!
Stephane
Posted by:
anonymous_9363
15 years ago
I think I'm having exactly what TK implied: my shortcut is created after the RemoveFile action.If it's the case that a CA is creating the shortcut, you can avoid all the heartache you're going through simply by preventing that CA from running. The easiest route is to add an impossible-to-meet condition to it. I normally use '0=1' as it's hard to think of a condition which is more impossible to meet! [waits for lengthy argument from mathemeticians...]
Posted by:
Fau
15 years ago
Posted by:
anonymous_9363
15 years ago
Posted by:
McRip
15 years ago
This will help you deleting the file via VBS Script on all users Desktop folder if file exists:
Example
Cheers
Example
'this script will check the file exists, and then it will delete it.
Option Explicit
On Error Resume next
Const alluser = &H19&
Dim Objshell
Dim oFSO
Dim filetokill
Dim oAlluser
Dim oAlluserItem
Set oFSO = Createobject("scripting.filesystemobject")
Set objShell = CreateObject("Shell.Application")
Set oAlluser = objShell.Namespace(alluser)
Set oAlluserItem = oAlluser.Self
filetokill = oAlluserItem.Path & "\Test.url" 'Just replace this item with your file you want to delete
If oFSO.fileexists (filetokill) Then
oFSO.deletefile (filetokill)
End If
on error goto 0
Cheers
Posted by:
abking99
15 years ago
Posted by:
McRip
15 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.