Showing posts with label vbs. Show all posts
Showing posts with label vbs. Show all posts

Tuesday, January 4, 2011

SCCM Package replication status gadget for Windows 7 Sidebar

Making sure your packages are replicating correctly in your SMS hierarchy is important.
Sometimes, you even want to know as soon as possible when a package has been replicated!
This has been useful when a new office is being build far away, and I want to inform the fields technicians on site when they'll be allowed to push out software.

Therefore, I present the "PackageStatusDetailSummarizer" gadget for Windows 7 Sidebar!

>>DOWNLOAD<<


It's like  the "Package Status" view in the "Configuration Manager Console", just neater in a gadget :-)



Inspiration from

To install in Windows 7:
  1. drop the folder "PackageStatusDetailSummarizer.Gadget" in %userprofile%\appdata\Local\Microsoft\Windows Sidebar
  2. right click on your desktop, choose "Gadgets", you should see it in the list
  3. right click, "install"
  4. configure by setting the options, just like a normal gadget
  5. Be careful with the refresh interval in the options, if you set it to low you can hurt your site's performance.

If you want to customize it,just close the gadget and edit the files in the folder you have copied (see the "Windows Sidebar" link)
The possibilites are endless : check the deployment of packages,advertisements, software updates, site health etc..

Tuesday, September 14, 2010

SCCM : converting programs to Windows 7

This is a VBS program I wrote for a customer, who has a SCCM 2007 R2 environment.

They had over 400 programs in various packages, and they weren't sure if all of them would run under Windows 7.

Visually, we had to make sure this box was ticked.

After a little digging in the SCCM SDK (link), and a script from Stuart James, the following will go through ALL programs in ALL packages. If a program is not set to "Run on all platforms", we add that it can run on "All x86 Windows 7"

It outputs changes with comma separated values (csv) so you can send this to a file and dress it up nice in Excel for your boss :-)

'===================================== 
'SetRunFromTS - Sets all programs to be able to run in Windows 7 x86
'Author: Patrick Paumier / Stuart James 
' 
'Requirements: Change line 22 to connect to your site server
' 
'Usage: CScript xxx.vbs or double click 
'===================================== 


'Check we're using CScript and if not then relaunch 
If "CSCRIPT.EXE" <> UCase(Right(WScript.Fullname, 11)) Then 
Set WshShell = WScript.CreateObject("WScript.Shell") 
WshShell.Run "CSCRIPT.EXE /nologo " & WScript.ScriptFullName 
Wscript.Quit 
End If 

' Setup a connection to the local provider. 
Set swbemLocator = CreateObject("WbemScripting.SWbemLocator") 
Set swbemServices= swbemLocator.ConnectServer("MY-SCCM-SERVER", "root\sms") 
Set providerLoc = swbemServices.InstancesOf("SMS_ProviderLocation") 

For Each Location In providerLoc 
If location.ProviderForLocalSite = True Then 
Set swbemServices = swbemLocator.ConnectServer(Location.Machine, "root\sms\site_" + Location.SiteCode) 
Exit For 
End If 
Next 

'Main call 
QueryPrograms swbemServices 

Sub QueryPrograms(connection) 

On Error Resume next 

Dim programs 
'Dim program 
' Run the query. 
Set programs = connection.ExecQuery("Select * From SMS_Program WHERE PackageID='TDE0024F'") 

If Err.Number<>0 Then 
Wscript.Echo "Couldn't get programs" 
Wscript.Quit 
End If 
For Each program In programs 
ModifyProgram connection,program.PackageID, program.ProgramName 
Next 
If programs.Count=0 Then 
Wscript.Echo "No packages found" 
End If 

End Sub 

Sub ModifyProgram (connection, existingPackageID, existingProgramName) 

' Build a query to get the specified package. 
packageQuery = "SMS_Package.PackageID='" & existingPackageID & "'" 

' Run the query to get the package. 
Set package = connection.Get(packageQuery) 
' Output package name and ID. 
wscript.echo VBCrLf 'New Line
Wscript.StdOut.Write package.PackageID & "," 'Package ID
Wscript.StdOut.Write package.Name & "," 'Package Name
' Build a query to get the programs for the package. 
programQuery = "SELECT * FROM SMS_Program WHERE PackageID='" & existingPackageID & "'" 
' Run the query to get the programs. 
Set allProgramsForPackage = connection.ExecQuery(programQuery, , wbemFlagForwardOnly Or wbemFlagReturnImmediately) 
'The query returns a collection of program objects that needs to be enumerated. 
For Each program In allProgramsForPackage                
If program.ProgramName = existingProgramName Then 
'Get all program object properties (in this case we specifically need some lazy properties).
programPath = program.Put_
Set program = connection.Get(programPath) 

' Output the program name 
Wscript.StdOut.Write program.ProgramName & "," ' Program Name
Wscript.StdOut.Write program.ProgramFlags & "," 'Program Flags

If program.ProgramFlags AND 2^27 Then
Wscript.StdOut.Write "OK for all platforms"
Else
' RUN_ON_SPECIFIED_PLATFORMS is set.
Win7OK = FALSE
For Each myOS in program.SupportedOperatingSystems
osver = Left(myOS.MinVersion,3)
If osver="6.1" And myOS.Platform="I386" Then
Wscript.StdOut.Write "OK for Windows 7" ' Name: " & myOS.Name & " MinVersion: "& myOS.MinVersion & " MaxVersion: " & myOS.MaxVersion & " Platform: " & myOS.Platform
Win7OK = TRUE
Exit For
End If
Next
If Win7OK = FALSE Then
'Add Windows 7 32bit platform
' Create 
Set tempSupportedPlatform = connection.Get("SMS_OS_Details").SpawnInstance_
' Populate tempSupportedPlatform values.    
tempSupportedPlatform.MaxVersion = "6.10.9999.9999"
tempSupportedPlatform.MinVersion = "6.10.0000.0"
tempSupportedPlatform.Name       = "Win NT"
tempSupportedPlatform.Platform   = "I386"

' Get the array of supported operating systems.
tempSupportedPlatformsArray = program.SupportedOperatingSystems   

' Add the new supported platform values (object) to the temporary array.
ReDim Preserve tempSupportedPlatformsArray (Ubound(tempSupportedPlatformsArray) + 1)
Set tempSupportedPlatformsArray(Ubound(tempSupportedPlatformsArray)) = tempSupportedPlatform

' Replace the SupportedOperatingSystems object array with the new updated array.
program.SupportedOperatingSystems = tempSupportedPlatformsArray

' Save the program.
program.Put_

' Output success message.

Wscript.StdOut.Write "Added Win7"
End If
End If
End If        
Next 
End Sub 

Wednesday, January 27, 2010

As part of a job interview, I was asked to program a VB script.

The goal was to:
"Disable LAN,WAN,Bluetooth devices as soon as any user (except shopAdmin) makes a login to the Computer (VB).
Hint this is only possible with the extra software piece called Devcon"


How do I start?
  1. search on the internet to see if someone else did it. If I judge it's well done, why reinvent what has already been invented?
  2. search in my scripts if I've already done it or part of it. Most likely, I will reuse generic scripts I made.

In this case, the "hint" meant that since a command line program would be used, some string parsing would be involved. A few Google searches turned up some ideas but nothing as complete as what was requested.

'Assuming devcon is the WINDOWS folder
'Assuming the logged on user has the right to disable devices.

LANadapter = "Broadcom Loca Network Adapter"
BTadapter = "BT adapter"
WLANadapter = "Dell Wireless 1470 Dual Band WLAN Mini-PCI Card"

Set objShell = WScript.CreateObject("WScript.Shell")

Set objNet = CreateObject("WScript.NetWork")

If Not objNet.UserName = "shopAdmin" Then
Set objExecObject = objShell.Exec("cmd /c devcon listclass Net")

Do While Not objExecObject.StdOut.AtEndOfStream

strText = objExecObject.StdOut.ReadLine()

If Instr(strText,LANadapter)>0 Then
ID = Split(strText,"\",3)
Set objExecObject = objShell.Exec("cmd /c devcon.exe disable " & ID(0) & "\" & ID(1) )
WScript.Echo "LAN disabled"

ElseIf Instr(strText,BTadapter )>0 Then
ID = Split(strText,"\",3)
Set objExecObject = objShell.Exec("cmd /c devcon.exe disable " & ID(0) & "\" & ID(1) )
WScript.Echo "Bluetooth disabled"

ElseIf Instr(strText,WLANadapter)>0 Then
ID = Split(strText,"\",3)
Set objExecObject = objShell.Exec("cmd /c devcon.exe disable " & ID(0) & "\" & ID(1) )
WScript.Echo "WLAN disabled"
End If

Loop
End If