DeanV Posted September 24, 2012 Share Posted September 24, 2012 Hi all,First of all I'm new to VBS scripting, I'm trying to build a script that start with a sleep command and then set the DNS Suffix on the NIC, join the (Virtual) machine to a domain and then delete the script after the unattended.xml (is working) is finished, but untill now I'm not very succesfull with it.The script will be started from the runonce registry (cscript //b c:\windows\system32\sysprep\*.VBS) after the autologon through the unattended.xml.All script seperate are working. PLease help me to put this in one file. Thanks in advance.these script I'm trying to put togheter in one *.VBS.Set WSHShell = wscript.CreateObject("Wscript.Shell")Wscript.sleep 20000_______________________________________________________Option ExplicitDim objWMIService, objItem, colItems, strComputer, StrDNSDomainstrComputer ="." StrDNSDomain ="DOMAIN.com"Set objWMIService = GetObject _ ("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery _ ("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled=True")On error Resume NextFor Each objItem In colItems 'WScript.Echo objItem.DNSDomain objItem.SetDNSDomain(StrDNSDomain) Next____________________________________________________________Set WSHShell = wscript.CreateObject("Wscript.Shell")Wscript.sleep 10000____________________________________________________________Const JOIN_DOMAIN = 1Const ACCT_CREATE = 2strDomain = "Domain.com"strUser = "Service_account"strPassword = "Password"strOU = "OU=VDI,OU=Hyper-V,OU=No WSUS Servers,OU=CORP,DC=grontmij,DC=net"Set objNetwork = CreateObject("WScript.Network")strComputer = objNetwork.ComputerNameSet objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")objComputer.JoinDomainOrWorkGroup strDomain, strPassword, strDomain & "\" & strUser, strOU, JOIN_DOMAIN + ACCT_CREATE____________________________________________________________________Set WSHShell = wscript.CreateObject("Wscript.Shell")Wscript.sleep 60000______________________________________________________________________Here should be the delete command of this file?_______________________________________________________________________Set WSHShell = Wscript.CreateObject("WScript.Shell")WshShell.Run "c:\windows\system32\shutdown.exe /r /t 20"Thanks. Link to comment Share on other sites More sharing options...
gunsmokingman Posted September 24, 2012 Share Posted September 24, 2012 You can not delete the file without creating Scripting.FileSystemObject,Save As Demo_Delete.vbs'-> Object For Files Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")'-> Msgbox With Path And Script Name WScript.Echo WScript.ScriptFullName'-> Delete The File Fso.DeleteFile(WScript.ScriptFullName),True Link to comment Share on other sites More sharing options...
DeanV Posted September 24, 2012 Author Share Posted September 24, 2012 Hi Gunsmokingman,Thanks for the script. Should this be a seperate VBS or can I place it in the missing part of the script?and Is it possible to place all the commands in one script and will it run or .....? Link to comment Share on other sites More sharing options...
gunsmokingman Posted September 24, 2012 Share Posted September 24, 2012 You could make one big script and use the delete example at the end of the script. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now