i made an installation script... it is working but i have a problem with the last part.
At the end of the script, i want to delete the current script after installation is complete
here is the code i am using to self-delete the install:
Option Explicit
DeleteSelf
Sub DeleteSelf()
Dim objFSO
'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Delete the currently executing script
objFSO.DeleteFile WScript.ScriptFullName
Set objFSO = Nothing
End Sub
it works very well if i use the code alone
but when i put it at the end of my script, i get an error..... why ???
here is the full script
Const HKEY_CLASSES_ROOT = &H80000000
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Folder\Shell\Copier la liste des fichiers dans le presse-papier\Command"
objRegistry.CreateKey HKEY_CLASSES_ROOT,strKeyPath
strValue = "%SystemRoot%\system32\wscript.exe C:\WINDOWS\system32\OutilUploadeur.vbs //nologo ""%1"" "
objRegistry.SetExpandedStringValue HKEY_CLASSES_ROOT,strKeyPath,vbNullString,strValue
'copier les fichiers dans system32
Dim objFSO, WshShell, delay, objDestinationFolder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
'set the time (in seconds) that the "Please Wait" window will be displayed on the screen
delay = 4
'enter the path to destination folder
objDestinationFolder = "C:\WINDOWS\System32"
'if the destination folder does not exist, it will be created
If Not objFSO.FolderExists(objDestinationFolder) Then objFSO.CreateFolder (objDestinationFolder) End If
'enter the name of the source files that reside inside the current folder
'the "True" argument means that existing files in destination folder will be overwritten
ObjFSO.CopyFile "*.vbs", (objDestinationFolder), True
'this will create a new System Environment Variable called PROGRAMSRV with the value port@localhost
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROGRAMSRV", "port@localhost", "REG_SZ"
'this is a trick - will display a "Please Wait" window even though the script is finished
'why you ask?
'the user needs to see that something runs when he clicks the .vbs file
WshShell.Popup "Installation...", (delay), "Installation......", 5
Set objFSO = Nothing
Set WshShell = Nothing
'apres install supprimer le setup
Option Explicit
MsgBox "Installation réeussie", 64 + 262144, "Install finished"
DeleteSelf
Sub DeleteSelf()
Dim objFSO
'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Delete the currently executing script
objFSO.DeleteFile WScript.ScriptFullName
Set objFSO = Nothing
End Sub
At the end of the script, i want to delete the current script after installation is complete
here is the code i am using to self-delete the install:
Option Explicit
DeleteSelf
Sub DeleteSelf()
Dim objFSO
'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Delete the currently executing script
objFSO.DeleteFile WScript.ScriptFullName
Set objFSO = Nothing
End Sub
it works very well if i use the code alone
but when i put it at the end of my script, i get an error..... why ???
here is the full script
Const HKEY_CLASSES_ROOT = &H80000000
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Folder\Shell\Copier la liste des fichiers dans le presse-papier\Command"
objRegistry.CreateKey HKEY_CLASSES_ROOT,strKeyPath
strValue = "%SystemRoot%\system32\wscript.exe C:\WINDOWS\system32\OutilUploadeur.vbs //nologo ""%1"" "
objRegistry.SetExpandedStringValue HKEY_CLASSES_ROOT,strKeyPath,vbNullString,strValue
'copier les fichiers dans system32
Dim objFSO, WshShell, delay, objDestinationFolder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
'set the time (in seconds) that the "Please Wait" window will be displayed on the screen
delay = 4
'enter the path to destination folder
objDestinationFolder = "C:\WINDOWS\System32"
'if the destination folder does not exist, it will be created
If Not objFSO.FolderExists(objDestinationFolder) Then objFSO.CreateFolder (objDestinationFolder) End If
'enter the name of the source files that reside inside the current folder
'the "True" argument means that existing files in destination folder will be overwritten
ObjFSO.CopyFile "*.vbs", (objDestinationFolder), True
'this will create a new System Environment Variable called PROGRAMSRV with the value port@localhost
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROGRAMSRV", "port@localhost", "REG_SZ"
'this is a trick - will display a "Please Wait" window even though the script is finished
'why you ask?
'the user needs to see that something runs when he clicks the .vbs file
WshShell.Popup "Installation...", (delay), "Installation......", 5
Set objFSO = Nothing
Set WshShell = Nothing
'apres install supprimer le setup
Option Explicit
MsgBox "Installation réeussie", 64 + 262144, "Install finished"
DeleteSelf
Sub DeleteSelf()
Dim objFSO
'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Delete the currently executing script
objFSO.DeleteFile WScript.ScriptFullName
Set objFSO = Nothing
End Sub