A
Adrian Marsh (NNTP)
All,
I'm having some problem with this computer script. Its various
Microsoft example script cobbled together.:
Runs as a Computer Script. idea is that if the computer is in the
/Computers container, then it gets moved to a sub-ou.
This works fine if the PC is actually in the /Computers CN, but if its
not (i.e. any subsequent boot), then it causes an error on boot.
Annoyingly, all subsequent programs fail to run properly after the
error, and in one case it caused problems with the IE6 installer, which
in turn corrupted an IE6 installation, and explorer always crashed... A
great Trojun!!
I can't define these "problems" any further, as each one behaves
differently. The only thing I can confirm, is that if I remove the below
script and manually move the object, all the other scripts work fine.
So where have I gone wrong???
P.S. I'm a crap .vbs programmer - just started to learn, so theres
probably some basic mistakes in here...
adrian.
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
On Error Resume Next
Set currentAccount = GetObject("LDAP://CN=" & strComputer &
",CN=Computers,DC=uk-lab,DC=lucent,DC=com")
'Wscript.Echo "Current: " & Err.Number
'If not currentAccount is Nothing Then
if Err.Number=0 Then
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
Wscript.Echo objOperatingSystem.Caption & " " & _
objOperatingSystem.Version
os=objOperatingSystem.Caption
Next
if InStr(1, os, "XP")>0 Then
labou="XP Workstations"
else
labou="2000 Workstations"
End if
Wscript.Echo "Moving Computer Account to Desktops A under " & labou
Set objNewOU = GetObject("LDAP://OU=Desktops A,OU=" & labou &
",DC=uk-lab,DC=lucent,DC=com")
Set objMoveComputer = objNewOU.MoveHere ("LDAP://CN=" & strComputer &
",CN=Computers,DC=uk-lab,DC=lucent,DC=com","CN=" & strComputer)
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer &
"\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from
Win32_OperatingSystem")
Wscript.Sleep 10000
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()
Next
Else
Wscript.Echo "*********** Computer doesn't exist in Computers DN - OK"
Err.Clear
On Error GoTo 0 'turn errors back on
End If
I'm having some problem with this computer script. Its various
Microsoft example script cobbled together.:
Runs as a Computer Script. idea is that if the computer is in the
/Computers container, then it gets moved to a sub-ou.
This works fine if the PC is actually in the /Computers CN, but if its
not (i.e. any subsequent boot), then it causes an error on boot.
Annoyingly, all subsequent programs fail to run properly after the
error, and in one case it caused problems with the IE6 installer, which
in turn corrupted an IE6 installation, and explorer always crashed... A
great Trojun!!
I can't define these "problems" any further, as each one behaves
differently. The only thing I can confirm, is that if I remove the below
script and manually move the object, all the other scripts work fine.
So where have I gone wrong???
P.S. I'm a crap .vbs programmer - just started to learn, so theres
probably some basic mistakes in here...
adrian.
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
On Error Resume Next
Set currentAccount = GetObject("LDAP://CN=" & strComputer &
",CN=Computers,DC=uk-lab,DC=lucent,DC=com")
'Wscript.Echo "Current: " & Err.Number
'If not currentAccount is Nothing Then
if Err.Number=0 Then
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
Wscript.Echo objOperatingSystem.Caption & " " & _
objOperatingSystem.Version
os=objOperatingSystem.Caption
Next
if InStr(1, os, "XP")>0 Then
labou="XP Workstations"
else
labou="2000 Workstations"
End if
Wscript.Echo "Moving Computer Account to Desktops A under " & labou
Set objNewOU = GetObject("LDAP://OU=Desktops A,OU=" & labou &
",DC=uk-lab,DC=lucent,DC=com")
Set objMoveComputer = objNewOU.MoveHere ("LDAP://CN=" & strComputer &
",CN=Computers,DC=uk-lab,DC=lucent,DC=com","CN=" & strComputer)
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer &
"\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from
Win32_OperatingSystem")
Wscript.Sleep 10000
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()
Next
Else
Wscript.Echo "*********** Computer doesn't exist in Computers DN - OK"
Err.Clear
On Error GoTo 0 'turn errors back on
End If