Friday, August 27, 2010

List Add/Remove Programs on Remote Computer

Quite a handy little script for listing programs showing as installed on a remote location without having to check the registry. Modify the computer name in the script. To output the file to a text file, run from dos with a >c:\output.txt command.

__________

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("COMPUTERNAMEHERE")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32Reg_AddRemovePrograms", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems
WScript.Echo "DisplayName: " & objItem.DisplayName
WScript.Echo "InstallDate: " & objItem.InstallDate
WScript.Echo "ProdID: " & objItem.ProdID
WScript.Echo "Publisher: " & objItem.Publisher
WScript.Echo "Version: " & objItem.Version
WScript.Echo
Next
Next

________

Thursday, August 26, 2010

Running a process on a remote machine SILENTLY

Below is the contents of a script to run a process on a remote workstation.

It will only run the program silently in the background. As you can't interact this is obviously only recommended to be run on processes which don't require any interaction.

The process will run as the user you run the VBS script as, on the workstation specified in the script.

________

strComputer = "remotecomputername"
strCommand = "notepad.exe"


Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")


errReturn = objProcess.Create(strCommand, null, null, intProcessID)

If errReturn = 0 Then
Wscript.Echo "notepad.exe was started with a process ID: " & intProcessID
Else
Wscript.Echo "notepad.exe could not be started due to error: " & errReturn
End If

__________

GP Templates for disabling removable devices

Below is a template for additional group policies for enabling/disabling removable devices and detailed in http://support.microsoft.com/kb/555324

Details of how to import the template into a Group Policy are in http://support.microsoft.com/kb/323639 under How to Load the Administrative Template.

You may need to select View and untick Show Policies Only for the options to appear under the custom template folder.

__________________

CLASS MACHINE
CATEGORY !!category
CATEGORY !!categoryname
POLICY !!policynameusb
KEYNAME "SYSTEM\CurrentControlSet\Services\USBSTOR"
EXPLAIN !!explaintextusb
PART !!labeltextusb DROPDOWNLIST REQUIRED

VALUENAME "Start"
ITEMLIST
NAME !!Disabled VALUE NUMERIC 3 DEFAULT
NAME !!Enabled VALUE NUMERIC 4
END ITEMLIST
END PART
END POLICY
POLICY !!policynamecd
KEYNAME "SYSTEM\CurrentControlSet\Services\Cdrom"
EXPLAIN !!explaintextcd
PART !!labeltextcd DROPDOWNLIST REQUIRED

VALUENAME "Start"
ITEMLIST
NAME !!Disabled VALUE NUMERIC 1 DEFAULT
NAME !!Enabled VALUE NUMERIC 4
END ITEMLIST
END PART
END POLICY
POLICY !!policynameflpy
KEYNAME "SYSTEM\CurrentControlSet\Services\Flpydisk"
EXPLAIN !!explaintextflpy
PART !!labeltextflpy DROPDOWNLIST REQUIRED

VALUENAME "Start"
ITEMLIST
NAME !!Disabled VALUE NUMERIC 3 DEFAULT
NAME !!Enabled VALUE NUMERIC 4
END ITEMLIST
END PART
END POLICY
POLICY !!policynamels120
KEYNAME "SYSTEM\CurrentControlSet\Services\Sfloppy"
EXPLAIN !!explaintextls120
PART !!labeltextls120 DROPDOWNLIST REQUIRED

VALUENAME "Start"
ITEMLIST
NAME !!Disabled VALUE NUMERIC 3 DEFAULT
NAME !!Enabled VALUE NUMERIC 4
END ITEMLIST
END PART
END POLICY
END CATEGORY
END CATEGORY

[strings]
category="Custom Policy Settings"
categoryname="Restrict Drives"
policynameusb="Disable USB"
policynamecd="Disable CD-ROM"
policynameflpy="Disable Floppy"
policynamels120="Disable High Capacity Floppy"
explaintextusb="Disables the computers USB ports by disabling the usbstor.sys driver"
explaintextcd="Disables the computers CD-ROM Drive by disabling the cdrom.sys driver"
explaintextflpy="Disables the computers Floppy Drive by disabling the flpydisk.sys driver"
explaintextls120="Disables the computers High Capacity Floppy Drive by disabling the sfloppy.sys driver"
labeltextusb="Disable USB Ports"
labeltextcd="Disable CD-ROM Drive"
labeltextflpy="Disable Floppy Drive"
labeltextls120="Disable High Capacity Floppy Drive"
Enabled="Enabled"
Disabled="Disabled"

_______