Re: VBscript that restart the domain comptuer



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





.



Relevant Pages

  • Re: logoff/shutdown script
    ... someone tries to log off or shutdown a computer. ... I know where to save the script ... the computers. ... Use Group Policy to run the script. ...
    (microsoft.public.scripting.vbscript)
  • Re: logoff/shutdown script
    ... someone tries to log off or shutdown a computer. ... I know where to save the script ... the computers. ... If you are using Windows Vista it will run with no problems, ...
    (microsoft.public.scripting.vbscript)
  • Re: logoff/shutdown script
    ... Are you obliged to use VBScript ?If not i can found solution ... someone tries to log off or shutdown a computer. ... I know where to save the script ... the computers. ...
    (microsoft.public.scripting.vbscript)
  • Re: Detect logoff or shutdown
    ... computer is shutting down or restarting from a VBScript running as a ... can FBSL tell whether or not the shutdown is a power off ... shutdown using the shutdown GPO script method. ... they select 'Restart', I could write a startup script to restart the ...
    (microsoft.public.scripting.vbscript)
  • Re: Restart option only
    ... That just makes restart the default but the user here can select shutdown and ... "Jerold Schulman" wrote: ... I have instructed my users to restart their computers at the end ...
    (microsoft.public.win2000.group_policy)