Harry,
No – that'll just run from a command line – doesn't need to be .vbs as its a simple batch command
It might be a little heavy handed - the net view command will list all the devices in your domain
On XP/Windows/w2k3 the command would work as follows:
For /f "tokens=1" %i in ('net view') do "sc %i config snmp start=disabled"
For is a pretty powerful command in batch scripts – it runs a specified command for an interative list
In this case – we're using the filenameset switch (/f) taking the first item in the list given by the command 'net view' and using that to DO an sc command –sc is a command line program used to modify service control manager
Really – the most straightforward way to do this is to use a GPO – in a GPO on the OU of your workstations simply configure the appropriate service to be disabled
If you must do it via .vbs then you could do something like:
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
' Get Domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")
objCommand.CommandText = _
"SELECT ADsPath FROM 'LDAP://" & strDomain & "' WHERE objectCategory='organizationalUnit'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Set objOU = GetObject(objRecordSet.Fields("ADsPath").Value)
Wscript.Echo objOU.distinguishedName
objOU.Filter = Array("Computer")
For Each objItem in objOU
Wscript.Echo " " & objItem.CN
call DisableService ("SNMP",objItem.CN)
Next
objRecordSet.MoveNext
Loop
Sub DisableService (cService,cMachineName)
Dim oContainer, oService
Set objWMIService = GetObject("winmgmts://" & cMachineName & "/root/cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name = '" & cService & "'")
For Each objService in colServiceList
wscript.echo "Disabling " & cService & " on " & cMachineName
errReturnCode = objService.Change( , , , , "Disabled")
Next
End Sub
From: thin-bounce@freelists.org [mailto:thin-bounce@freelists.org] On Behalf Of Harry Singh
Sent: 04 September 2008 16:55
To: thin@freelists.org
Subject: [THIN] Re: Disable a service remotely
Andrew,
i would simply copy your code into a file and change the extension to vbs ?
how would i deploy that script to the computers i'd like to run it against ?
On Thu, Sep 4, 2008 at 11:14 AM, Andrew Wood <andrew.wood@gilwood-cs.co.uk> wrote:
If you can't use a GPO then something like:-
For /f "tokens=1" %i in ('net view') do "sc %i config snmp start=disabled"
Should do the trick
From: thin-bounce@freelists.org [mailto:thin-bounce@freelists.org] On Behalf Of Minero, Hector B CIV NSWCDD, K55
Sent: 04 September 2008 15:51
To: thin@freelists.org
Subject: [THIN] Re: Disable a service remotely
Thanks,
can this be scripted? I need to disable SNMP on 200 clients.
_______________________________
Hector Minero
NSWCDD K55
-----Original Message-----
From: thin-bounce@freelists.org [mailto:thin-bounce@freelists.org] On Behalf Of Joe Shonk
Sent: Thursday, September 04, 2008 9:45 AM
To: thin@freelists.org
Subject: [THIN] Re: Disable a service remotelyPSExec.exe from Microsoft's sysinternals.
Joe
From: thin-bounce@freelists.org [mailto:thin-bounce@freelists.org] On Behalf Of Minero, Hector B CIV NSWCDD, K55
Sent: Thursday, September 04, 2008 5:28 AM
To: thin@freelists.org
Subject: [THIN] Disable a service remotely
Hi all, is there a way to disable a service remotely through a script?
_______________________________
Hector Minero
NSWCDD K55
No comments:
Post a Comment