MSFN Forum: Add runonce script - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Add runonce script How to put all in one script Rate Topic: -----

#1 User is offline   DeanV 

  • Group: Members
  • Posts: 2
  • Joined: 24-September 12
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 24 September 2012 - 08:59 AM

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. :rolleyes:
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 Explicit

Dim objWMIService, objItem, colItems, strComputer, StrDNSDomain

strComputer ="."
StrDNSDomain ="DOMAIN.com"

Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled=True")

On error Resume Next

For Each objItem In colItems
'WScript.Echo objItem.DNSDomain
objItem.SetDNSDomain(StrDNSDomain)
Next
____________________________________________________________

Set WSHShell = wscript.CreateObject("Wscript.Shell")
Wscript.sleep 10000
____________________________________________________________

Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2

strDomain = "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.ComputerName

Set 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.


#2 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 24 September 2012 - 10:35 AM

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



#3 User is offline   DeanV 

  • Group: Members
  • Posts: 2
  • Joined: 24-September 12
  • OS:Windows 7 x64
  • Country: Country Flag

Posted 24 September 2012 - 03:17 PM

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 .....?

#4 User is offline   gunsmokingman 

  • MSFN Master
  • Group: Super Moderator
  • Posts: 2,352
  • Joined: 02-August 03
  • OS:none specified
  • Country: Country Flag

Posted 24 September 2012 - 03:49 PM

You could make one big script and use the delete example at the end of the script.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy