Siteserver = InputBox("Please enter the name of the SMS/SCCM Site Server")
Sitecode = InputBox("Please enter the Site Code of the SMS/SCCM Site")
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.CreateTextFile("ValidatePkgSourcePath.log")
Dim objSWbemLocator : Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Dim objSWbemServices : Set objSWbemServices = objSWbemLocator.ConnectServer (Siteserver, "root\sms\site_" + Sitecode)
Set colPackages=objSWbemServices.ExecQuery("SELECT * FROM SMS_Package")
For Each objPackage In colPackages
strPackageName = objPackage.Manufacturer &" " &objPackage.Name &" " &objPackage.Version &" " &objPackage.Language
If objPackage.PkgSourcepath = "" Then
objFile.WriteLine strPackageName &" - Sourcepath is empty"
End If
If Not objFSO.FolderExists(objPackage.PkgSourcepath) Then
objFile.WriteLine strPackageName &" - Sourcepath is not valid (" &objPackage.PkgSourcepath &")"
End If
Next
WScript.Echo "Finished"
1/28/2009
vbScript to validate SMS/SCCM Sourcepaths
This Script will check the Sourcepath for each package in SMS or SCCM if it is valid.
9/04/2008
Retrieving "exit strings" from vbScript
Retrieving exit codes from vbScript is not very tricky, but there's no method to retrieve "exit strings" from a script.
Below there's listed a little workaround to keep strings in "computers mind" after a script finished without using tempfiles, registry keys or environment variables as data store.
Step by Step:
ShowResult.vbs
AskUser.vbs
Below there's listed a little workaround to keep strings in "computers mind" after a script finished without using tempfiles, registry keys or environment variables as data store.
Step by Step:
- ShowResult.vbs calls the script AskUser.vbs
- AskUser.vbs captures somes user input
- AskUser.vbs writes the user input into the windows clipboard
- AskUser.vbs ends
- ShowResults.vbs queries the clipboard for the written text
- ShowResults.vbs shows the result
ShowResult.vbs
Dim objShell : set objShell = CreateObject("Wscript.Shell")
Dim objIE :Set objIE = CreateObject("InternetExplorer.Application")
objShell.Run "\AskUser.vbs",1,True
objIE.Navigate("about:blank")
WScript.echo objIE.document.parentwindow.clipboardData.GetData("text")
AskUser.vbs
Dim objIE : Set objIE = CreateObject("InternetExplorer.Application")
If Msgbox("Please press YES or NO", vbYesNo) = vbYes Then
YourText = "YES was pressed"
Else
YourText = "NO was pressed"
End If
'Write to clipboard
objIE.Navigate("about:blank")
objIE.document.parentwindow.clipboardData.SetData "text", YourText
9/03/2008
vbScript to automatically changing a specific DNS Server on all Servers
The following vbScript replaces a specific DNS Server IP with another one, independed if the IP is the Primary or Secondary DNS Server.
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell : Set objShell = CreateObject("Wscript.Shell")
Dim objFile : Set objFile = objFSO.OpenTextFile("c:\computers.txt")
Dim strOldIP : strOldIP = "1.1.1.1"
dim strNewIP : strNewIP = "2.2.2.2"
Dim arrDNSServer(2)
dim i : i = 0
Do While Not objFile.AtEndOfStream
currentserver = objFile.ReadLine
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & currentserver & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each objNicConfig In colNicConfigs
If Not IsNull(objNicConfig.DNSServerSearchOrder) Then
For Each strDNSServer In objNicConfig.DNSServerSearchOrder
arrDNSServer(i) = strDNSServer
i=i+1
Next
End If
Next
If arrDNSServer(0) = strOldIP Then
'Changing the primary dns server
objShell.Run "netsh -r " ¤tserver &" interface ip set dnsserver " &chr(34) &"local area connection" &Chr(34) &" static " &strNewIP &" primary",1,True
objShell.Run "netsh -r " ¤tserver &" interface ip delete dnsserver " &chr(34) &"local area connection" &Chr(34) &" " &arrDNSServer(1),1,True
objShell.Run "netsh -r " ¤tserver &" interface ip add dns " &chr(34) &"local area connection" &Chr(34) &" " &arrDNSServer(1) &" index=2",1,True
ElseIf arrDNSServer(1) = strOldIP Then
'Changing the secondary DNS Server
objShell.Run "netsh -r " ¤tserver &" interface ip delete dnsserver " &chr(34) &"local area connection" &Chr(34) &" " &arrDNSServer(0),1,True
objShell.Run "netsh -r " ¤tserver &" interface ip set dnsserver " &chr(34) &"local area connection" &Chr(34) &" static " &arrDNSServer(0) &" primary",1,True
objShell.Run "netsh -r " ¤tserver &" interface ip add dns " &chr(34) &"local area connection" &Chr(34) &" " &strNewIP &" index=2",1,True
End If
i = 0
Loop
9/02/2008
Get User's last successful and failed logon
The following VBScript will show the last successful and the last failed logon of the current user. Depending of the OS Version the event id's from eventvwr has to be customized.
Dim objNetwork : Set objNetwork = CreateObject("WScript.Network")
strComputer = "."
Dim EventTime, strUsername
strLogonSuccess = "528"
strLogonError = "529"
Set objWMIService = GetObject("winmgmts:" & "{(Security)}!\\" & strComputer & "\root\cimv2")
'Determine the last successful logon process
Set colLoggedEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent Where Logfile = 'Security' and EventCode = '" &strLogonSuccess &"'")
For Each objEvent in colLoggedEvents
If Not IsNull(objEvent.User) And objEvent.User = objNetwork.UserDomain &"\" &objNetwork.UserName Then
If cint(objEvent.Eventcode) = cint(strLogonSuccess) Then
Call ConvertTime(objEvent.TimeWritten)
Wscript.Echo "The last successful Logon from " &objEvent.User &" was at " &EventTime
Exit For
End If
End If
Next
'Determine the last failed logon process
Set colLoggedEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent Where Logfile = 'Security' and EventCode = '" &strLogonError &"'")
For Each objEvent in colLoggedEvents
'Convert username out of the eventvwr message
Call GetUsername(objEvent.Message)
'Check if username from event matches local logged in user
If lcase(cstr(strUsername)) = lcase(cstr(objNetwork.UserName)) Then
If cint(objEvent.Eventcode) = cint(strLogonError) Then
Call ConvertTime(objEvent.TimeWritten)
Wscript.Echo "The last failed Logon from " &strUsername &" was at " &EventTime
Exit For
End If
End If
Next
Function ConvertTime(datetime)
EventTime = Mid(datetime, 5, 2) & "/" & Mid(datetime, 7, 2) & "/" & _
Mid(datetime, 1, 4) & " " & Mid(datetime, 9, 2) & ":" & _
Mid(datetime, 11, 2) & "." & Mid(datetime, 13, 2)
End Function
Function GetUsername(strMessage)
strStart = InStr(strMessage,"User Name:") + 10
strEnd = InStr(strMessage,"Domain:")
strLen = strEnd - strStart
strUsername = Replace(Replace(Replace(Replace(Mid(strMessage,strStart,strLen)," ",""),vbTab, ""),VbCrLf,""), vbNewLine,"")
End Function
7/10/2008
vbScript to backup and restore the windows taskbar toolbars
1. Create a backup of the toolbar settings
The following vbscript creates a backup of the current users toolbar settings.
It's also possible to target other userprofiles or computers. For this the variables HKEY_CURRENT_USER and strComputer must be customized.
The backupfile will be written at D:\ToolbarBackup.txt
2. Restore backup of the toolbar settings
To restore the toolbar settings, the following vbscript must be executed. It's important that the explorer.exe is terminated when restoring the settings, because else the settings are discarded.
The following vbscript creates a backup of the current users toolbar settings.
It's also possible to target other userprofiles or computers. For this the variables HKEY_CURRENT_USER and strComputer must be customized.
The backupfile will be written at D:\ToolbarBackup.txt
Dim strComputer
Dim objFile, objFSO
Dim objRegistry
Dim strKeyPath
Dim arrValues, strValue
Const HKEY_CURRENT_USER = &H80000001
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\Streams\Desktop"
strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("D:\ToolbarBackup.txt")
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
objRegistry.GetBinaryValue HKEY_CURRENT_USER,strKeyPath, "TaskbarWinXP",arrValues
For Each strValue In arrValues
objFile.WriteLine strValue
Next
objFile.Close
Set objRegistry = Nothing
Set objFile = Nothing
Set objFSO = Nothing
2. Restore backup of the toolbar settings
To restore the toolbar settings, the following vbscript must be executed. It's important that the explorer.exe is terminated when restoring the settings, because else the settings are discarded.
Dim strComputer
Dim objFile, objFSO
Dim objRegistry
Dim strKeyPath, strValues, arrStrValues, arrValues
Const HKEY_CURRENT_USER = &H80000001
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\Streams\Desktop"
strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("D:\ToolbarBackup.txt")
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strValues=objFile.ReadAll
arrStrValues=Split(strValues, vbCrLf)
ReDim arrValues(UBound(arrStrValues)-1)
for i=0 To UBound(arrStrValues)-1
arrValues(i)=CInt(arrStrValues(i))
Next
For Each Process in GetObject("winmgmts:").ExecQuery ("select * from Win32_Process where name='explorer.exe'")
Process.Terminate(0)
Next
objRegistry.SetBinaryValue HKEY_CURRENT_USER,strKeyPath, "TaskbarWinXP",arrValues
objFile.Close
Set objRegistry = Nothing
Set objFile = Nothing
Set objFSO = Nothing
4/16/2008
vbscript to check each line in a file if there are included keywords defined in another file
Dim objSourceFile, objKeywordFile, objNewFile, objFSO
Dim currentline, currentvariable, bIncluded
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSourceFile = objFSO.OpenTextFile("D:\sourcefile.txt")
Set objKeywordFile = objFSO.OpenTextFile("D:\keywordfile.txt")
Set objNewFile = objFSO.CreateTextFile("D:\result.txt")
bIncluded = False
Do While Not objSourceFile.AtEndOfStream
currentline = objSourceFile.ReadLine
Call CheckIfIncluded
Loop
Function CheckIfIncluded
Do While Not objKeywordFile.AtEndOfStream
currentvariable = objKeywordFile.ReadLine
If InStr(currentline,currentvariable) Then
bIncluded = False
Exit Do
Else
bIncluded = True
End If
Loop
If bIncluded = True Then
objNewFile.WriteLine currentline
End If
Set objKeywordFile = Nothing
Set objKeywordFile = objFSO.OpenTextFile("D:\variablefile.txt")
End Function
3/18/2008
Unattended installation of a single Office 2007 Language Pack (MUI)
1. Copy the MUI language pack sources into your office source folder (do not replace available items)
2. In the OMUI.XX-YY folder for the specific language customize the config.xml as listed below:

3. Install the Language with the following command, where the setup.exe is the original from the office 2007 source, not from the language pack.
\\server\office\setup.exe /config \\server\office\omui.xx-yy\config.xml
2. In the OMUI.XX-YY folder for the specific language customize the config.xml as listed below:
3. Install the Language with the following command, where the setup.exe is the original from the office 2007 source, not from the language pack.
\\server\office\setup.exe /config \\server\office\omui.xx-yy\config.xml
Subscribe to:
Posts (Atom)