Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


what is wrong with this script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,34641
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> what is wrong with this script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 what is wrong with this script - 5/17/2006 6:45:35 PM   
  avipenina

 

Posts: 102
Score: 0
Joined: 4/24/2006
Status: offline
Hi,

why i can't reboot group of machines with this script

arrComputers = Array("1","2")
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
       arrComputers & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
   ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
   objOperatingSystem.Reboot()
Next

i get an error message
 
 
Post #: 1
 
 RE: what is wrong with this script - 5/17/2006 7:57:38 PM   
  ginolard


Posts: 1068
Score: 21
Joined: 8/10/2005
Status: offline
Because you're not iterating through the array.

arrComputers = Array("1","2")

For i = 0 to Ubound(arrComputers)

   Set objWMIService = GetObject("winmgmts:" _
       & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
           arrComputers(i) & "\root\cimv2")
   Set colOperatingSystems = objWMIService.ExecQuery _
      ("Select * from Win32_OperatingSystem")
   For Each objOperatingSystem in colOperatingSystems
       objOperatingSystem.Reboot()
   Next
Next

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to avipenina)
 
 
Post #: 2
 
 RE: what is wrong with this script - 5/17/2006 8:09:43 PM   
  avipenina

 

Posts: 102
Score: 0
Joined: 4/24/2006
Status: offline
ok i see,now in this script how do i put that the script will connect to remote machine with username and password?

(in reply to ginolard)
 
 
Post #: 3
 
 RE: what is wrong with this script - 5/17/2006 11:44:50 PM   
  ginolard


Posts: 1068
Score: 21
Joined: 8/10/2005
Status: offline
Do you mean that you want to connect (say, via Remote Desktop) with alternative credentials or you want the WMI connection to be made with alternate credentials?

Or something else?

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to avipenina)
 
 
Post #: 4
 
 RE: what is wrong with this script - 5/18/2006 12:30:43 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
Try this script from Mark
'==========================================================================
'
' NAME: RebootWSfromList.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: http://www.thespidersparlor.com
' DATE  : 7/6/2004
'
' COMMENT: <comment>
'
'==========================================================================

On Error Resume Next

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream = oFSO.OpenTextFile("wslist.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
For Each strComputer In RemotePC
   Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//" & strComputer).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
       for each OpSys in OpSysSet
           OpSys.Reboot()
        next
Next

Hope this helps

(in reply to avipenina)
 
 
Post #: 5
 
 RE: what is wrong with this script - 5/18/2006 1:43:05 AM   
  avipenina

 

Posts: 102
Score: 0
Joined: 4/24/2006
Status: offline
quote:

ORIGINAL: gdewrance

Try this script from Mark
'==========================================================================
'
' NAME: RebootWSfromList.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: http://www.thespidersparlor.com
' DATE  : 7/6/2004
'
' COMMENT: <comment>
'
'==========================================================================

On Error Resume Next

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream = oFSO.OpenTextFile("wslist.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
For Each strComputer In RemotePC
  Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//" & strComputer).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
      for each OpSys in OpSysSet
          OpSys.Reboot()
       next
Next

Hope this helps


this answer is good but i want to put alternative credentials to connect to another remote machine, how i do it with your script or the script that there is up there

(in reply to gdewrance)
 
 
Post #: 6
 
 RE: what is wrong with this script - 5/18/2006 7:27:44 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
just google vbscript runas
I think thats what you after

(in reply to avipenina)
 
 
Post #: 7
 
 RE: what is wrong with this script - 5/18/2006 7:35:38 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
if you need to reboot them every week , use devcon and set it as a scheduled task
I use it for my servers to restart on weekends when no ones around

if xp try start run shutdown -i
hope this helps

(in reply to avipenina)
 
 
Post #: 8
 
 RE: what is wrong with this script - 5/18/2006 7:50:29 PM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
you will need to do somthing like thie

Dim co As New ConnectionOptions

co.Impersonation = ImpersonationLevel.Impersonate
co.EnablePrivileges = True
co.Username = "domain\username" 'domain admin
co.Password = "Password"

(in reply to avipenina)
 
 
Post #: 9
 
 RE: what is wrong with this script - 5/18/2006 11:17:03 PM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
Also, you can take a look at psShutdown from sysinternals.  This allows you to supply a username and password to shutdown a remote PC.

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to gdewrance)
 
 
Post #: 10
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> what is wrong with this script Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts