Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with a self-delete script

Status
Not open for further replies.

anarchoi

Technical User
Jun 29, 2009
12
CA
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

 
what is the error, on which line etc?

I get a 'complilation error: Expected statement' on line 3 of this script...it would appear in my script that you must put Option Explicit as the first line in your code.....

where does your code error?


strX = """C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe"" -sBKUPEXEC"""
strY = Left(strX, InStrRev(strX, " "))
Option Explicit

Msgbox strY
 
btw, i thought WshShell.Popup was a blocked method call? i.e. your script doesnt continue until the Popup has finished
 
the error is on line 66 "compilation error expected statement)"

I tryed putting Option Explicit at the begginning but then i would get an error saying "strComputer variable not defined".... But without Option Explicit this part of the script works


as for WshShell.Popup maybe the problem comes from there... i didn't write this part of the script, i found it on google..... But i thought the script would continue after the delay (a few seconds) ???
 
its up to you.
if you want to use Option Explicit then put it at the top of your script. If you use Option Explicit then you must declare your variables with 'Dim strComputer' etc. If you dont want to Dim your variables then just dont put Option Explicit in.

yes, the script will continue once the .Popup method returns....which will be in 5 seconds or less if the user clicks the OK button
 
Ok i got it to work now.... i just had to declare my variables like you said..... i'm dumb !!

thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top