0

Various: Delete a vb script after running (this script will self destruct in xx seconds)

Posted September 8th, 2010 in Various, vbscript and tagged , by dirk adamsky

Yesterday I did some work on VMware VDI.

I had a problem with the clones joining the 2003 domain.
The joining fails for 5% of the new cloned Win XP machines.
VMware VDI uses sysprep to rename, join domain, etc.
The sysprep inf file is generated by a customization specification.
Also in the customization specification I had a small afterjob that
moves the computer account to the right AD container (I used the Dsmod utility),
this afterjob also failed in 5% of the cases.

I decided to do some scripting.
The script to join the domain I already had, I only had to add 2 parts:

  1. Something to remove the script after running (because it contains admin credentials)
  2. Something to reboot the machine after running the job

For the destruction of the script after running I found this code:

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(Wscript.ScriptFullName)
Set objFSO = Nothing

Cut and paste this code at the end of your script.
Normally the script code is parsed before running so there should be no File Locking problem removing the script.

Tomorrow I will post the completed script with:

  • Join domain
  • Add the right container
  • Remove the script file
  • Reboot the machine

Happy scripting.

Best regards,

Dirk Adamsky – Deludi BV

[adrotate group="3"]


Related Posts:
  • Active Directory: Vbscript to enumerate all Active Directory users sorted by OU
  • Active Directory: VBscript to enumerate the home directories and their sizes of all users in Active Directory
  • Active Directory: VBscript to enumerate the local profile size of all computers and users in Active Directory

  • Leave a Reply