SMS/SCCM, Beyond Application Deployment is a blog by Matthew Hudson covering SMS 2003, SCCM 2007, 2012 and beyond package deployment. Here you will find hints, tips, and tricks to help with managing your infrastructure. It will focus mainly on Reg files, Batch, VbScript, WMI, and possibly other methods.
Showing posts with label vbscript. Show all posts
Showing posts with label vbscript. Show all posts
Tuesday, April 7, 2015
Manual force of WSUS via automation
Have you ever wanted to have an odd Schedule or found that your site will not longer sync on the schedule but a full sync will work.
Well here is some code to kick off a Full sync on your site. All you have to do is create a scheduled task on the Central or primary site.
The code modifies the control file. Because of some timing issues I did add a few seconds on to the request.
XXX - SITE CODE
SERVER - SERVERNAME
*******************************************
Set swbemLocator = CreateObject("WbemScripting.SWbemLocator")
swbemLocator.Security_.AuthenticationLevel = 6 'Packet Privacy
Set swbemServices= swbemLocator.ConnectServer("SERVER", "root\sms\site_XXX")
Set context = CreateObject("WbemScripting.SWbemNamedValueSet")
'context.Add "LocaleID", "MS\1033"
'context.Add "MachineName", "SERVER"
Context.Add "SessionHandle", swbemServices.ExecMethod("SMS_SiteControlFile", "GetSessionHandle").SessionHandle
SynchronizeSoftwareUpdatePoint swbemServices,context,"XXX"
Sub SynchronizeSoftwareUpdatePoint(swbemServices,swbemContext,siteCode)
' Load site control file and get the SMS_WSUS_SYNC_MANAGER component section.
swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext
' Calculate the current timestamp (number of seconds from 1/1/1970 to current time UTC).
calculatedUTCOffsetinSeconds = (8 * 60 * 60)
currentTimestamp = datediff("s", "1/1/1970 12:00:00 AM", now()) + calculatedUTCOffsetinSeconds
currentTimestamp=currentTimestamp-7198
Query = "SELECT * FROM SMS_SCI_Component " & _
"WHERE ComponentName = 'SMS_WSUS_SYNC_MANAGER' " & _
"AND SiteCode = '" & siteCode & "'"
Set SCIComponentSet = swbemServices.ExecQuery(Query, ,wbemFlagForwardOnly Or wbemFlagReturnImmediately, swbemContext)
' Only one instance is returned from the query.
For Each SCIComponent In SCIComponentSet
' Loop through the array of embedded SMS_EmbeddedProperty instances.
For Each vProperty In SCIComponent.Props
' Setting: Sync Now
If vProperty.PropertyName = "Sync Now" Then
' Modify the value.
vProperty.Value = currentTimestamp
' wscript.echo "New value " & currentTimestamp
' Output success message.
' wscript.echo " "
' wscript.echo "Reset 'Sync Now' property with current timestamp. "
End If
Next
' Update the component in your copy of the site control file. Get the path
' to the updated object, which could be used later to retrieve the instance.
Set SCICompPath = SCIComponent.Put_(wbemChangeFlagUpdateOnly, swbemContext)
Next
' Commit the change to the actual site control file.
Set InParams = swbemServices.Get("SMS_SiteControlFile").Methods_("CommitSCF").InParameters.SpawnInstance_
InParams.SiteCode = siteCode
swbemServices.ExecMethod "SMS_SiteControlFile", "CommitSCF", InParams, , swbemContext
' Release copy of the site control file.
swbemServices.Get("SMS_SiteControlFile").ReleaseSessionHandle swbemContext.Item("SessionHandle").Value
End Sub
*******************************************
I know this works on SCCM 2007, I am sure it will work on SCCM 2012 but I never tried it:
Tuesday, November 2, 2010
I was getting tired of some of the problems with the Java core.zip install failure so I came up with this script. It isn't pretty but it does work to install or fix a machine that currently messed up. Test it, use at your own risk
------------------------
--------------------
------------------------
'On Error Resume Next
Dim WshShell, strKeyPath
dim filesys, demofolder
set WshShell = WScript.CreateObject("WScript.Shell")
set filesys = CreateObject ("Scripting.FileSystemObject")
Installed=0 ' I haven't installed Java correctly yet
'determine if this is a 64bit machine
Set Wmi = GetObject("winmgmts:\\.\root\CIMV2")
Set Col = Wmi.ExecQuery("SELECT * FROM Win32_Processor")
For Each Obj in Col
MachineType= Obj.AddressWidth
next
'''Install Java Loop
Do Until Installed=1
'Install Java
WshShell.run("msiexec /i jre1.6.0_22.msi /qb IEXPLORER=1 MOZILLA=1 REBOOT=Suppress JAVAUPDATE=0"), 0, True
'check to see if it installed correctly
if filesys.FileExists("c:\Program Files\Java\jre6\Core.zip") then
FixJava(MachineType)
elseif filesys.FileExists("c:\Program Files (x86)\Java\jre6\core.zip") then
FixJava(MachineType)
else
Installed=1
end if
Loop
Sub FixJava(MachineType)
if MachineType=32 then
'''''''''x86 runtime
''delete the registry entries FOR X86
strKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F83216022FF}\"
WshShell.RegDelete strKeyPath
strKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Web Start\1.6.0_22\"
WshShell.RegDelete strKeyPath
strKeyPath = "HKEY_CLASSES_ROOT\Installer\Products\4EA42A62D9304AC4784BF238120622FF\SourceList\Net\"
WshShell.RegDelete strKeyPath
strKeyPath = "HKEY_CLASSES_ROOT\Installer\Products\4EA42A62D9304AC4784BF238120622FF\sourceList\Media\"
WshShell.RegDelete strKeyPath
strKeyPath = "HKEY_CLASSES_ROOT\Installer\Products\4EA42A62D9304AC4784BF238120622FF\SourceList\"
WshShell.RegDelete strKeyPath
strKeyPath = "HKEY_CLASSES_ROOT\Installer\Products\4EA42A62D9304AC4784BF238120622FF\"
WshShell.RegDelete strKeyPath
set demofolder = filesys.GetFolder("Program Files\Java\")
demofolder.Delete
end if
if MachineType=64 then
'''''''''''''''x64 runtime
strKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{26A24AE4-039D-4CA4-87B4-2F83216022FF}\"
WshShell.RegDelete strKeyPath
strKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Web Start\1.6.0_22\"
WshShell.RegDelete strKeyPath
strKeyPath = "HKEY_CLASSES_ROOT\Installer\Products\4EA42A62D9304AC4784BF238120622FF\SourceList\Net\"
WshShell.RegDelete strKeyPath
strKeyPath = "HKEY_CLASSES_ROOT\Installer\Products\4EA42A62D9304AC4784BF238120622FF\sourceList\Media\"
WshShell.RegDelete strKeyPath
strKeyPath = "HKEY_CLASSES_ROOT\Installer\Products\4EA42A62D9304AC4784BF238120622FF\SourceList\"
WshShell.RegDelete strKeyPath
strKeyPath = "HKEY_CLASSES_ROOT\Installer\Products\4EA42A62D9304AC4784BF238120622FF\"
WshShell.RegDelete strKeyPath
set demofolder = filesys.GetFolder("c:\program files (x86)\java")
demofolder.Delete
End if
End Sub
--------------------
Tuesday, July 6, 2010
Adobe Updates on x64
I will go back and modify my script on this blog and my http://www.sccm-tools.com/ website later today but I wanted to post because people have asked me about my script and x64 machines.
I have several posts http://sms-hints-tricks.blogspot.com/2009/05/deploy-adobe-acrobat-updates.html on how to deploy the adobe updates in a single VBscript file that makes life easy. Again this for those that don't have an Administrative install point or some other method for patching Adobe.
So you need to check the registry to determine what version of Adobe Reader/Pro is install so you know which patch to install. The problem is the 64bit machines will store this in the Wow64 section since it isn't a 64bit app. Here is the trick for your machine.
By looking in WMI we can determine if the machine is a 32bit machine or 64bit machine. This data is in several places in WMI. Here is just one example.
Adobe 9 Professional
---------------------------------------
Dim objShell, RegLocate
Set objShell = WScript.CreateObject("WScript.Shell")
On error resume next
'determine if this is a 64bit machine
Set Wmi = GetObject("winmgmts:\\.\root\CIMV2")
Set Col = Wmi.ExecQuery("SELECT * FROM Win32_Processor")
For Each Obj in Col
MachineType= Obj.AddressWidth
next
if MachineType=32 then
Dim sngVersion
'''' Adobe 9.0.0
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.0.0" then
objShell.run "msiexec /p AcroPro-std9.1.msp /qb /norestart", 0, True
end if
'''' Adobe 9.1.0
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.0" then
objShell.run "msiexec /p Adobe_9.1.2_pro.msp /qb /norestart", 0, True
end if
'''' Adobe 9.1.1
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.1" then
objShell.run "msiexec /p Adobe_9.1.2_pro.msp /qb /norestart", 0, True
end if
'''' Adobe 9.1.3
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.2" then
objShell.run "msiexec /p AcrobatUpd913_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.3" then
objShell.run "msiexec /p AcrobatUpd920_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.2.0" then
objShell.run "msiexec /p AcrobatUpd930_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.3.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.3.0" then
objShell.run "msiexec /p AcrobatUpd932_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.3.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.3.1" then
objShell.run "msiexec /p AcrobatUpd932_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.3.3
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.3.2" then
objShell.run "msiexec /p AcrobatUpd933_all_incr.msp /qb /norestart", 0, True
end if
else ' MachineType=64
'''' Adobe 9.0.0
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.0.0" then
objShell.run "msiexec /p AcroPro-std9.1.msp /qb /norestart", 0, True
end if
'''' Adobe 9.1.0
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.0" then
objShell.run "msiexec /p Adobe_9.1.2_pro.msp /qb /norestart", 0, True
end if
'''' Adobe 9.1.1
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.1" then
objShell.run "msiexec /p Adobe_9.1.2_pro.msp /qb /norestart", 0, True
end if
'''' Adobe 9.1.3
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.2" then
objShell.run "msiexec /p AcrobatUpd913_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.3" then
objShell.run "msiexec /p AcrobatUpd920_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.2.0" then
objShell.run "msiexec /p AcrobatUpd930_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.3.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.3.0" then
objShell.run "msiexec /p AcrobatUpd932_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.3.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.3.1" then
objShell.run "msiexec /p AcrobatUpd932_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.3.3
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.3.2" then
objShell.run "msiexec /p AcrobatUpd933_all_incr.msp /qb /norestart", 0, True
end if
end if
WScript.Quit
------------------------------------------
The nice trick about this is you don't need to create a seperate program or package for the 64bit machines. You simply modify the vbscript/batch/cmd file you use to deploy your application. I admit there are good reasons for seperating this. We have some advertisments that have a program for 64bit and some for 32 but in this instance it is easy to send it all machines and allow the program to determine the best course.
I have several posts http://sms-hints-tricks.blogspot.com/2009/05/deploy-adobe-acrobat-updates.html on how to deploy the adobe updates in a single VBscript file that makes life easy. Again this for those that don't have an Administrative install point or some other method for patching Adobe.
So you need to check the registry to determine what version of Adobe Reader/Pro is install so you know which patch to install. The problem is the 64bit machines will store this in the Wow64 section since it isn't a 64bit app. Here is the trick for your machine.
By looking in WMI we can determine if the machine is a 32bit machine or 64bit machine. This data is in several places in WMI. Here is just one example.
Adobe 9 Professional
---------------------------------------
Dim objShell, RegLocate
Set objShell = WScript.CreateObject("WScript.Shell")
On error resume next
'determine if this is a 64bit machine
Set Wmi = GetObject("winmgmts:\\.\root\CIMV2")
Set Col = Wmi.ExecQuery("SELECT * FROM Win32_Processor")
For Each Obj in Col
MachineType= Obj.AddressWidth
next
if MachineType=32 then
Dim sngVersion
'''' Adobe 9.0.0
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.0.0" then
objShell.run "msiexec /p AcroPro-std9.1.msp /qb /norestart", 0, True
end if
'''' Adobe 9.1.0
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.0" then
objShell.run "msiexec /p Adobe_9.1.2_pro.msp /qb /norestart", 0, True
end if
'''' Adobe 9.1.1
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.1" then
objShell.run "msiexec /p Adobe_9.1.2_pro.msp /qb /norestart", 0, True
end if
'''' Adobe 9.1.3
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.2" then
objShell.run "msiexec /p AcrobatUpd913_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.3" then
objShell.run "msiexec /p AcrobatUpd920_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.2.0" then
objShell.run "msiexec /p AcrobatUpd930_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.3.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.3.0" then
objShell.run "msiexec /p AcrobatUpd932_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.3.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.3.1" then
objShell.run "msiexec /p AcrobatUpd932_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.3.3
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.3.2" then
objShell.run "msiexec /p AcrobatUpd933_all_incr.msp /qb /norestart", 0, True
end if
else ' MachineType=64
'''' Adobe 9.0.0
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.0.0" then
objShell.run "msiexec /p AcroPro-std9.1.msp /qb /norestart", 0, True
end if
'''' Adobe 9.1.0
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.0" then
objShell.run "msiexec /p Adobe_9.1.2_pro.msp /qb /norestart", 0, True
end if
'''' Adobe 9.1.1
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.1" then
objShell.run "msiexec /p Adobe_9.1.2_pro.msp /qb /norestart", 0, True
end if
'''' Adobe 9.1.3
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.2" then
objShell.run "msiexec /p AcrobatUpd913_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.1.3" then
objShell.run "msiexec /p AcrobatUpd920_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.2.0" then
objShell.run "msiexec /p AcrobatUpd930_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.3.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.3.0" then
objShell.run "msiexec /p AcrobatUpd932_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.3.2
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.3.1" then
objShell.run "msiexec /p AcrobatUpd932_all_incr.msp /qb /norestart", 0, True
end if
'''' Adobe 9.3.3
sngVersion = objShell.RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-0000-7760-000000000004}\DisplayVersion")
if sngVersion="9.3.2" then
objShell.run "msiexec /p AcrobatUpd933_all_incr.msp /qb /norestart", 0, True
end if
end if
WScript.Quit
------------------------------------------
The nice trick about this is you don't need to create a seperate program or package for the 64bit machines. You simply modify the vbscript/batch/cmd file you use to deploy your application. I admit there are good reasons for seperating this. We have some advertisments that have a program for 64bit and some for 32 but in this instance it is easy to send it all machines and allow the program to determine the best course.
Friday, October 9, 2009
Change cache location
Sometimes you have a cache folder needs to move because of space issues
To do this at install time you need to use the SMSCACHEDIR attribute:
CCMSetup.exe SMSCACHEDIR="D:\sccm\cache"
Will force the client to install the cache folder to the D drive in a new folder
Maybe the client is already installed but you want to change the folder. Here is a VbScript that you can push down to the client. This takes a fraction of a second to run on the client so they are not affected by the change. Be aware that Cache cannot have any advertisment that is active. If so then you can't move the cache.
--------------------------
Dim oUIResourceMgr
Dim oCache
Set oUIResourceMgr = CreateObject("UIResource.UIResourceMgr")
Set oCacheInfo = oUIResourceMgr.GetCacheInfo
oCacheInfo.Location = "D:SCCM\Cache"
-------------------------------------
To do this at install time you need to use the SMSCACHEDIR attribute:
CCMSetup.exe SMSCACHEDIR="D:\sccm\cache"
Will force the client to install the cache folder to the D drive in a new folder
Maybe the client is already installed but you want to change the folder. Here is a VbScript that you can push down to the client. This takes a fraction of a second to run on the client so they are not affected by the change. Be aware that Cache cannot have any advertisment that is active. If so then you can't move the cache.
--------------------------
Dim oUIResourceMgr
Dim oCache
Set oUIResourceMgr = CreateObject("UIResource.UIResourceMgr")
Set oCacheInfo = oUIResourceMgr.GetCacheInfo
oCacheInfo.Location = "D:SCCM\Cache"
-------------------------------------
Sunday, May 10, 2009
Inventory Certificates
Ok here is the link to the code to inventory certificates.
http://www.sccm-tools.com/tools/vbscript/vbscript-certificates.html
http://www.sccm-tools.com/tools/vbscript/vbscript-certificates.html
Inventory Certificates
Recently we found some Native Mode computers that had expired computer certificates. When this happens the client becomes unhealth and thus stops responding. Until the cert is renewed it will just sit in a dead state. Well instead of working "reactively" I want to be "proactive." Now I have found several differnet reasons for certificate renewal errors which I have document one or more here in my blog. With my latest work with Sherry Kissinger, another MVP in the ConfigMgr area we were able to create a VBscript that would pull the cert data and inject into WMI so it can be pulled at inventory time. Since the expiration date (and count down in days) is pulled a report can be run that will tell you if a computer is getting ready to expire or has already occured.
The only difficult issue is that it relies on Capicom, which some admins don't use. It will attempt to register the dlls so it can inventory. I haven't found a better way to do this. .NET offers some but again you are dependent on an installtion of .NET and some other assemblies. Well hopefully I can have some others confirm this works correctly in their test enviroments. I will then post the code here, link from the original post in the Technet Forums and move it into production.
The only difficult issue is that it relies on Capicom, which some admins don't use. It will attempt to register the dlls so it can inventory. I haven't found a better way to do this. .NET offers some but again you are dependent on an installtion of .NET and some other assemblies. Well hopefully I can have some others confirm this works correctly in their test enviroments. I will then post the code here, link from the original post in the Technet Forums and move it into production.
Sunday, October 19, 2008
Report Right click tool
Here is an SCCM console extension that could also be used for SMS if changed for the MMC GUID system.
The Tool is designed to allow the admin to run any of the reports. All that is needed is the reporting point server name, the report ID and the values that need to be passed.
report.vbs
Example:
Report.vbs sms-serve1 170 MachineName ##Sub:name##
Currently I have it set for the individual computer and collection GUIDS. This can be added and set to run for almost any one of the guids. Instead of trying to post all the code here I will give you a link to my sccm tools website and you can download the code from there.
http://www.sccm-tools.com/tools/rightclick/rightclick-webreports.html
The Tool is designed to allow the admin to run any of the reports. All that is needed is the reporting point server name, the report ID and the values that need to be passed.
report.vbs
Example:
Report.vbs sms-serve1 170 MachineName ##Sub:name##
Currently I have it set for the individual computer and collection GUIDS. This can be added and set to run for almost any one of the guids. Instead of trying to post all the code here I will give you a link to my sccm tools website and you can download the code from there.
http://www.sccm-tools.com/tools/rightclick/rightclick-webreports.html
Tuesday, August 19, 2008
Deploy Shortcut
I give credit to a co-worker of mine. We were deploying Hummingbird (3270 Terminal program) and we needed to create a shortcut to a predefined location for each person.
Here is a vbscript example of how to create a shortcut link on the fly
--------------------------------------------
'declare variables
dim WshShell, fso, oShellLink, strDesktop, strAppData
'set variables
set WshShell = WScript.CreateObject("WScript.Shell")
set fso = CreateObject("Scripting.FileSystemObject")
strDesktop = WshShell.SpecialFolders("Desktop")
strAppData = WshShell.ExpandEnvironmentStrings("%AppData%")
'do they have the profile data in their My Profile Space
if fso.FileExists(strAppData & "\Hummingbird\Connectivity\13.00\Profile\XYZ.hep") then
'create shortcut
set oShellLink = WshShell.CreateShortcut(strDesktop & "\VTAM.lnk")
oShellLink.TargetPath = strAppData & "\Hummingbird\Connectivity\13.00\Profile\VTAM.hep"
oShellLink.WindowStyle = 1
oShellLink.Description = "Hover description here"
oShellLink.Save
else
'they don't have them in the My Profile Space, should I move them there?
end if
--------------------------------------------------
Here is a vbscript example of how to create a shortcut link on the fly
--------------------------------------------
'declare variables
dim WshShell, fso, oShellLink, strDesktop, strAppData
'set variables
set WshShell = WScript.CreateObject("WScript.Shell")
set fso = CreateObject("Scripting.FileSystemObject")
strDesktop = WshShell.SpecialFolders("Desktop")
strAppData = WshShell.ExpandEnvironmentStrings("%AppData%")
'do they have the profile data in their My Profile Space
if fso.FileExists(strAppData & "\Hummingbird\Connectivity\13.00\Profile\XYZ.hep") then
'create shortcut
set oShellLink = WshShell.CreateShortcut(strDesktop & "\VTAM.lnk")
oShellLink.TargetPath = strAppData & "\Hummingbird\Connectivity\13.00\Profile\VTAM.hep"
oShellLink.WindowStyle = 1
oShellLink.Description = "Hover description here"
oShellLink.Save
else
'they don't have them in the My Profile Space, should I move them there?
end if
--------------------------------------------------
Thursday, July 31, 2008
Client action revamp
I have blown this old post away:
http://sms-hints-tricks.blogspot.com/2008/06/client-actions-for-entire-collection.html
I have deleted code for this tool and rewritten from scratch.
I have a problem with textarea tag in that it put breaks in the text area. Sorry about that. Until I get that fixed you will need to just to do a search and replace. The tool will allow that admin to right click and force an action on a collection or single computer. Unlike other tools for policy and inventory I don't kick the inventory key forcing the machine to do a Full inventory. I kick off a standard Inventory so it will be a delta and fast.
http://sms-hints-tricks.blogspot.com/2008/06/client-actions-for-entire-collection.html
I have deleted code for this tool and rewritten from scratch.
I have a problem with textarea tag in that it put breaks in the text area. Sorry about that. Until I get that fixed you will need to just to do a search and replace. The tool will allow that admin to right click and force an action on a collection or single computer. Unlike other tools for policy and inventory I don't kick the inventory key forcing the machine to do a Full inventory. I kick off a standard Inventory so it will be a delta and fast.
Tuesday, July 15, 2008
SMS to SCCM upgrade and Client Cache Issues
If you perform an upgrade of your SMS 2003 server to SCCM 2007 you should be aware of a potentional problem with your client cache. Client cache is not cleared when the new client is installed. This could cause problems with client tombstoning correctly. There are several ways to fix this. You should do a manual "clear cache" on every system. I know you are laughing... I have a vbscript that clears the cache of a client that can be used with a login script. I am currently working on making it a right click tool. This could be used once the site is upgraded and it could also be used at any time you feel the need to clear the cache of a client.
I have it 90% written, since I plan to use it in my enviroment. I will at a convention in Las Vegas presenting my research in the area of GIS so I won't have time to work on it. I hope to have it done by Friday if not the weekend. I will post it here for those that wish to use it.
I have it 90% written, since I plan to use it in my enviroment. I will at a convention in Las Vegas presenting my research in the area of GIS so I won't have time to work on it. I hope to have it done by Friday if not the weekend. I will post it here for those that wish to use it.
Tuesday, June 17, 2008
SCCM Right Click Tools by Rick Houchins
Rick over at MyITforum (a place I love to visit) has updated his Right click tool program.
Version 1.7 (6/17/2008)
http://myitforum.com/cs2/blogs/rhouchins/archive/2008/04/09/sccm-right-click-tools.aspx
I will update this page as he updates the application. It is a very nice collection of tools. I suggest you check it out.
Version 1.7 (6/17/2008)
http://myitforum.com/cs2/blogs/rhouchins/archive/2008/04/09/sccm-right-click-tools.aspx
I will update this page as he updates the application. It is a very nice collection of tools. I suggest you check it out.
Wednesday, June 11, 2008
Client actions for an entire collection
This page still isn't displaying correclty.
Here is a link on the SCCM tools website
http://www.sccm-tools.com/tools/rightclick/rightclick-clientactions.html
Ok I have deleted this whole section since I re-wrote this tool...
Files: (files names are case sensative)
clientactions.vbs : File that controls everything
Clearcache.vbs : Client clear cache file
Inventory.vbs: Client HW/SW inventory file
Policy.vbs: Client machine policy refresh
Computer.XML : This will be the xml file for right click on a computer
Collection.XML: This will be the xml file for right click on a collection
C:\Program Files\MCNS\ClientActions\ : Location where all the files are stored on the server
7ba8bf44-2344-4035-bdb4-16630291dcf6 - computers
fa922e1a-6add-477f-b70e-9a164f3b11a2 - this GUID is for first-level collections
dbb315c3-1d8b-4e6a-a7b1-db8246890f59 - this GUID is for all subcollections
---
x:\Program Files\Microsoft Configuration Manager\AdminUI\XmlStorage\Extensions
Under this folder create the guid and place the appropriate XML file
-------------------------------------------------------------------------
******Clientactions.vbs***************
******Clearcache.vbs***************
******Inventory.vbs***************
******Policy.vbs***************
******Computer.XML***************
******Collection.XML***************
Here is a link on the SCCM tools website
http://www.sccm-tools.com/tools/rightclick/rightclick-clientactions.html
Ok I have deleted this whole section since I re-wrote this tool...
Files: (files names are case sensative)
clientactions.vbs : File that controls everything
Clearcache.vbs : Client clear cache file
Inventory.vbs: Client HW/SW inventory file
Policy.vbs: Client machine policy refresh
Computer.XML : This will be the xml file for right click on a computer
Collection.XML: This will be the xml file for right click on a collection
C:\Program Files\MCNS\ClientActions\ : Location where all the files are stored on the server
7ba8bf44-2344-4035-bdb4-16630291dcf6 - computers
fa922e1a-6add-477f-b70e-9a164f3b11a2 - this GUID is for first-level collections
dbb315c3-1d8b-4e6a-a7b1-db8246890f59 - this GUID is for all subcollections
---
x:\Program Files\Microsoft Configuration Manager\AdminUI\XmlStorage\Extensions
Under this folder create the guid and place the appropriate XML file
-------------------------------------------------------------------------
******Clientactions.vbs***************
******Clearcache.vbs***************
******Inventory.vbs***************
******Policy.vbs***************
******Computer.XML***************
******Collection.XML***************
Saturday, May 31, 2008
Vbscript behavior

Wscript Method wscript x.vbs

Cscript Method cscript x.vbs
Do you have right click tools that run in a command (DOS) box. And you have an "Enter" key function so it will stay open so you can see the data.
There are 2 things you can do.
1. Run with a wscript xxx.vbs
This will force it to use the wscript method and data will be placed in a nice popup box
2. Set the default method for vbscript to wscript
wscript /H:WScript
A popup will tell you that the default is now wscript do the same with a cscript to change it back
This will make some of the right click tools that display information alot easier to read and gives it a more professional look.
Tuesday, May 20, 2008
Internet Based Client setup
Did you already deploy the client to your machines? Did you want to setup some laptops or computers with Internet Based management. Use this vbscript to push the change to the necessary computers:
-------Internetclient.vbs----------------
On Error Resume Next
Dim newInternetBasedManagementPointFQDN
Dim client
newInternetBasedManagementPointFQDN = "foo.com"
set client = CreateObject ("Microsoft.SMS.Client")
client.SetInternetManagementPointFQDN newInternetBasedManagementPointFQDN
' Clear variables.
Set client = Nothing
Set internetBasedManagementPointFQDN = Nothing
--------------------------------------------------------
-------Internetclient.vbs----------------
On Error Resume Next
Dim newInternetBasedManagementPointFQDN
Dim client
newInternetBasedManagementPointFQDN = "foo.com"
set client = CreateObject ("Microsoft.SMS.Client")
client.SetInternetManagementPointFQDN newInternetBasedManagementPointFQDN
' Clear variables.
Set client = Nothing
Set internetBasedManagementPointFQDN = Nothing
--------------------------------------------------------
Tuesday, May 13, 2008
Collections with Maintenance Windows
Here is an update to my previous vbscript file that had collection listings.
This vbscript can be run from the console of SCCM. It will tell you what user a collection is in, what collection a computer is in. You also have the option of seeing if a maintenance window is set to the collection. This is my first version of this. Please let me know any changes
------------------compmain.vbs----------------------
'Matthew Hudson
'There is no warranty, run code at your own risk
''' sytanx: Application ResourceID Option
' option= blank No tag
' option=1 Collections with Maintenance windows will have a *
' option=2 Collections with Maintenance windows will have a description next to them
on error resume next
Dim CollectionArray(100)
Dim MainWindowArray(100)
count=0
Set objArgs = WScript.Arguments
if (objArgs.count > 1) then
Mainoption = wscript.arguments.item(1)
end if
ResourceID = wscript.arguments.item(0)
Set Shell = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set SWbemLocator=CreateObject("WbemScripting.SWbemLocator")
set SWbemServices = SWbemLocator.ConnectServer("SERVER","root\SMS\site_XXXX")
Set connection= swbemServices
strQuery = "select * from SMS_CollectionMember_a where ResourceID='"+ ResourceID +"'"
Set Collections = SWbemServices.ExecQuery(strQuery)
'''''''''''''''''' move through the collections
for each Collection in Collections
set Collectionfound=SWbemServices.Get("SMS_Collection='" & Collection.CollectionID & "'" )
CollectionArray(count)=Collectionfound.Name
'''''' see if there is a maintenance window
Set collectionSettingsInstance = SWbemServices.Get("SMS_CollectionSettings.CollectionID='" & Collection.CollectionID &"'" )
Set allCollectionSettings = connection.ExecQuery("Select * From SMS_CollectionSettings Where CollectionID = '" & Collection.CollectionID & "'")
If allCollectionSettings.Count > 0 then
MaintenanceWindowArray = collectionSettingsInstance.ServiceWindows
'wscript.echo Collectionfound.Name & len(MaintenanceWindowArray(0).Name)
if Mainoption="2" then
MainWindowArray(count)=MaintenanceWindowArray(0).Description
end if
if Mainoption="1" then
MainWindowArray(count)="*"
end if
end if
count=count+1
Next
'''''''''''''''
'Sort Collection list
for i = count - 2 To 0 Step -1
for j= 0 to i
if CollectionArray(j)>CollectionArray(j+1) then
temp=CollectionArray(j+1)
temp2=MainWindowArray(j+1)
CollectionArray(j+1)=CollectionArray(j)
MainWindowArray(j+1)=MainWindowArray(j)
CollectionArray(j)=temp
MainWindowArray(j)=temp2
end if
next
next
''' print out the collection listing
For NC = 0 to count-1
WhatCollections= WhatCollections & CollectionArray(NC) & " " & MainWindowArray(NC) & VbCrLf
Next
Wscript.echo WhatCollections
'''''''''''''''
'
-------------------------------------
<ActionDescription Class="Group" DisplayName="MCNS" MnemonicDisplayName="MCNS" Description="MCNS Tools" SqmDataPoint="100">
<ActionGroups>
<ActionDescription Class="Executable" DisplayName="Collection Listing" MnemonicDisplayName="Collection Listing" Description="Display machine Collection membership">
<Executable>
<FilePath>C:\Program Files\MCNS\collections\compmain.vbs</FilePath>
<Parameters>##SUB:ResourceID## 1</Parameters>
</Executable>
</ActionDescription>
</ActionGroups>
</ActionDescription>
If the tool vbscript just runs a black box and disappears then check out this link
http://sms-hints-tricks.blogspot.com/2008/05/vbscript-behavior.html
This vbscript can be run from the console of SCCM. It will tell you what user a collection is in, what collection a computer is in. You also have the option of seeing if a maintenance window is set to the collection. This is my first version of this. Please let me know any changes
------------------compmain.vbs----------------------
'Matthew Hudson
'There is no warranty, run code at your own risk
''' sytanx: Application ResourceID Option
' option= blank No tag
' option=1 Collections with Maintenance windows will have a *
' option=2 Collections with Maintenance windows will have a description next to them
on error resume next
Dim CollectionArray(100)
Dim MainWindowArray(100)
count=0
Set objArgs = WScript.Arguments
if (objArgs.count > 1) then
Mainoption = wscript.arguments.item(1)
end if
ResourceID = wscript.arguments.item(0)
Set Shell = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set SWbemLocator=CreateObject("WbemScripting.SWbemLocator")
set SWbemServices = SWbemLocator.ConnectServer("SERVER","root\SMS\site_XXXX")
Set connection= swbemServices
strQuery = "select * from SMS_CollectionMember_a where ResourceID='"+ ResourceID +"'"
Set Collections = SWbemServices.ExecQuery(strQuery)
'''''''''''''''''' move through the collections
for each Collection in Collections
set Collectionfound=SWbemServices.Get("SMS_Collection='" & Collection.CollectionID & "'" )
CollectionArray(count)=Collectionfound.Name
'''''' see if there is a maintenance window
Set collectionSettingsInstance = SWbemServices.Get("SMS_CollectionSettings.CollectionID='" & Collection.CollectionID &"'" )
Set allCollectionSettings = connection.ExecQuery("Select * From SMS_CollectionSettings Where CollectionID = '" & Collection.CollectionID & "'")
If allCollectionSettings.Count > 0 then
MaintenanceWindowArray = collectionSettingsInstance.ServiceWindows
'wscript.echo Collectionfound.Name & len(MaintenanceWindowArray(0).Name)
if Mainoption="2" then
MainWindowArray(count)=MaintenanceWindowArray(0).Description
end if
if Mainoption="1" then
MainWindowArray(count)="*"
end if
end if
count=count+1
Next
'''''''''''''''
'Sort Collection list
for i = count - 2 To 0 Step -1
for j= 0 to i
if CollectionArray(j)>CollectionArray(j+1) then
temp=CollectionArray(j+1)
temp2=MainWindowArray(j+1)
CollectionArray(j+1)=CollectionArray(j)
MainWindowArray(j+1)=MainWindowArray(j)
CollectionArray(j)=temp
MainWindowArray(j)=temp2
end if
next
next
''' print out the collection listing
For NC = 0 to count-1
WhatCollections= WhatCollections & CollectionArray(NC) & " " & MainWindowArray(NC) & VbCrLf
Next
Wscript.echo WhatCollections
'''''''''''''''
'
-------------------------------------
<ActionDescription Class="Group" DisplayName="MCNS" MnemonicDisplayName="MCNS" Description="MCNS Tools" SqmDataPoint="100">
<ActionGroups>
<ActionDescription Class="Executable" DisplayName="Collection Listing" MnemonicDisplayName="Collection Listing" Description="Display machine Collection membership">
<Executable>
<FilePath>C:\Program Files\MCNS\collections\compmain.vbs</FilePath>
<Parameters>##SUB:ResourceID## 1</Parameters>
</Executable>
</ActionDescription>
</ActionGroups>
</ActionDescription>
If the tool vbscript just runs a black box and disappears then check out this link
http://sms-hints-tricks.blogspot.com/2008/05/vbscript-behavior.html
Wednesday, November 28, 2007
SMS tool: What collection is a computer or User in?
[NOTE: I have updated this with a new version to work with SCCM and Maintenance windows collections-with-maintenance-windows (May 2008)]
OK I have this pulled from my C# app to vbscript. It isn't pretty but it works. The one problem is that I didn't create an array to sort the list so if you wanted sorted you will need to do it. I will update this later with the sort feature. Obviously I make no warranty. You will need to add the sever data and change the path to match your computer. Copy the vbscript to your folder, run the reg file and you will then see it in the MMC when you right click on a computer.
This will work with SMS 2003. To work with SCCM you will need to change the GUID and possible look at the WMI query for changes
-----------------------------Addmmc.reg-----------------------
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MMC\NodeTypes\{4D26C0D4-A8A8-11D1-9BD9-00C04FBBD480}\Extensions\SMS_tools\xCol Mem]
"Name"="Collection Membership"
"Description"="Show what collections a computer is in"
"CommandLine"="wscript.exe \"c:\\Program Files\\MCNS\\Collections\\computercols.vbs\" ##SUB:ResourceID##"
------------------------------------------------------------------
'------------ SCCM console -----------------
c:\program files Files\Microsoft Configuration Manager\AdminUI\XmlStorage\Extensions\Actions\7ba8bf44-2344-4035-bdb4-16630291dcf6
'------mcns.xml---------------------------
<actiondescription class="Group" displayname="MCNS" mnemonicdisplayname="MCNS" description="MCN Tools" sqmdatapoint="100">
<actiongroups>
<actiondescription class="Executable" displayname="Collection Listing" mnemonicdisplayname="Collection Listing" description="Display machine Collection membership">
<executable>
<filepath>C:\Program Files\MCNS\collections\computercols07.vbs
</filepath>
<parameters>##SUB:ResourceID##</parameters>
</executable>
</actiondescription>
</actiongroups></actiondescription>
'---------------------------------------------
---------------------------computercols.vbs -----------------------------------------------
Dim CollectionArray(100)
count=0
Set objArgs = WScript.Arguments
if (objArgs.count > 0) then
MyPos = InStr(objArgs(0), ":")
ResourceID = wscript.arguments.item(0)
end if
Set Shell = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set SWbemLocator=CreateObject("WbemScripting.SWbemLocator")
set SWbemServices = SWbemLocator.ConnectServer("server","root\SMS\site_XXX")
strQuery = "select * from SMS_CollectionMember_a where ResourceID='"+ ResourceID +"'"
Set Collections = SWbemServices.ExecQuery(strQuery)
for each Collection in Collections
set Collectionfound=SWbemServices.Get("SMS_Collection='" & Collection.CollectionID & "'" )
CollectionArray(count)=Collectionfound.Name
count=count+1
Next
'''''''''''''''
'Sort Collection list
for i = count - 2 To 0 Step -1
for j= 0 to i
if CollectionArray(j)>CollectionArray(j+1) then
temp=CollectionArray(j+1)
CollectionArray(j+1)=CollectionArray(j)
CollectionArray(j)=temp
end if
next
next
''' print out the collection listing
For NC = 0 to count-1
WhatCollections= WhatCollections & CollectionArray(NC) & VbCrLf
Next
Wscript.echo WhatCollections
--------------------------------------------------------------------------
OK I have this pulled from my C# app to vbscript. It isn't pretty but it works. The one problem is that I didn't create an array to sort the list so if you wanted sorted you will need to do it. I will update this later with the sort feature. Obviously I make no warranty. You will need to add the sever data and change the path to match your computer. Copy the vbscript to your folder, run the reg file and you will then see it in the MMC when you right click on a computer.
This will work with SMS 2003. To work with SCCM you will need to change the GUID and possible look at the WMI query for changes
-----------------------------Addmmc.reg-----------------------
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MMC\NodeTypes\{4D26C0D4-A8A8-11D1-9BD9-00C04FBBD480}\Extensions\SMS_tools\xCol Mem]
"Name"="Collection Membership"
"Description"="Show what collections a computer is in"
"CommandLine"="wscript.exe \"c:\\Program Files\\MCNS\\Collections\\computercols.vbs\" ##SUB:ResourceID##"
------------------------------------------------------------------
'------------ SCCM console -----------------
c:\program files Files\Microsoft Configuration Manager\AdminUI\XmlStorage\Extensions\Actions\7ba8bf44-2344-4035-bdb4-16630291dcf6
'------mcns.xml---------------------------
<actiondescription class="Group" displayname="MCNS" mnemonicdisplayname="MCNS" description="MCN Tools" sqmdatapoint="100">
<actiongroups>
<actiondescription class="Executable" displayname="Collection Listing" mnemonicdisplayname="Collection Listing" description="Display machine Collection membership">
<executable>
<filepath>C:\Program Files\MCNS\collections\computercols07.vbs
</filepath>
<parameters>##SUB:ResourceID##</parameters>
</executable>
</actiondescription>
</actiongroups></actiondescription>
'---------------------------------------------
---------------------------computercols.vbs -----------------------------------------------
Dim CollectionArray(100)
count=0
Set objArgs = WScript.Arguments
if (objArgs.count > 0) then
MyPos = InStr(objArgs(0), ":")
ResourceID = wscript.arguments.item(0)
end if
Set Shell = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set SWbemLocator=CreateObject("WbemScripting.SWbemLocator")
set SWbemServices = SWbemLocator.ConnectServer("server","root\SMS\site_XXX")
strQuery = "select * from SMS_CollectionMember_a where ResourceID='"+ ResourceID +"'"
Set Collections = SWbemServices.ExecQuery(strQuery)
for each Collection in Collections
set Collectionfound=SWbemServices.Get("SMS_Collection='" & Collection.CollectionID & "'" )
CollectionArray(count)=Collectionfound.Name
count=count+1
Next
'''''''''''''''
'Sort Collection list
for i = count - 2 To 0 Step -1
for j= 0 to i
if CollectionArray(j)>CollectionArray(j+1) then
temp=CollectionArray(j+1)
CollectionArray(j+1)=CollectionArray(j)
CollectionArray(j)=temp
end if
next
next
''' print out the collection listing
For NC = 0 to count-1
WhatCollections= WhatCollections & CollectionArray(NC) & VbCrLf
Next
Wscript.echo WhatCollections
--------------------------------------------------------------------------
Friday, November 23, 2007
Add computer to collection, Vbscript
Edit: October 25, 2008
I have added a better way of doing this via a right click
Here at Sccm-tools.com. This uses a HTA file so you can right click on a computer and add it to collections or right click on a computer in a collection or query and add it to multiple collections.
*-------------
I didn't create the script but someone had asked if there was a way to add a computer to a collection. I have the .Net code to do it but here is the vbscript method. This can be used to add the current computer to a collection as soon as the computer has imaged or performed some other action.
' *************************************************************************
' === Initialize Variables and Constants
' *************************************************************************
Option Explicit ' --- Force Declaration of variables
' === Script arguments override ====
' These variables are for testing only. To test, assign values to the variables and then comment out
' the Comment-out the ValdateArguments()subrourtine. To restur, comment out the variables below, and
' uncomment the ValdateArguments() subroutine to allow original argument values to be passed to the script.
'TargetCollectionName = "#Test-AddUser"
'NewComputerName = "LT01385"
' *************************************************************************
' == SMS Envronment Variables
CONST SMSSiteCode = "xxx" ' --- SMS Server Central Site Code
CONST SMSServer = "xxxxx" ' --- SMS Server
' -------------------------------------------------------------
' === Script varables
DIM lLocator ' --- Object handle for WMI Scripting "Locator object" ?
DIM gService ' --- Object hanlde for WMI object model ConnectServer object ?
DIM ResID ' --- Store the SMS ResourceID for the desired resource
DIM RuleName ' --- Name for Membership Rule (label seen in SMS collection properties)
DIM AllComputersSet ' --- Object handle to store the query results of the SMS System_R_System table
DIM AllComputersItem ' --- Index variable used for the AllComputersSet Object Collection (Array)
DIM CollectionRule ' --- CollectionRule
DIM oCollectionSet ' --- Object handle to store collection names from table SMS_Collection
DIM CollListItem ' --- Index variable for Collection Object (Array)
DIM WshShell ' --- Object handle for WshShell object (Windows Script Host Shell)
DIM oFSO ' --- Object handle for the FSO (File System Object)
DIM AddMembRuleSuccess ' --- Flag to track added collection membership rule status
Public TargetCollectionName ' --- Store command-line argument for desired collection name to add a computer resource
Public NewComputerName ' --- Store command-line argument for desired computer resource to add to the collection
' === Script Environment
' *********************************************************************************************
' ===== Connect to provider namespace for local computer.
' *********************************************************************************************
Set lLocator = CreateObject("WbemScripting.SWbemLocator")
Set gService = lLocator.ConnectServer(SMSServer, "Root\SMS\Site_" & SMSSiteCode)
' -- /// FileSytemObject already instantiated in subroutine ScriptPath() into object handle oFSO
' ********************************************
' ===== Script Start =======================
' ********************************************
ValdateArguments() ' --- Load command-line arguments into variables
ValidateComputerResource() ' --- Find computer name match in SMS "All Systems" table SMS_R_System
FindCollandAddMembRule() ' --- Find specific collection and add membership rule to the collection
wscript.quit
' *************************************************************************************
' *************************************************************************************
' Subroutines
' *************************************************************************************
' *************************************************************************************
' *************************************************************************************
' **** Validate command-line parameters and load them into variables to be used
' **** by the script. Otherwise, display an error message and exit the script
' *************************************************************************************
Sub ValdateArguments() ' --- Load command-line arguments into variables
If wscript.arguments.count<> 2 Then
wscript.echo "Two arguments please - The collection followed by Computer Name"
wscript.quit ' --- quit if invalid number of arguments
Else
TargetCollectionName = wscript. arguments(0)
NewComputerName = wscript. arguments(1)
End if
End Sub
' **************************************************************************
' **** Search the SMS_R_System table for a match to the computer name passed by the
' **** command-line argument, then store the corresponding SMS ResourceID
' **** in a variable.
' **************************************************************************
Sub ValidateComputerResource() ' --- Find computer name match in SMS "All Systems" table SMS_R_System
' --- Create object with query results from the SMS SQL table SMS_R_System
Set AllComputersSet = gService.ExecQuery("Select * From SMS_R_System WHERE Name LIKE ""%" + NewComputerName + "%""")
' --- Iterate through the SMS_R_System table resultset (loaded into the variable "AllComputersSet")
' and match the name to be added. Then retreive the ResourceID for the corresponding computer record.
For Each AllComputersItem In AllComputersSet
If UCase(AllComputersItem.Name) = UCase(NewComputerName) Then
ResID = AllComputersItem.ResourceID
RuleName = "ResourceID = " & ResID & " " & AllComputersItem.NetBiosName
End If
Next
End Sub
'***************************************************************************
'**** Walk through the the whole list of SMS collections and search for a match to the
'**** desired collection. If the desired collection is sucessfully found, then
'**** add the Membership rule created in the subrioutine CreateSMSDirectRule() to the
'**** existing matched collection.
'***************************************************************************
Sub FindCollandAddMembRule() ' --- Find specific collection and add membership rule to the collection
' --- Create object with query results from the SMS_Collection table
Set oCollectionSet = gService.ExecQuery("Select * From SMS_Collection")
AddMembRuleSuccess = "False" ' --- Initialize flag to indicate Added Collection Membership Rule Failed
' --- Walk through the list of SMS collections and find a match to the collection name passed by the
' command-line argument. If the collection exists, then add the new direct rule that includes
' the new computer name to the collection.
For Each CollListItem In oCollectionSet
If CollListItem.Name = TargetCollectionName Then
'***************************************************************************
'**** Create a direct membership rule (spawn a blank instance) to add to an existing collection.
'**** Then give that instance the values it needs - this is REQUIRED
'***************************************************************************
Set CollectionRule = gService.Get("SMS_CollectionRuleDirect").SpawnInstance_()
CollectionRule.ResourceClassName = "SMS_R_System"
CollectionRule.RuleName = RuleName
CollectionRule.ResourceID = ResID
' ***** Add the direct membership rule to matched collection. ************
CollListItem.AddMembershipRule CollectionRule
If Err.Number = 0 Then ' --- If Error = 0, then adding membership was successful.
AddMembRuleSuccess = "True" ' --- Set flag to "True" to indicate memb. rule added Successfully
End If
End If
Next
End Sub
I have added a better way of doing this via a right click
Here at Sccm-tools.com. This uses a HTA file so you can right click on a computer and add it to collections or right click on a computer in a collection or query and add it to multiple collections.
*-------------
I didn't create the script but someone had asked if there was a way to add a computer to a collection. I have the .Net code to do it but here is the vbscript method. This can be used to add the current computer to a collection as soon as the computer has imaged or performed some other action.
' *************************************************************************
' === Initialize Variables and Constants
' *************************************************************************
Option Explicit ' --- Force Declaration of variables
' === Script arguments override ====
' These variables are for testing only. To test, assign values to the variables and then comment out
' the Comment-out the ValdateArguments()subrourtine. To restur, comment out the variables below, and
' uncomment the ValdateArguments() subroutine to allow original argument values to be passed to the script.
'TargetCollectionName = "#Test-AddUser"
'NewComputerName = "LT01385"
' *************************************************************************
' == SMS Envronment Variables
CONST SMSSiteCode = "xxx" ' --- SMS Server Central Site Code
CONST SMSServer = "xxxxx" ' --- SMS Server
' -------------------------------------------------------------
' === Script varables
DIM lLocator ' --- Object handle for WMI Scripting "Locator object" ?
DIM gService ' --- Object hanlde for WMI object model ConnectServer object ?
DIM ResID ' --- Store the SMS ResourceID for the desired resource
DIM RuleName ' --- Name for Membership Rule (label seen in SMS collection properties)
DIM AllComputersSet ' --- Object handle to store the query results of the SMS System_R_System table
DIM AllComputersItem ' --- Index variable used for the AllComputersSet Object Collection (Array)
DIM CollectionRule ' --- CollectionRule
DIM oCollectionSet ' --- Object handle to store collection names from table SMS_Collection
DIM CollListItem ' --- Index variable for Collection Object (Array)
DIM WshShell ' --- Object handle for WshShell object (Windows Script Host Shell)
DIM oFSO ' --- Object handle for the FSO (File System Object)
DIM AddMembRuleSuccess ' --- Flag to track added collection membership rule status
Public TargetCollectionName ' --- Store command-line argument for desired collection name to add a computer resource
Public NewComputerName ' --- Store command-line argument for desired computer resource to add to the collection
' === Script Environment
' *********************************************************************************************
' ===== Connect to provider namespace for local computer.
' *********************************************************************************************
Set lLocator = CreateObject("WbemScripting.SWbemLocator")
Set gService = lLocator.ConnectServer(SMSServer, "Root\SMS\Site_" & SMSSiteCode)
' -- /// FileSytemObject already instantiated in subroutine ScriptPath() into object handle oFSO
' ********************************************
' ===== Script Start =======================
' ********************************************
ValdateArguments() ' --- Load command-line arguments into variables
ValidateComputerResource() ' --- Find computer name match in SMS "All Systems" table SMS_R_System
FindCollandAddMembRule() ' --- Find specific collection and add membership rule to the collection
wscript.quit
' *************************************************************************************
' *************************************************************************************
' Subroutines
' *************************************************************************************
' *************************************************************************************
' *************************************************************************************
' **** Validate command-line parameters and load them into variables to be used
' **** by the script. Otherwise, display an error message and exit the script
' *************************************************************************************
Sub ValdateArguments() ' --- Load command-line arguments into variables
If wscript.arguments.count<> 2 Then
wscript.echo "Two arguments please - The collection followed by Computer Name"
wscript.quit ' --- quit if invalid number of arguments
Else
TargetCollectionName = wscript. arguments(0)
NewComputerName = wscript. arguments(1)
End if
End Sub
' **************************************************************************
' **** Search the SMS_R_System table for a match to the computer name passed by the
' **** command-line argument, then store the corresponding SMS ResourceID
' **** in a variable.
' **************************************************************************
Sub ValidateComputerResource() ' --- Find computer name match in SMS "All Systems" table SMS_R_System
' --- Create object with query results from the SMS SQL table SMS_R_System
Set AllComputersSet = gService.ExecQuery("Select * From SMS_R_System WHERE Name LIKE ""%" + NewComputerName + "%""")
' --- Iterate through the SMS_R_System table resultset (loaded into the variable "AllComputersSet")
' and match the name to be added. Then retreive the ResourceID for the corresponding computer record.
For Each AllComputersItem In AllComputersSet
If UCase(AllComputersItem.Name) = UCase(NewComputerName) Then
ResID = AllComputersItem.ResourceID
RuleName = "ResourceID = " & ResID & " " & AllComputersItem.NetBiosName
End If
Next
End Sub
'***************************************************************************
'**** Walk through the the whole list of SMS collections and search for a match to the
'**** desired collection. If the desired collection is sucessfully found, then
'**** add the Membership rule created in the subrioutine CreateSMSDirectRule() to the
'**** existing matched collection.
'***************************************************************************
Sub FindCollandAddMembRule() ' --- Find specific collection and add membership rule to the collection
' --- Create object with query results from the SMS_Collection table
Set oCollectionSet = gService.ExecQuery("Select * From SMS_Collection")
AddMembRuleSuccess = "False" ' --- Initialize flag to indicate Added Collection Membership Rule Failed
' --- Walk through the list of SMS collections and find a match to the collection name passed by the
' command-line argument. If the collection exists, then add the new direct rule that includes
' the new computer name to the collection.
For Each CollListItem In oCollectionSet
If CollListItem.Name = TargetCollectionName Then
'***************************************************************************
'**** Create a direct membership rule (spawn a blank instance) to add to an existing collection.
'**** Then give that instance the values it needs - this is REQUIRED
'***************************************************************************
Set CollectionRule = gService.Get("SMS_CollectionRuleDirect").SpawnInstance_()
CollectionRule.ResourceClassName = "SMS_R_System"
CollectionRule.RuleName = RuleName
CollectionRule.ResourceID = ResID
' ***** Add the direct membership rule to matched collection. ************
CollListItem.AddMembershipRule CollectionRule
If Err.Number = 0 Then ' --- If Error = 0, then adding membership was successful.
AddMembRuleSuccess = "True" ' --- Set flag to "True" to indicate memb. rule added Successfully
End If
End If
Next
End Sub
Wednesday, October 17, 2007
Laptop Network Configuration Group
Do you have locked down laptops and you want to enable the users to change the ip address. This is assuming they are traveling and need a new ip at a hotel. There are several ways you can accomplish this. Here is a vbscript method.
*-------------------
'' This will add all the domain users to the network config group for laptopson error resume next
Set network = WScript.CreateObject("WScript.Network") strComputer = network.computernameSet objGroup = GetObject("WinNT://" & strComputer & "/Network Configuration Operators,group")Set objUser = GetObject("WinNT://DOMAIN/DOMAIN USERS")objGroup.Add(objUser.ADsPath)
--------------------------------
*-------------------
'' This will add all the domain users to the network config group for laptopson error resume next
Set network = WScript.CreateObject("WScript.Network") strComputer = network.computernameSet objGroup = GetObject("WinNT://" & strComputer & "/Network Configuration Operators,group")Set objUser = GetObject("WinNT://DOMAIN/DOMAIN USERS")objGroup.Add(objUser.ADsPath)
--------------------------------
Wednesday, May 9, 2007
Defrag a computer
Just like doing a disk clean up, you may not have a policy that runs disk defragment at a given time. Maybe you have DiskKeeper. This will allow you to force your computers to run a defrag through SMS. We have a defrag set to run once a month. This can keep the computers running a bit faster and keeps the help desk calls down. Granted if you have a policy or software inplace you can just ignore this one :) I recommend you run the file with "cscript defrag.vbs" so if an error occurs it will not try to force a popup.
-----------defrag.vbs--------------
Set objShell = CreateObject("WScript.Shell")
'Run the Defrag Utility
intRetVal = objShell.Run("%comspec% /c %WinDir%\system32\defrag.exe c: -f -v ", 0, True)
If intRetVal <> 0 Then WScript.Quit intRetVal
-----------------------------------------
-----------defrag.vbs--------------
Set objShell = CreateObject("WScript.Shell")
'Run the Defrag Utility
intRetVal = objShell.Run("%comspec% /c %WinDir%\system32\defrag.exe c: -f -v ", 0, True)
If intRetVal <> 0 Then WScript.Quit intRetVal
-----------------------------------------
Sunday, May 6, 2007
Lock down SMS Control Panel
There are several ways to lock down the control panel I will address the one I know or found. Since this has come up in other forums and newsgroups I thought I would add my 2 cents.
Why would you want to lock it down. Well, if you have a user that is an admin on their machine they might revolt and turn off the service or fool around with the cache to prevent SMS from doing its job. It is a fact of life that some users will have admin rights to their machine. This will hopefully deter or slow them down. There isn't a way to totally stop them.
1. Hide the SMS Control Panel for current user (Systems Managment)
This will require a restart, force it or just wait for them to restart.
-------no show.reg------------------
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Control Panel\don't load]
"SMSCFGRC.cpl"="No"
---------------------------------------------
2. Disable sections of the Contol Panel [Courtesy of Rune Norberg, MS Newsgroup]
For site assignment:>
HKLM\Software\Microsoft\SMS\Mobile Client\Configuration\CP Site Assignment> Options=Disabled (REG_SZ)
For cache:>
HKLM\Software\Microsoft\SMS\Mobile Client\Configuration\CP Cache> Options=Disabled (REG_SZ)
----------------------------------
3. Restart CCM Service on remote machine
If the admin keeps turning off the service you can setup a scheduled task to run say every 3 hours to turn it back on. If they turn off WMI then you have a problem but you can use this to give you a return value if it is failing to start it.
-------------restart sms agent.vbs------------
strComputer = "YourComputer"
strCommand = "net start ccmexec"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set oStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = oStartup.SpawnInstance_
objConfig.ShowWindow = 1
Set oProcess = objWMIService.Get("Win32_Process")
intReturn = oProcess.Create (strCommand, Null, objConfig, intProcessID)
‘’use the intReturn if you want to log success or failure, maybe they turned off Dcom or WMI
--------------------------------------
None of these are top secret and it will only take a little bit of digging for them to fix it. But it will deter some people. You can only try so much.
Why would you want to lock it down. Well, if you have a user that is an admin on their machine they might revolt and turn off the service or fool around with the cache to prevent SMS from doing its job. It is a fact of life that some users will have admin rights to their machine. This will hopefully deter or slow them down. There isn't a way to totally stop them.
1. Hide the SMS Control Panel for current user (Systems Managment)
This will require a restart, force it or just wait for them to restart.
-------no show.reg------------------
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Control Panel\don't load]
"SMSCFGRC.cpl"="No"
---------------------------------------------
2. Disable sections of the Contol Panel [Courtesy of Rune Norberg, MS Newsgroup]
For site assignment:>
HKLM\Software\Microsoft\SMS\Mobile Client\Configuration\CP Site Assignment> Options=Disabled (REG_SZ)
For cache:>
HKLM\Software\Microsoft\SMS\Mobile Client\Configuration\CP Cache> Options=Disabled (REG_SZ)
----------------------------------
3. Restart CCM Service on remote machine
If the admin keeps turning off the service you can setup a scheduled task to run say every 3 hours to turn it back on. If they turn off WMI then you have a problem but you can use this to give you a return value if it is failing to start it.
-------------restart sms agent.vbs------------
strComputer = "YourComputer"
strCommand = "net start ccmexec"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set oStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = oStartup.SpawnInstance_
objConfig.ShowWindow = 1
Set oProcess = objWMIService.Get("Win32_Process")
intReturn = oProcess.Create (strCommand, Null, objConfig, intProcessID)
‘’use the intReturn if you want to log success or failure, maybe they turned off Dcom or WMI
--------------------------------------
None of these are top secret and it will only take a little bit of digging for them to fix it. But it will deter some people. You can only try so much.
Subscribe to:
Posts (Atom)