>.
>
"faunalarch" <anon...@discussions.microsoft.com> wrote in message
news:080601c3ca34$89676270$a601...@phx.gbl...
Your actions should be something like this:
Set objUser = GetObject("WinNT://" & strName_
& "/Administrator, user")
objUser.SetPassword "testpassword"
objUser.SetInfo
Please note that you must run this as an account that had
Admin rights on all the computers you want to change.
HTH
Bjørn
PS! Please excuse the language mixup in the code :-)
------------------Start Code-----------------------------
'----------------------------------------------------------
----------
' ServiceStatus.vbs
' -----------------
' Get service status on all computers in an OU
'----------------------------------------------------------
----------
Dim strOutPut
Dim strLocation
Dim strServiceDisplay
Dim strPrev
Set objArgs = WScript.Arguments
if objArgs.count=0 Then
WScript.Echo "Debug -> No parameters"
Else
For I = 1 to objArgs.Count
GetVal objArgs(I-1), strParm, strValue
If Ucase(strParm) = "FORMAT" Then
strOutput = strValue
ElseIf UCase(strParm) = "OU" Then
strLocation = "LDAP://" &strValue
ElseIf UCase(strParm) = "SERVICE" Then
IF strServiceDisplay = "" Then
strServiceDisplay = "'" & strValue & "'"
Else
strServiceDisplay = strServiceDisplay & " Or
DisplayName = '" & strValue & "'"
End If
Else
WScript.Echo "Wrong arguments!"
WScript.Echo "Syntax: cscript ServList.vbs
[Service:<name>] ... [Format:<csv|display>] [OU:<LDAP-
Path>]"
End If
Next
End If
'
' Søkeparametre
'
If strOutput = "" then strOutput = "csv"
If strServiceDisplay = "" Then strServiceDisplay
= "Automatiske oppdateringer"
If strLocation = "" Then strLocation = "LDAP://ou=Some
OU,DC=TEST,DC=NET"
WScript.Echo "Output = " & strOutput
WScript.Echo "Display = " & strServiceDisplay
WScript.Echo "Location = " & strLocation
'
' CSV Header
'
If UCase( strOutput ) = "CSV" Then
Wscript.Echo "Computer, Comp_state," & strServiceDisplay
End IF
'
' ADSI konstanter
'
Const ADS_SCOPE_SUBTREE = 2
'----------------------------------------------------------
----------
' Henter en collection av alle computer objekter i OU
'----------------------------------------------------------
----------
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from '" & strLocation & "' " _
& "where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
'
' Loop all objects found in the OU (including subs)
'
Do Until objRecordSet.EOF
'
' Use ping to test if the computer is available
'
strName = Trim( objrecordSet.Fields("Name").Value)
Set objPing = GetObject("winmgmts:
{impersonationLevel=impersonate}")._
ExecQuery("select * from Win32_PingStatus where
address = '"_
& strName & "'")
For Each objStatus in objPing
'
' Ping OK?
'
strResult = ""
'If IsNull(objStatus.StatusCode) or
objStatus.StatusCode<>0 Then
If objStatus.StatusCode = 0 Then
strResult = "Online"
Else
'if strResult = "" Then strResult = "Offline"
strResult = "Offline"
End If
Next
'strResult = "Online"
If strResult = "Online" Then
'
' Connect to server and get service status
'
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\" & strName
& "\root\cimv2")
If Err.number = 0 Then
Set colRunningServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where DisplayName
= " & strServiceDisplay )
If colRunningServices.Count <= 0 Then
'
' Service er ikke definert på maskinen
'
strService = "Not installed"
Else
'
' Service installed, get status
'
For Each objService in colRunningServices
If UCase( strOutput ) = "CSV" Then
strService = objService.State
Else
strService = objService.DisplayName &"
installert: " & objService.State
End If
Next
End If
Set colRunningServices = Nothing
Set objWMIService = Nothing
Else
strService = "#NA [WMI Unavailable]"
Err.clear
End If
Set objPing = Nothing
On Error Goto 0
Else
'
' Computer unavailable
'
strService = ""
End If
If strOutput = "Display" Then
Wscript.Echo "Computer Name: " & strName & " status: "
& strResult & " " & strService
Else
Wscript.Echo strName & "," & strResult & "," &
strService
End If
objRecordSet.MoveNext
Loop
' --End Main
Sub GetVal( strIn, strP, strV )
If InStr( strIn, ":" ) Then
arrParm = split( strIn, ":" )
strP = arrParm(0)
strTemp = arrParm(1)
strV = ""
If InStr( strTemp, """") Then
For J = 1 to Len(strTemp )
If Mid(strTemp,J,1) <> """" Then strV = strV & Mid
(strTemp,J,1)
Next
Else
strV = strTemp
End If
strParm = strP
strValue = strV
Else
strParm = "Error"
End If
End Sub
---------------------------------End Code-----------------
>.
>
If you have all of the correct names and passwords for the computers,
whether you run the script against a system with the right Admin Account and
Password wouldn't really matter.
Simply write in a little error correction so your script does not fail when
it can't connect to a system and edit the script per different Account Name
and password, Or even better if you want to get it all done in one fail
swoop just write a loop that cycles through the different Admin Accounts and
Passwords.
Gavin D. Garley
"Tom" <sprdt...@hotmail.com> wrote in message
news:eY%23Ikw50...@TK2MSFTNGP12.phx.gbl...
> My problem is that the machines I am trying to connect to use a different
> administrator username and password than the server I am calling them from.
> How do i supply the username and password needed to allow the connection to
> the remote machines?
Hi
IADsOpenDSObject::OpenDSObject
http://msdn.microsoft.com/library/en-us/adsi/adsi/iadsopendsobject_opendsobject.asp
(note that the constant ADS_SECURE_AUTHENTICATION mentioned in the link above
needs to be explicit defined to 1 in a VBScript)
An example on how to use OpenDSObject:
Modifying User Cannot Change Password (WinNT Provider)
http://msdn.microsoft.com/library/en-us/adsi/adsi/modifying_user_cannot_change_password_winnt_provider.asp
--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter
> Have a look at the source below. This script enumerates
> all computer objects in a specific OU (including sub OUs)
> and gets the state of a named service. It should be fairly
> easy to modify the actions for your needs. It also
> includes a lot of stuff that you don't need. I haven't got
> the time to shorten it just now :-)
>
> Your actions should be something like this:
>
> Set objUser = GetObject("WinNT://" & strName_
> & "/Administrator, user")
Note that the script may fail when using a space between the two parameters in
the GetObject call above, it is safer to do like this:
& "/Administrator,user")
> objUser.SetPassword "testpassword"
> objUser.SetInfo
>
> Please note that you must run this as an account that had
> Admin rights on all the computers you want to change.
--
"Gavin Garley" <ggar...@hotmail.com> wrote in message
news:O7SxT350...@TK2MSFTNGP12.phx.gbl...
I have a few more questions and then I'll tap around and see what I
can come up with.
How many Admin Accounts/Passwords vs. systems are you dealing with?
If they all are part of a domain, and the only issue you are dealing with is
that the accounts are different... I'd have to play around with that
scenario a bit but I would not think it that difficult to have a list or an
array of account names you could cycle through.
Theoretically assuming these systems were part of a domain and you had
Domain admin rights then something like this might work:
AccountName = XXXXXX
Set objUser = GetObject("WinNT://" & strName_
& "/"& AccountName &",user")
As the logic would break down, if the password change failed, the value for
AccountName would change and try to connect again and change it and so on
and so forth.
I'll have to rename an admin account and see if that would work. Give me a
bit more information on the scope of accounts and passwords and I'll test
this out as time permits.
Thanks,
Gavin D. Garley
"Tom" <sprdt...@hotmail.com> wrote in message
news:uZALwPI1...@TK2MSFTNGP12.phx.gbl...