Windows Script Host & Quick Fix Engineering - wsh

I want to get list of installed windows hotfix and updates. I use script below:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colQuickFixes = objWMIService.ExecQuery _
("Select * from Win32_QuickFixEngineering")
Set objDateTime = CreateObject("WbemScripting.SWbemDateTime")
For Each objQuickFix in colQuickFixes
Wscript.Echo "Computer: " & objQuickFix.CSName
Wscript.Echo "Description: " & objQuickFix.Description
Wscript.Echo "Hot Fix ID: " & objQuickFix.HotFixID
If Not (IsNull(objQuickFix.InstallDate) Or _
IsEmpty(objQuickFix.InstallDate)) Then
objDateTime.Value = objQuickFix.InstallDate
Wscript.Echo "Installation Date: " & objDateTime.GetFileTime
Else
WScript.Echo "Install Date Type: " &
TypeName(objQuickFix.InstallDate)
End If
Wscript.Echo "Installed By: " & objQuickFix.InstalledBy
Next
When I run this script I get Error message:
Syntax error
Error Code 800A03EA
What's wrong in this piece of code? Thanks!
Sorry if my English is not perfect.

You are missing the line continuation character (_) here:
''# -----------
''# |
''# \/
WScript.Echo "Install Date Type: " & _
TypeName(objQuickFix.InstallDate)
Either add it or put the code in a singe line:
WScript.Echo "Install Date Type: " & TypeName(objQuickFix.InstallDate)

Related

SSRS 2008 R2 Goto URL Action Mail to field

I have a goto url action in Reporting Services 2008 R2 tablix with the expression:
="mailto:" & ReportItems!Textbox17.Value &
"?subject=" & "Project" & Fields!ReferenceNo.Value & "&body=" & "Hi Guys!,"
The ReportItems!Textbox.17.Value doesn't seem to return the value for the To box in the email.
The ReportItems!Textbox17.Value is an expression of
=Join(
Lookupset(Fields!ReferenceNo.Value,
Fields!ReferenceNo.Value,Fields!Task_Owner.Value, "Alert_TaskOwners"),
";")
Is it possible to return this value for the "To:" field?
The "To" mail field should return such as:
"Name1; Name2; Name2"
it seems that this works by starting the expression with ="mailto://" & ReportItems!Textbox19.Value . . .
the lookup doesn't work but fetching the report item from the tablix with the lookup values in does!

Event filter with query could not be reactivated in namespace "//./root/CIMV2" because of error 0x80041003

In my SCVMM server, the following error is logged in events.
Event filter with query "SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA "Win32_Processor" AND TargetInstance.LoadPercentage > 99" could not be reactivated in namespace "//./root/CIMV2" because of error 0x80041003. Events cannot be delivered through this filter until the problem is corrected.
How to resolve it?
Try this workaround from Microsoft. It's actually a good one, and comes with a "real" explanation of the problem.
http://support.microsoft.com/kb/2545227 (For Win7 and Server 2008 R2)
http://support.microsoft.com/kb/950375 (For Vista and Server 2008)
In summary, this is a leftover WMI registration from the ISO creation process that can be safely removed.
For Windows 7, make a .vbs file with the following and execute it from an elevated command prompt:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\subscription")
Set obj1 = objWMIService.ExecQuery("select * from __eventfilter where name='BVTFilter' and query='SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA ""Win32_Processor"" AND TargetInstance.LoadPercentage > 99'")
For Each obj1elem in obj1
set obj2set = obj1elem.Associators_("__FilterToConsumerBinding")
set obj3set = obj1elem.References_("__FilterToConsumerBinding")
For each obj2 in obj2set
WScript.echo "Deleting the object"
WScript.echo obj2.GetObjectText_
obj2.Delete_
next
For each obj3 in obj3set
WScript.echo "Deleting the object"
WScript.echo obj3.GetObjectText_
obj3.Delete_
next
WScript.echo "Deleting the object"
WScript.echo obj1elem.GetObjectText_
obj1elem.Delete_
Next

Visual Basic 6: error 91 and 13 when executing a stored procedure

I'm new to Visual Basic 6 and I'm trying to execute an stored procedure and get the result into a text field variable.
The code below shows this error: error 91
"Object variable or With block variable not set" runtime error
Dim auxInfo As rdoResultset
Dim Cone As ADODB.Connection
SQL = "EXEC [mybase].[dbo].[myStoredProcedure] '" & var1 & "', '" & var2 & "','" & var3 & "'"
Set auxInfo = Cone.Execute(SQL)
myTextField.Text = Trim(auxInfo("fistColumn"))
auxInfo.Close
And if I change the following:
Set auxInfo = Cone.Execute(SQL)
into
Set auxInfo = UAN.OpenResultset(SQL, rdOpenDynamic, rdConcurValues, 0)
'with UAN I call the funcion that connects to my database. The connection works, I've tested it.
I get a new error: error 13 type mismatch
Could please tell what am I doing wrong?
Thanks!!
As the error says, You've not actually set Cone to anything.
You're missing the Set Cone = New ADODB.Connection.

Executing a SQL stored procedure with parameters in VBA

I'm fairly new to this. I'm trying to write a procedure in VBA that executes a stored procedure from excel and returns the record set. It currently returns the results of the stored procedure in spreadsheet 2 but I've had to hard code the parameter into the SQL code. Here is what I have pinched from other online forums.
Option Explicit
Public Sub OpenConnection()
'Set the variables
Dim conn As ADODB.Connection
Dim str As String
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Dim fld
Dim i As Integer
'Error handler
On Error GoTo errlbl
'Open database connection
Set conn = New ADODB.Connection
'First, construct the connection string.
'ODBC CONNECTION YOU'VE ALREADY SET UP:
conn.ConnectionString = "DSN=PC_Tool_Coding"
conn.Open 'Here's where the connection is opened.
Debug.Print conn.ConnectionString 'This can be very handy to help debug!
'Recordset
Set rs = New ADODB.Recordset
str = "exec Select_account_info"
'recordset is opened here
rs.Open str, conn, adOpenStatic, adLockReadOnly
If Not IsEmptyRecordset(rs) Then
rs.MoveFirst
'Populate the first row of the sheet with recordset’s field names
i = 0
For Each fld In rs.Fields
Sheet2.Cells(1, i + 1).Value = rs.Fields.Item(i).Name
i = i + 1
Next fld
'Populate the sheet with the data from the recordset
Sheet2.Range("A2").CopyFromRecordset rs
Else
MsgBox "Unable to open recordset, or unable to connect to database.", _
vbCritical, "Can't get requested records"
End If
'Cleanup
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
exitlbl:
Debug.Print "Error: " & Err.Number
If Err.Number = 0 Then
MsgBox "Done", vbOKOnly, "All Done."
End If
Exit Sub
errlbl:
MsgBox "Error #: " & Err.Number & ", Description: " & Err.Description, vbCritical, "Error in OpenConnection()"
Exit Sub
'Resume exitlbl
End Sub
I've looked around on how to get it to work with parameters and I just can't seem to get there. The parameter I'll be using is called #accgrpnum in SQL. Its a 12 letter string.
Many thanks to any help in advance.
Take a look at bonCodigo's link or
I've also been able to do this (with SQL Server 2008) by sending more than one statement, but separated in a SQL statement like
str = "SET #accgrpnum = 'my_account'; exec Select_account_info;"

VBS script to parse a csv, get data and move AD object

I am quite new in vbs and I would like some of your help on this script.
Basically I need a script that will get my current computername, look into a csv file to get the new related computername and then use that new name to move the corresponding account in the AD to a new OU.
I already know how to get my current computername and how to move an object to a new OU, these are things I have already done, but I am really not confident about parsing the csv looking for the new computername based on my current one.
The new name is the value just after the current name in the csv file. Only separted by a coma.
Edit 1
I tried your solution but as stated in the comments I think there are some things that I don't get. I might misuse the recordset or do not know how to retrieve the information from it. Here is my full script so you can see what I am doing:
'Get the old/current computername
Set wshShell = WScript.CreateObject( "WScript.Shell" )
OldComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
'Parse the xml file to get the related new computername
Dim CONNECTION : Set CONNECTION = CreateObject("ADODB.CONNECTION")
Dim RECORDSET : Set RECORDSET = CreateObject("ADODB.RECORDSET")
CONNECTION.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test\;Extended Properties=""text;HDR=YES;FMT=Delimited"""
RECORDSET.Open "SELECT NewComputerName FROM ComputerList.csv WHERE ComputerName = '& OldComputerName'", CONNECTION, 3, 3
'Move the new computername in the target AD to a new OU
Dim NewComputerName
Dim OldLocation
NewComputerName = RECORDSET
OldLocation = "LDAP://CN=" & NewComputerName & ",OU=Staging,OU=Workstations,DC=contoso,DC=lab"
Set objNewOU = GetObject("LDAP://OU=Migration,OU=Workstations,DC=contoso,DC=lab")
Set objMoveComputer = objNewOU.MoveHere(OldLocation, vbNullString)
' It does not work as it said Error: Wrong number of arguments or invalid property assignment pour la ligne:
' OldLocation = "LDAP://CN=" & NewComputerName & ",OU=Staging,OU=Workstations,DC=contoso,DC=lab"
Thanks a lot for your help ! :)
You can use ADO to read CSV (and other delimited) files. The gory details are discussed in this article. Sample code for reading a simple CSV file using VBScript is as follows:
Note: the CSV file needs a header line in order for ADO to use column names:
ComputerName,NewComputerName
Computer #1,Other Computer #1
Computer #2,Other Computer #2
Computer #3,Other Computer #3
VBScript Code:
option explicit
dim CONNECTION : set CONNECTION = CreateObject("ADODB.CONNECTION")
dim RECORDSET : set RECORDSET = CreateObject("ADODB.RECORDSET")
CONNECTION.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Folder\Containing\CSV\File\;Extended Properties=""text;HDR=YES;FMT=Delimited"""
RECORDSET.Open "SELECT * FROM data.csv WHERE ComputerName = '" & OldComputerName & "'", CONNECTION, 3, 3
' //// For testing \\\\
WScript.Echo RECORDSET.Source
' \\\\ For testing ////
if RECORDSET.EOF then
WScript.Echo "Record not found"
WScript.Quit
else
dim NewComputerName : NewComputerName = RECORDSET("NewComputerName") & ""
WScript.Echo NewComputerName
end if
Note that this code might not work on 64-bit OS -- not directly. You must run 32-bit version of CScript/WScript like so:
%windir%\SysWoW64\cscript c:\Path\To\test.vbs
Ok the script works perfectly now thanks to your modifications ! :)
But I've got one more trouble, it seems that I cannot open the csv file in the FROM clause when this file have - in the name.
Like : CONTOSO-US-ComputerList.csv I get the error Syntax error in FROM clause
But when I use a file name without dashes there is no problem.
I know it is a detail but I have no choice than having a file with dashes in the name :/
Thanks again for your help :) Very much appreciated !!
EDIT:
Nevermind I found the solution thanks to the scriptingguys !
The request now looks like this:
strFile = "[CONTOSO-ComputerList.csv]"
RECORDSET.Open "SELECT * FROM " & strFile & " WHERE ComputerName = '" & OldComputerName & "'", CONNECTION, 3, 3

Resources