Re: VBscript that restart the domain comptuer
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 26 Dec 2008 11:29:16 -0600
If you have a shutdown script that cleans up the profiles, all you need is
something to restart the computers. Perhaps a scheduled task with sufficient
permissions can restart (or shutdown) all computers in a list remotely. For
example, to shutdown the computers:
===========
Option Explicit
Dim objWMIService, strComputer, colOperatingSystems, objOperatingSystem
Dim objFSO, objFile
Const SHUTDOWN = 1
Const ForReading = 1
' Specify file of computer NetBIOS names.
strFile = "c:\scripts\Computers.txt"
' Open the text file.
Set objFSO = CreateObjet("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
' Read computer NetBIOS names from the file.
Do Until objFile.AtEndOfStream
strComputer = Trim(objFile.ReadLine)
' Skip blank lines.
If (strComputer <> "") Then
Set objWMIService = GetObject("winmgmts: {(Shutdown)}" _
& "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\"
_
& strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem In colOperatingSystems
objOperatingSystem.Win32Shutdown(SHUTDOWN)
Next
End If
Next
' Clean up.
objFile.Close
=========
If instead you want to restart the computers, use this:
============
If (strComputer <> "") Then
Set objWMIService = GetObject("winmgmts:" _
&
"{impersonationLevel=impersonate,authenticationLevel=Pkt,(Shutdown)}!\\" _
& strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("SELECT * FROM Win32_OperatingSystem")
For Each objOperatingSystem In colOperatingSystems
objOperatingSystem.Reboot()
Next
End If
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
"madal" <madal@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E5E8A7CD-43DE-4F6F-AFAB-911CDFAA8ADC@xxxxxxxxxxxxxxxx
Hello Richard.
Thanks for your detail informaion on the subjected matter. What I am
trying
to do is : I have a small R&D lab were quite a lot people logs in to it. I
do
not maintain romaing profile so everytime user logs on it creats local
users
profile in c:\document setting\username. I have already VB script I
deployed
via GPO in shutdown script and that does the delete all those pofile. But
what I would like to do is write some vbscript that will restart the
machine
let say at midnight and on the same time delete those profiles. Basically
with the script vbscript or bat restart the machine once a day (midnight)
and
when it re-starting should apply the shutdown script that will delete
those
users profile.
Madal
romaing profile .com> wrote in message
news:2E458F2D-48E9-4577-ABA0-0B4E59B13EE0@xxxxxxxxxxxxxxxx
I would like to restart domain computer once a day and like to deploy
script
via GPO. Would it be possible ? also at the time it restarts i would
like
to
call another vbscript that deletes some files in computer.
Can someone point out how to achieve this ?
With a GPO you can deploy logon, logoff, startup, and shutdown scripts.
The
shutdown script, for example, runs during shutdown. It does not initiate
shutdown. I don't see how a GPO script would meet your needs. Logon and
logoff scripts run with the credentials of the user, who probably does
not
have permission to restart or delete files.
A VBScript program using WMI can shutdown or restart a computer remotely.
For example:
http://www.microsoft.com/technet/scriptcenter/guide/sas_cpm_gmen.mspx
Perhaps you could restart the computers remotely. You could read computer
names from a text file. WMI can also be used in a VBScript program to
remotely delete files. For example:
http://www.microsoft.com/technet/scriptcenter/guide/sas_fil_vudw.mspx
You need a query for the specific files you want to delete. Browse more
of
"Microsoft Windows 2000 Scripting Guide" for more on using WMI queries to
delete files meeting your conditions:
http://www.microsoft.com/technet/scriptcenter/guide/sas_fil_ciaj.mspx
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
.
- References:
- VBscript that restart the domain comptuer
- From: madal
- Re: VBscript that restart the domain comptuer
- From: Richard Mueller [MVP]
- Re: VBscript that restart the domain comptuer
- From: madal
- VBscript that restart the domain comptuer
- Prev by Date: Re: need advice for repairing ad on win2k3
- Next by Date: Domain Controller "status"on new W2K8 server is "not available"
- Previous by thread: Re: VBscript that restart the domain comptuer
- Next by thread: Re: VBscript that restart the domain comptuer
- Index(es):
Relevant Pages
|