I have to write a file to change the IP settings to Static with an input for the static IP.
It isn't very hard to write a file that does this(trough BATCH or VBS) but the problem is the name of the connection, standard windows is Local Area Connection, but it has to work with every connection, even if i(for example) rename my connection to test. Also some people have 2 or more connections, and only the standard one should be changed and every other should be disabled(WIFI, Hamachi, etc). It is going to be used on a LAN-Party to quickly change everybody's IP adresses to the given ones(there has to be some kind of input), instead of the manual job(takes to much time with 200+ people).
Can you guys give me some tips/ examples?
Thanks in Advance,
Bart
I wrote this a while ago for a similar purpose.
Its a bit laborious but basically it asks the user which Network connection to modify, then asks them if they want to turn on DHCP, or type a manual IP address. I imagine that the logged in user would need administrative rights to change this
Option Explicit
Const SCRIPT_NAME = "Set IP"
Const SUBNET_MASK = "255.255.255.0"
Dim objWMI
Dim arrNANames
Dim colNa, objNa
Dim colNAConfig, objNAConfig
Dim strIP
Dim intIPRet
Dim intCount, strSelectString, intSelected
Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
Set colNA = objWMI.ExecQuery("select * from Win32_NetworkAdapter")
ReDim arrNANames(colNA.Count)
intCount = 0
strSelectString = "Select a network adapter to modify:" & vbCrLf
For Each objNa In colNa
arrNANames(intCount) = objNA.Name
strSelectString = strSelectString & intCount & ") " & arrNANames(intCount) & vbCrLf
intCount = intCount + 1
Next
Do
intSelected = inputbox(strSelectString, SCRIPT_NAME)
If intSelected = "" Or Not IsNumeric(intSelected) Then
quitScript
End If
Loop Until CInt(intSelected) < UBound(arrNANames) And CInt(intSelected) > -1
Set colNA = objWMI.ExecQuery("select * from Win32_NetworkAdapter where Name='" & arrNANames(intSelected) & "'")
For Each objNA In colNA
Set colNAConfig = objWMI.ExecQuery("ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID='" & objNA.DeviceID & "'} WHERE resultClass = win32_NetworkAdapterConfiguration ")
For Each objNAConfig In colNAConfig
If MsgBox("Do you want to enable automatic IP (DHCP/APIPA) for device " & chr(34) & objNa.Name & chr(34), vbQuestion+vbYesNo, SCRIPT_NAME) = vbYes Then
intIPRet = objNAConfig.EnableDHCP
Select Case intIPRet
Case 0 MsgBox "DHCP enabled successfully", vbInformation, SCRIPT_NAME
Case 1 MsgBox "DHCP enabled successfully" & vbCrLf & "Please reboot for changes to take effect", vbInformation, SCRIPT_NAME
Case Else MsgBox "Could not enable DHCP", vbCritical, SCRIPT_NAME
End Select
Else
Do
strIP = inputbox("Type an IP for network adapter: " & objNA.Name, SCRIPT_NAME)
If strIP = "" Then
quitScript
End If
Loop Until isValidIP(strIP)
intIPRet = objNAConfig.EnableStatic(Array(strIP),Array(SUBNET_MASK))
Select Case intIPRet
Case 0 MsgBox "IP changed to " & strIP, vbInformation, SCRIPT_NAME
Case 1 MsgBox "IP changed to " & strIP & vbCrLf & "Please reboot for changes to take effect", vbInformation, SCRIPT_NAME
Case Else MsgBox "Could not change IP", vbCritical, SCRIPT_NAME
End Select
End If
Next
Next
quitScript
'returns true if the parameter is a valid IP address
Function isValidIP(ip)
Dim arrNums, intNum
arrNums = Split(ip, ".")
If UBound(arrNums) <> 3 Then
isValidIP = False
Exit Function
End If
For Each intNum In arrNums
If Not IsNumeric(intNum) Then
isValidIP = False
Exit Function
End If
If intNum < 0 Or intNum > 255 Then
isValidIP = False
Exit Function
End If
If Len(intNum) > 1 And Left(intNum,1) = "0" Then
isValidIP = False
Exit Function
End If
Next
isValidIP = True
End Function
Sub quitScript
Set objWMI = Nothing
Set colNa = Nothing
WScript.Quit
End Sub
Related
I have an Access database to report on event statistics gathered from a mainframe system. The mainframe scheduler (ZEKE) doesn't have robust reporting features, so I export daily event data to report on.
A master listing from a separate source (a static list that will not change on a regular basis) lists the individual applications, including the application code (which is the naming standard for production runs) and the name of the programmer, coordinator, manager, business unit, etc. for that application.
The user can search by any field, application code, programmer, coordinator, etc.
Choose the production center to search in (there are 5) or default to all, and choose all dates, a single date, or a date range.
The query takes the search parameters and starting with either the application code, or the person, searches the table for applications and copies records to a temp table for reporting.
For example, to see how many failures the application coordinator John Doe had for the past week for all of the applications he is responsible for, the query would move all application records listing John Doe as the coordinator to the temp table.
From there, it moves through the temp table for each application and searches the event data for events under that application code which meet the criteria entered for date, production center and event type (success, failure or both).
This is moved to a temp table for the final report.
The table for event data is currently 2.5 million lines (this is 15 days worth of data) and is growing daily.
I put the back end onto a newly created NAS drive on our network.
A report that took two minutes when the back end and front end were on the same machine now takes 29 minutes.
Any suggestions to streamline the queries over a network?
Code which is run from the report criteria selection form and runs the report.
'this macro will generate a report based on multiple input criteria.
'this report allows the user to slect:
' date range, single date or all dates
' type of events: Abends, Successes or both
' centers to pull data from: OCC,QCC,BCC,ITS,DAIN, or ALL centers
' The type of data to report on: App code, App Coordinator, Custodian, L3, L4 or L5
'Once the user has selected all of the required data and fields, the report will be generated
'based on the selection criteria.
'we begin by defining the active database as the currently open database
Dim db As DAO.Database
Set db = DBEngine(0)(0)
On Error GoTo ErrorHandler
'Now we designate the variables which will be used in this macro
Dim strSQ1 As String
Dim strSQ2 As String
Dim strSQ3 As String
Dim strSQ4 As String
Dim appl As String
Dim evstatus As String
Dim appletype As String
Dim fullapp As String
Dim length As Long
Dim iipmname As String
Dim iipmcoor As String
Dim fullappnm As String
Dim fullappcoor As String
Dim kinddate As String
Dim coor As String
Dim cust As String
Dim appL3 As String
Dim appL4 As String
Dim appL5 As String
Dim ctrOCC As String
Dim ctrMTL As String
Dim ctrBCC As String
Dim ctrITS As String
Dim ctrDAIN As String
'We will start by setting some default values
'We will ste the default values for center selection.
'We start by searching for terms we know are not there, then change them to
'valid search terms if the center is selected.
ctrOCC = "notOCC"
ctrMTL = "notMTL"
ctrBCC = "notBCC"
ctrITS = "notITS"
ctrDAIN = "notUSWM"
fullapp = "*"
'First we determine which event types the user wants to look for
state = Me![opt-status].Value
If state = 1 Then
evstatus = " [ev-status] = 'AEOJ'"
ElseIf state = 2 Then
evstatus = " [ev-status] = 'EOJ'"
ElseIf state = 3 Then
evstatus = " ([ev-status] = 'EOJ' OR [ev-status] = 'AEOJ')"
End If
'MsgBox "Event status pulled is:.. " & evstatus & "."
' Next up we will configure the date parameters based on the user input
If [grp-datesel] = 1 Then
Sdte = "1"
Edte = "9999999"
kinddate = "[ev-date] >= " & Sdte & " AND [ev-date] <= " & Edte & " "
End If
If [grp-datesel] = 2 Then
'error handling
If IsNull(Me.[sel-onedate]) Then
MsgBox "You have not entered a date to search....please try again."
Me.[sel-onedate] = Null
Me.[sel-onedate].SetFocus
Exit Sub
End If
'end of error handling
Dim currdte As Date
currdte = Me![sel-onedate].Value
currjul = Format(currdte, "yyyyy")
daycurr = CDbl(currjul)
Sdte = daycurr
Edte = daycurr
kinddate = "[ev-date] >= " & Sdte & " AND [ev-date] <= " & Edte & " "
End If
If [grp-datesel] = 3 Then
'error handling
If IsNull(Me.[sel-Sdate]) Or IsNull(Me.[sel-Edate]) Then
MsgBox "You Must enter a start and end date for the search....please try again."
Me.[sel-Sdate] = Null
Me.[sel-Edate] = Null
Me.[sel-Sdate].SetFocus
Exit Sub
End If
'end of error handling
Dim startdte As Date
Dim enddte As Date
startdte = Me.[sel-Sdate].Value
enddte = Me.[sel-Edate].Value
startjul = Format(startdte, "yyyyy")
endjul = Format(enddte, "yyyyy")
Sday = CDbl(startjul)
Eday = CDbl(endjul)
Sdte = Sday
Edte = Eday
'MsgBox "start date is " & Sdte & " and end date is " & Edte & "."
'check that dates are in proper chronological order
If Sdte > Edte Then
MsgBox "The start Date you entered is after the end date....please try again."
Me.[sel-Sdate] = Null
Me.[sel-Edate] = Null
Me.[sel-Sdate].SetFocus
Exit Sub
End If
'keep going if it's all good
kinddate = "[ev-date] >= " & Sdte & " AND [ev-date] <= " & Edte & " "
End If
MsgBox "Date used is:.. " & kinddate & "."
'Now lets look at center selection
If [chk-allctr].Value = True Then
ctrOCC = "OCC"
ctrMTL = "MTL"
ctrBCC = "BCC"
ctrITS = "ITS"
ctrDAIN = "USWM"
End If
If [chk-OCC].Value = True Then
ctrOCC = "OCC"
End If
If [chk-MTL].Value = True Then
ctrMTL = "MTL"
End If
If [chk-BCC].Value = True Then
ctrBCC = "BCC"
End If
If [chk-RTF].Value = True Then
ctrITS = "ITS"
End If
If [chk-DAIN].Value = True Then
ctrDAIN = "DAIN"
End If
'Error handling if no center is selected
If [chk-OCC].Value = Flase Then
If [chk-MTL].Value = Flase Then
If [chk-BCC].Value = Flase Then
If [chk-RTF].Value = Flase Then
If [chk-DAIN].Value = Flase Then
MsgBox "You have not selected a center to search search....please try again."
Me.[chk-allctr].SetFocus
Exit Sub
End If
End If
End If
End If
End If
'end of error handling
'MsgBox "centers used are: Chr(10) " & ctrOCC & " Chr(10) " & ctrBCC & " Chr(10) " & ctrMTL & " Chr(10) " & ctrITS & " Chr(10) " & ctrDAIN & " For this run"
'All good so far, now we will parse the application code if an
'application code report is selected
appl = "*"
If [opt-criteria].Value = 1 Then
'error handling
If IsNull(Me.[sel-appcode]) Then
MsgBox "You have not entered an application code to search....please try again."
Me.[sel-appcode] = Null
Me.[sel-appcode].SetFocus
Exit Sub
End If
'end of error handling
End If
If [opt-criteria].Value = 1 Then
appl = Me![sel-appcode].Value
End If
'trust = "no"
'If Mid(appl, 3, 2) = "RT" Then trust = "yes"
'length = Len(appl)
'If length = 2 Then appltype = "short"
'If length = 3 Then appltype = "long"
'If appltype = "short" Then fullapp = "" & appl & "00"
'If appltype = "long" Then fullapp = "" & appl & "0"
'If trust = "yes" Then fullapp = appl
'End If
fullapp = appl
'MsgBox "App to use is: " & appl & " fullapp code is " & fullapp & "."
'Now we set values if names are used
coor = "*"
cust = "*"
appL3 = "*"
appL4 = "*"
appL5 = "*"
If [opt-criteria].Value = 2 Then
'error handling
If IsNull(Me.[sel-coor]) Then
MsgBox "You have not entered a Coordinator to search....please try again."
Me.[sel-coor] = Null
Me.[sel-coor].SetFocus
Exit Sub
End If
'end of error handling
coor = Me![sel-coor].Value
'MsgBox "Coordinator report selected for: " & coor & "."
End If
If [opt-criteria].Value = 3 Then
'error handling
If IsNull(Me.[sel-custodian]) Then
MsgBox "You have not entered a Custodian to search....please try again."
Me.[sel-custodian] = Null
Me.[sel-custodian].SetFocus
Exit Sub
End If
'end of error handling
cust = Me![sel-custodian].Value
'MsgBox "Custodian report selected for: " & cust & "."
End If
If [opt-criteria].Value = 4 Then
'error handling
If IsNull(Me.[sel-L3]) Then
MsgBox "You have not entered an L3 to search....please try again."
Me.[sel-L3] = Null
Me.[sel-L3].SetFocus
Exit Sub
End If
'end of error handling
appL3 = Me![sel-L3].Value
'MsgBox "L3 report selected for: " & appL3 & "."
End If
If [opt-criteria].Value = 5 Then
'error handling
If IsNull(Me.[sel-L4]) Then
MsgBox "You have not entered an L4 to search....please try again."
Me.[sel-L4] = Null
Me.[sel-L4].SetFocus
Exit Sub
End If
'end of error handling
appL4 = Me![sel-L4].Value
'MsgBox "L4 report selected for: " & appL4 & "."
End If
If [opt-criteria].Value = 6 Then
'error handling
If IsNull(Me.[sel-L5]) Then
MsgBox "You have not entered an L5 to search....please try again."
Me.[sel-L5] = Null
Me.[sel-L5].SetFocus
Exit Sub
End If
'end of error handling
appL5 = Me![sel-L5].Value
'MsgBox "L5 report selected for: " & appL5 & "."
End If
'Most of these reports take a while to build with this macro, so to make sure the user
'knows that the macro is still working, we didsplay a splash screen. It's cute and has
'hamsters, cause everyone loves hamsters.
DoCmd.OpenForm "PlsWaitFrm", acWindowNormal
[Forms]![PlsWaitFrm].Repaint
'All of out criteria values are now selected. We can move on to pulling data from the tables.
'We start by populating the IIPM table with the information that we require for applications.
strSQ1 = "DELETE * from [tbl-RPT-IIPM] "
db.Execute strSQ1
strSQ2 = "INSERT INTO [tbl-RPT-IIPM] " & _
"SELECT * FROM [tbl-IIPM] " & _
"WHERE (([AppCode] like '" & fullapp & "')" & _
"AND ([AppCoordinator] like '" & coor & "') " & _
"AND ([AppCustodian] like '" & cust & "') " & _
"AND ([L3] like '" & appL3 & "') " & _
"AND ([L4] like '" & appL4 & "') " & _
"AND ([L5] like '" & appL5 & "')) "
db.Execute strSQ2
'MsgBox "made it past the populate of rpt-iipm"
'Now we have populated the IIPM report table, it's time to populate the event report table.
'We will loop through all fields in the IIPM report table and pull information for each
'application code.
strSQ3 = "DELETE * from [tbl-EVENTREPORT] "
db.Execute strSQ3
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl-RPT-IIPM") 'this opens the IIPM report table just populated
'populate the table
rs.MoveLast
rs.MoveFirst
Do While Not rs.EOF
'we will execute these action against the selected record.
'first step - parse the application code to display the full application code
appl = rs![AppCode].Value
length = Len(appl)
If length = 1 Then appl = "" & appl & "00"
rptdelin = Mid(appl, 3, 1)
rptcode = Mid(appl, 1, 3)
If rptdelin = "0" Then rptcode = Mid(appl, 1, 2)
If rptdelin = "R" Then rptcode = "RT" & Mid(appl, 1, 2) & ""
'MsgBox "searching for: " & rptcode & "."
applist = applist & "," & appl
strSQ4 = "INSERT INTO [tbl-EVENTREPORT] " & _
"SELECT * FROM [tbl-EVENT DATA] " & _
"WHERE (([ev-jobname] LIKE '?" & rptcode & "*') " & _
"AND (([ev-ctr] = '" & ctrOCC & "')" & _
"OR ([ev-ctr] = '" & ctrMTL & "')" & _
"OR ([ev-ctr] = '" & ctrBCC & "')" & _
"OR ([ev-ctr] = '" & ctrITS & "')" & _
"OR ([ev-ctr] = '" & ctrDAIN & "'))" & _
"AND (" & kinddate & ") " & _
"AND " & evstatus & ")"
db.Execute strSQ4
'now we're done with this report, we move on to the next
rs.MoveNext 'press Ctrl+G to see debuG window beneath
Loop
'END OF LOOPING CODE
'MsgBox "made it past the looping"
'Now we have completed populating the table that the report will be based on.
'Next step is to gather master statistics to produce abend and success percentages.
totfail = DCount("[ev-status]", "tbl-EVENTREPORT", "[ev-status] = 'AEOJ'")
totsucc = DCount("[ev-status]", "tbl-EVENTREPORT", "[ev-status] = 'EOJ'")
Dim allabend As Long
Dim allsucc As Long
allabend = DCount("[ev-status]", "[tbl-EVENT DATA]", "[ev-status] = 'AEOJ' AND ([ev-date] >= " & Sdte & " AND [ev-date] <= " & Edte & ")")
allsucc = DCount("[ev-status]", "[tbl-EVENT DATA]", "[ev-status] = 'EOJ' AND ([ev-date] >= " & Sdte & " AND [ev-date] <= " & Edte & ")")
Dim pctabend As Long
Dim pctsucc As Long
pctabend = (totfail / allabend) * 100
pctsucc = (totsucc / allsucc) * 100
'Now we will generate the reports for display based on what type of report was selected
'by the user in the initial form.
'Before we open the report, we will close the splash screen
DoCmd.Close acForm, "PlsWaitFrm", acSaveNo
'Now we open the report
If [opt-criteria].Value = 1 Then
fullappnm = DLookup("AppName", "tbl-RPT-IIPM", "AppCode = '" & fullapp & "' ")
fullappcoor = DLookup("AppCoordinator", "tbl-RPT-IIPM", "AppCode = '" & fullapp & "' ")
DoCmd.OpenReport "rpt-APPLREPORT", acViewReport
[Reports]![rpt-APPLREPORT]![rpt-appcode].Value = fullapp
[Reports]![rpt-APPLREPORT]![rpt-appname].Value = fullappnm
[Reports]![rpt-APPLREPORT]![rpt-appcoor].Value = fullappcoor
[Reports]![rpt-APPLREPORT]![rpt-abendtot].Value = totfail
[Reports]![rpt-APPLREPORT]![rpt-succtot].Value = totsucc
[Reports]![rpt-APPLREPORT]![rpt-abdpct].Value = pctabend
[Reports]![rpt-APPLREPORT]![rpt-succpct].Value = pctsucc
End If
If [opt-criteria].Value = 2 Then
DoCmd.OpenReport "rpt-COORREPORT", acViewReport
[Reports]![rpt-COORREPORT]![rpt-appcode].Value = applist
[Reports]![rpt-COORREPORT]![rpt-appcoor].Value = coor
[Reports]![rpt-COORREPORT]![rpt-abendtot].Value = totfail
[Reports]![rpt-COORREPORT]![rpt-succtot].Value = totsucc
[Reports]![rpt-COORREPORT]![rpt-abdpct].Value = pctabend
[Reports]![rpt-COORREPORT]![rpt-succpct].Value = pctsucc
End If
If [opt-criteria].Value = 3 Then
DoCmd.OpenReport "rpt-CUSTREPORT", acViewReport
[Reports]![rpt-CUSTREPORT]![rpt-appcode].Value = applist
[Reports]![rpt-CUSTREPORT]![rpt-appcoor].Value = cust
[Reports]![rpt-CUSTREPORT]![rpt-abendtot].Value = totfail
[Reports]![rpt-CUSTREPORT]![rpt-succtot].Value = totsucc
[Reports]![rpt-CUSTREPORT]![rpt-abdpct].Value = pctabend
[Reports]![rpt-CUSTREPORT]![rpt-succpct].Value = pctsucc
End If
If [opt-criteria].Value = 4 Then
DoCmd.OpenReport "rpt-L3REPORT", acViewReport
[Reports]![rpt-L3REPORT]![rpt-appcode].Value = applist
[Reports]![rpt-L3REPORT]![rpt-appcoor].Value = appL3
[Reports]![rpt-L3REPORT]![rpt-abendtot].Value = totfail
[Reports]![rpt-L3REPORT]![rpt-succtot].Value = totsucc
[Reports]![rpt-L3REPORT]![rpt-abdpct].Value = pctabend
[Reports]![rpt-L3REPORT]![rpt-succpct].Value = pctsucc
End If
If [opt-criteria].Value = 5 Then
DoCmd.OpenReport "rpt-L4REPORT", acViewReport
[Reports]![rpt-L4REPORT]![rpt-appcode].Value = applist
[Reports]![rpt-L4REPORT]![rpt-appcoor].Value = appL4
[Reports]![rpt-L4REPORT]![rpt-abendtot].Value = totfail
[Reports]![rpt-L4REPORT]![rpt-succtot].Value = totsucc
[Reports]![rpt-L4REPORT]![rpt-abdpct].Value = pctabend
[Reports]![rpt-L4REPORT]![rpt-succpct].Value = pctsucc
End If
If [opt-criteria].Value = 6 Then
DoCmd.OpenReport "rpt-L5REPORT", acViewReport
[Reports]![rpt-L5REPORT]![rpt-appcode].Value = applist
[Reports]![rpt-L5REPORT]![rpt-appcoor].Value = appL5
[Reports]![rpt-L5REPORT]![rpt-abendtot].Value = totfail
[Reports]![rpt-L5REPORT]![rpt-succtot].Value = totsucc
[Reports]![rpt-L5REPORT]![rpt-abdpct].Value = pctabend
[Reports]![rpt-L5REPORT]![rpt-succpct].Value = pctsucc
End If
ErrorHandler:
If Err.Number = 7874 Then
Resume Next 'Tried to delete a non-existing table, resume
End If
End Sub
'''
Firstly, you need to work out where the bottlenecks are, so I would suggest putting some Debug.Print Now statements throughout the code to give you an idea of what is causing the issue.
I would guess that two of the processes that take most of the time are the DELETE/INSERT statements that you are doing.
I would suggest that rather than doing this, you look at normalizing your database, and then creating a query that provides the information that you need.
Also, by running the report directly from a query rather than a temporary table means that you don't have to worry about the deletes/inserts creating database bloat.
If you really insist on keeping this process, then consider deleting the table [tbl-RPT-IIPM] and then recreating it, rather than deleting the records. And consider removing the indexes before the insert, and then adding them back afterwards, as indexes splow down inserts, but obviously speed up searches and joins.
Also, when you are inserting data into [tbl-RPT-IIPM], you are using ([L3] like '" & appL3 & "'), which is the same as ([L3]='" & appL3 & "'), but slower.
When you are inserting data into [tbl-EVENTREPORT], you are doing it when looping through a recordset - it may be faster to use an INSERT SQL statement.
Regards,
OK, with some more information, some more answers that may (or may not!!) help. Again, you will need to run timing tests to see which works best for you.
Try adding a "Yes/No" field to the table [tbl-EVENT DATA]. You can then use an UPDATE statement to indicate which fields to include in the report, rather than using the slow INSERT query.
Another thing to try would be to replace the INSERT statement with several, each using a different value for [ev-ctr]. Or else rather than using OR try using IN:
strSQ4 = "INSERT INTO [tbl-EVENTREPORT] " & _
"SELECT * FROM [tbl-EVENT DATA] " & _
"WHERE [ev-jobname] LIKE '?" & rptcode & "*' " & _
"AND [ev-ctr] IN('" & ctrOCC & "','" & ctrMTL & "','" & ctrBCC & "','" & ctrITS & "','" & ctrDAIN & "')" & _
"AND " & kinddate & _
"AND " & evstatus
Also, I notice that kinddate is set to effectively include all dates in one instance, and that evstatus is set to include both "EOJ" and "AEOJ" in one instance. Rather than including these fields as criteria in these cases, you may wish to not include them at all:
If state = 1 Then
evstatus = " AND [ev-status] = 'AEOJ'"
ElseIf state = 2 Then
evstatus = " AND [ev-status] = 'EOJ'"
ElseIf state = 3 Then
evstatus = " "
End If
And then you would rewrite " AND " & evstatus to & evstatus in the SQL statement.
A final thing to look at is to actually run the INSERT directly in the backend, rather than operating on linked tables in the frontend, as Access will be dragging vast amounts of data across the network and then sending it back. As a basic guide, something like this:
Sub sUpdateQuery()
Dim objAccess As New Access.Application
objAccess.OpenCurrentDatabase "J:\downloads\test.accdb"
objAccess.DoCmd.RunSQL "UPDATE test2 SET Field1=UCASE(Field1);"
objAccess.CloseCurrentDatabase
Set objAccess = Nothing
End Sub
Regards,
Applecore, Firstly, let me thank you for your insights. Unfortunately due to the nature of the way the data is processed, some of them I'm not sure I can implement. I have used debug.print statements to get a better idea of the timing.
You are correct, the INSERT statement is causing me the most problems, and only the second one. The deletes fly through almost instantly, no issues there. It's the second insert from the event data that is slowing it down.
I have been thinking about this since inception of how to nromalize more efficiently and create better relationships, but I'm stymied. My issue is, the data between the event table and the event table are related "in the world" but in no clear way in terms of data. There is no way to determine the relationship without a complex calculation. For example, the unique part of the application data is the application code. They are always unique. A single Application coordinator can have dozens of codes assigned to them, as can custodians, L3,L4, etc. Each event is related to an application, however, there is no specific field that is exported that tells the application code, it is obtained by parsing the event name (And yes, that is as archaic as it sounds). The event naming standards are standard mainframe 8 character names: .
For example PGRD1234 - Production job, GRD application, 1234 as the designator. So to determine what application the job is related to, I take the application code, and select LIKE with wildcards. It's not 100% accurate I am well aware, but to use wildcards, I seem to be stuck using LIKE. I haven't been able to make '=' work with wildcards. Can you?
You also mentioned "When you are inserting data into [tbl-EVENTREPORT], you are doing it when looping through a recordset - it may be faster to use an INSERT SQL statement." which I'm not sure what you are saying.. My apologies. I don't think I am understanding it. I think that is what I am doing now. I use the IIPM table to obtain the listing of the application codes I need to pull, then loop through that recordset to pull all of the event data for only those applications. As there is no direct correlation between the data, I Can't think of another way to do it.
I'm working on some code that checks a database for a specific value and returns a string under certain conditions.
I cannot get this code to iterate to the next row in my database results. It appears that my code only checks the first record of the recordset and then continues.
Sometimes my recordset may only have one row, but sometimes it may have many rows. If any of the rows of this recordset have a certain value I want to throw a MsgBox. Not just the first or last record.
Here's my code:
'Database Connection Strings.
strServerName = "string"
strDatabase = "string"
strUserName = "string"
strPassword = "string"
'Connection string for SQL Server.
strConn = "Driver={SQL Server};Server=" & strServerName & ";Database=" & strDatabase & ";Uid=" & strUsername & ";Pwd=" & strPassword & ";"
'Create required objects for the session.
Set WShell = CreateObject("WScript.Shell")
Set db = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
'Create the array of reciever lines and count them.
Set arrayLine = LINES.Value
intNumOfLines = arrayLine.Count
intLineNum = Cint(intNumOfLines)-1
cleanPN2 = array()
skipArray = array("-", " ", "PLATE", "HEAT-TREAT", "PAINT", "MACHINE", "WELD", "MPI")
result = MsgBox ("Scan PO for cert requirements?", vbYesNo, "PO Requirement Scanner")
Select Case result
Case vbYes
'Iterate through the reciever lines and look for part numbers.
For intLineNum = 0 To intNumOfLines
If intLineNum = intNumOfLines Then
Exit For
End If
Set arrayLine = LINES(intLineNum).Value
strPN = arrayLine("VENDOR_PART_ID")
cleanPN = split(strPN, " ")
For Each iteration in cleanPN
iteration = LTrim(RTrim(iteration))
ReDim Preserve cleanPN2(UBound(cleanPN2) + 1)
cleanPN2(UBound(cleanPN2)) = iteration
Next
Next
'Take any part numbers that were found and search the WO Master for operations that require certs.
For Each cleanPN3 In cleanPN2
strSQL = "SELECT USER_3 FROM OPERATION WHERE WORKORDER_BASE_ID = " & "'" & cleanPN3 & "';"
db.Open strConn, db
rs.Open strSQL, db
If Not rs.EOF And Not rs.BOF Then
strUSER3 = rs("USER_3")
Do While rs("USER_3") = Null
strUSER3 = rs("USER_3").MoveNext
Loop
If (strUSER3 <> Null) Or (strUSER3 <> "") Then
MsgBox "Certifications are required for part number " & cleanPN3 & "!", vbOKOnly
End If
End If
rs.Close
db.Close
Next
MsgBox "PO Scan Complete!"
Case vbNo
MsgBox("PO Scan Cancelled!")
End Select
Assuming everything else is working as you wish
rs.Open strSQL, db
If Not rs.BOF Then
rs.MoveFirst
Do While Not rs.EOF
If Len(Trim(Cstr(rs.fields("USER_3").value)) > 0 Then
MsgBox "Certifications are required for part number " & cleanPN3 & "!", vbOKOnly
End If
rs.MoveNext
Loop
End If
rs.Close
Apologies for the shabby formatting...
The following script refers to a simple single-line csv text file on my root directory containing server-name, username and password strings. I appreciate that it is probably the most inelegant, convoluted and inefficient piece of .vbs you've ever seen, but please bear with me, I'm learning. :P The script runs fine and performs all but one operation as expected. When the very last "elseif" statement is encountered it abruptly ends, no messagebox, nothing... I can't fathom how to get the array and iteration to cofunction... Please afford me your time, kindness and assistance, I will be immeasurably grateful.
dim objfso, objinputfile, filepath, searchstr, tmpstr, result, arr(2)
result = msgbox ("Please select" & vbCrLf & " " & vbCrLf & "Yes = Save password" & vbCrLf & "No = Load password ", vbyesnocancel, "Password Manager")
select case result
case vbyes
dim server, user, pass
set fso = createobject("scripting.filesystemobject")
do
server = inputbox ("Please enter server name", "Password manager")
if server = "" then
wscript.quit ()
end if
loop until server <> ""
do
user = inputbox ("Please enter username", "Password manager")
if user = "" then
wscript.quit ()
end if
loop until user <> ""
do
pass = inputbox ("Please enter password", "Password manager")
if pass = "" then
wscript.quit ()
end if
loop until pass <> ""
set file = fso.opentextfile("C:\passwords.txt",8,true)
file.write server & ", " & user & ", " & pass & ", "
file.close
msgbox "Entry added to C:\password.txt"
case vbno
set objfso = createobject("scripting.filesystemobject")
filepath = "C:\passwords.txt"
call SEARCH
sub SEARCH
if objfso.fileexists(filepath) then
do
searchstr = inputbox ("Please enter server name", "Password manager")
if searchstr = "" then
wscript.quit ()
end if
loop until searchstr <> ""
set objinputfile = objfso.opentextfile(filepath)
tmpstr = objinputfile.readline
if instr(lcase(tmpstr),lcase(searchstr)) <= 0 then
result = msgbox ("No matches", vbretrycancel, "Password Manager")
if result = 4 then
call SEARCH
elseif result = 2 then
wscript.quit ()
end if
elseif instr(lcase(tempstr),lcase(searchstr)) > 0 then
for i = 1 to 3
arr(i)
result = msgbox ("Match found" & vbCrLf & " " & vbCrLf & "Username = " & arr(0) & vbCrLf & "Password = " & arr(1), vbretrycancel, "Password Manager")
next
end if
else
result = msgbox ("C:\passwords.txt does not exist", vbokonly, "Password Manager")
end if
end sub
case vbcancel
wscript.quit ()
end select
You should get solution using option explicit statement to force explicit declaration of variables. In that last elseif I see a variable tempstr with no value assignment (should be tmpstr?).
Using proper indentation could help as well.
However, in your next construction:
if xx <= 0 then
' ...
elseif xx > 0 then
' here xx <= 0 is not valid thus always xx > 0 holds
' ...
end if
that elseif is redundant and harmful. Rather, use
if xx <= 0 then
' ...
else
' ...
end if
Another example:
result = msgbox ("No matches", vbretrycancel, "Password Manager")
if result = 4 then
call SEARCH
elseif result = 2 then
wscript.quit ()
else
'''''''''''''''''''''''''''''''''''
' else missing or elseif redundant?
'''''''''''''''''''''''''''''''''''
end if
Last not least: I'd recommend next simple script structure:
' VB Script Document
Option Explicit
On Error Goto 0
' declarations: variables declared by DIM at the script level are available
' to all procedures within the script
Dim arrNames(9) ' Declare an array with 10 elements
Dim dynNames() ' Declare a dynamic array
Dim strMyVar, intMyNum ' Declare two variables
'script code: statements, procedure calls
Wscript.Quit
' declarations: Function and Sub procedures
Sub example
' declarations: variables declared by DIM at the procedure level
' are available only within the procedure
' procedure code: statements, procedure calls
End Sub 'example
' declarations: constants for use in place of literal values
' various useful constants, e.g.
Const ForReading = 1 _
, ForWriting = 2 _
, ForAppending = 8
Const RabbitEars = """"
Const OpenAsDefault = -2 ' Opens the file using the system default.
Const OpenAsUnicode = -1 ' Opens the file as Unicode.
Const OpenAsUSAscii = 0 ' Opens the file as ASCII.
Const NoCreateFileIfNotExist = False
Const DoCreateFileIfNotExist = True
Your script is a complete mess (Sub definition intermixed with top level code); if you want to learn something, read a book about structured programming and start with something a bit more complicated than HelloWorld but much less ambicious that your program.
You don't use Option Explicit. That is why your elseif instr(lcase(tempstr),lcase(searchstr)) > 0 then fails: tmpstr <> tempstr.
The statement arr(i) looks like a stupid call of a Sub arr with a by value parameter i. As there is no such Sub, you'll get a Type Mismatch error on that line.
Instead of file.write server & ", " & user & ", " & pass & ", " you should use .WriteLine (to get a file of lines). The separator should be "," to adhere to the CSV standard.
You can use Split() on .ReadLine() to get your data back. That would give you an array of 3 elements. Those can be looked at - arr(0) = server/searchstr - and displayed - WScript.Echo/MsgBox Join(arr, ",").
Finally, after immense toil (trial, error, and lots of reading and learning in-between) I've managed to create a working script, it may not be elegant or efficient, but it works, and I understand it. As I learn more about vbs I will no doubt revisit this script, and perhaps even improve on it... I thought it maybe important to also include this link, where another friendly, critically constructive gentleman gave me useful pointers... https://social.technet.microsoft.com/Forums/scriptcenter/en-US/8aae30ac-0972-43dd-88fb-7d811d9b9a73#a8579428-f138-4c78-832a-12b6806b0e8c
Thanks again for your (plural) help, now to think of another basic project, to learn new aspects of vbs or solidify learnt ones. :P
option explicit
dim server, user, pass, input, file, txtfile, filepath, line, arr, returnval, searchstr
filepath = "C:\passwords.txt"
input = msgbox ("Please select" & vbCrLf & " " & vbCrLf & "Yes = Save username & password" & vbCrLf & "No = Load username & password ", vbyesnocancel, "Password Manager by CMJR1979")
select case input
case vbyes
do
server = inputbox ("Please enter server name", "Password manager")
if server = "" then
wscript.quit ()
end if
loop until server <> ""
do
user = inputbox ("Please enter username", "Password manager")
if user = "" then
wscript.quit ()
end if
loop until user <> ""
do
pass = inputbox ("Please enter password", "Password manager")
if pass = "" then
wscript.quit ()
end if
loop until pass <> ""
set file = createobject("scripting.filesystemobject")
set txtfile = file.opentextfile(filepath,8,true)
txtfile.writeline server & "," & user & "," & pass
txtfile.close
msgbox "Entry added to C:\password.txt"
case vbno
call SEARCH
case vbcancel
wscript.quit ()
end select
sub SEARCH
filepath = "C:\passwords.txt"
set file = createobject("scripting.filesystemobject")
if file.fileexists(filepath) then
do
searchstr = inputbox ("Please enter server name", "Password manager")
if searchstr = "" then
wscript.quit ()
end if
loop until searchstr <> ""
returnval = SEARCHSTRLINE(searchstr, filepath)
if isempty(returnval) then
input = msgbox ("No matches", vbretrycancel, "Password Manager")
if input = 4 then
call SEARCH
elseif input = 2 then
wscript.quit ()
end if
else
input = msgbox ("Match found" & vbCrLf & " " & vbCrLf & "Servername = " & returnval(0) & vbCrLf & "Username = " & returnval(1) & vbCrLf & "Password = " & returnval(2), vbokonly, "Password Manager")
end if
else
input = msgbox ("C:\passwords.txt does not exist", vbokonly, "Password Manager")
end if
end sub
function SEARCHSTRLINE(x,y)
x = lcase(x)
set file = CreateObject("Scripting.FileSystemObject")
set txtfile = file.opentextfile(y)
while not txtfile.atendofstream
line = txtfile.readline()
arr = split(line,",")
if lcase(arr(0)) = x then
SEARCHSTRLINE = arr
exit function
end if
wend
end function
I need a VBScript that will check if a process is in use by a specific user:
Agent clicks program icon --> batch file calls for progcheck.vbs -->
progcheck.vbs looks to see is "whatever.exe" is running under that user only -->
if program is running under that user then MsgBox "Program running" --> wscript.quit (this needs to terminate out of the batch file)
else --> return to batch file.
I have tried this with tasklist in a batch file and the script works, but takes forever to run for a domain user. Want to do this in vbscript anyway.
*** UPDATED SCRIPT WITH MODS 10/12 *****
OPTION EXPLICIT
DIM strComputer,strProcess, strUserName,wshShell
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
strComputer = "." '
strProcess = "notepad.exe"
IF isProcessRunning(strComputer,strProcess,strUserName) THEN
If MsgBox ("Notepad needs to be closed.", 1) = 1 then
wscript.Quit(1)
End If
END IF
FUNCTION isProcessRunning(BYVAL strComputer,BYVAL strProcessName,BYVAL strUserName)
DIM objWMIService, strWMIQuery
strWMIQuery = "Select * from Win32_Process where name like '" & strProcessName & "' AND owner like '" &strUserName& "'"
SET objWMIService = GETOBJECT("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
IF objWMIService.ExecQuery(strWMIQuery).Count > 0 THEN
isProcessRunning = TRUE
ELSE
isProcessRunning = FALSE
END If
End Function
Let me know what you think and where I have it wrong. Thanks in advance.
UPDATED CODE v3: review comments for help
OPTION EXPLICIT
DIM strComputer, strProcess, strUserName, wshShell
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
strComputer = "."
strProcess = "notepad.exe" 'change this to whatever you are trying to detect
IF isProcessRunning(strComputer, strProcess, strUserName) THEN
If MsgBox ("Notepad needs to be closed.", 1) = 1 then
wscript.Quit(1) 'you need to terminate the process if that's your intention before quitting
End If
Else
msgbox ("Process is not running") 'optional for debug, you can remove this
END IF
FUNCTION isProcessRunning(ByRef strComputer, ByRef strProcess, ByRef strUserName)
DIM objWMIService, strWMIQuery, objProcess, strOwner, Response
strWMIQuery = "SELECT * FROM Win32_Process WHERE NAME = '" & strProcess & "'"
SET objWMIService = GETOBJECT("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2").ExecQuery(strWMIQuery)
IF objWMIService.Count > 0 THEN
msgbox "We have at least ONE instance of Notepad"
For Each objProcess in objWMIService
Response = objProcess.GetOwner(strOwner)
If Response <> 0 Then
'we didn't get any owner information - maybe not permitted by current user to ask for it
Wscript.Echo "Could not get owner info for process [" & objProcess.Name & "]" & VBNewLine & "Error: " & Return
Else
Wscript.Echo "Process [" & objProcess.Name & "] is owned by [" & strOwner & "]" 'for debug you can remove it
if strUserName = strOwner Then
msgbox "we have the user who is running notepad"
isProcessRunning = TRUE
Else
'do nothing as you only want to detect the current user running it
isProcessRunning = FALSE
End If
End If
Next
ELSE
msgbox "We have NO instance of Notepad - Username is Irrelevant"
isProcessRunning = FALSE
END If
End Function
You can use the following function:
FUNCTION isProcessRunning(BYVAL strComputer,BYVAL strProcessName)
DIM objWMIService, strWMIQuery
strWMIQuery = "Select * from Win32_Process where name like '" & strProcessName & "'"
SET objWMIService = GETOBJECT("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
IF objWMIService.ExecQuery(strWMIQuery).Count > 0 THEN
isProcessRunning = TRUE
ELSE
isProcessRunning = FALSE
END IF
END FUNCTION
For local computer you would use "."
For the process name, you would use the executable "notepad.exe"
For the rest of the code, you could can use something simple:
OPTION EXPLICIT
DIM strComputer,strProcess
strComputer = "." ' local computer
strProcess = "notepad.exe" 'whatever is the executable
IF isProcessRunning(strComputer,strProcess) THEN
'do something
ELSE
'do something else or nothing
wscript.echo strProcess & " is NOT running on computer '" & strComputer & "'"
END IF
That should do it.
EXTRA
To show every process running, then just run:
Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strList
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process")
For Each objProcess in colProcess
strList = strList & vbCr & _
objProcess.Name
Next
WSCript.Echo strList
WScript.Quit
in terminal server this function can be very slow, all the GetOwner calls are terrible in performance.
A very fast solution i created is to narrow the query using SessionID of the current user (assuming we want only current user's processes) So I added this code:
SessionID can be obtained this way:
Dim oExec, sOutput, iUserPos, iUserLen, iStatePos, SessionID
dim oShell, userName
Set oShell = CreateObject("Wscript.Shell")
userName = oShell.ExpandEnvironmentStrings("%USERNAME%")
Set oExec = oShell.Exec("query session %username%")
sOutput = LCase(oExec.StdOut.ReadAll)
iUserPos = InStr(sOutput, LCase(userName))
iStatePos = InStr(sOutput, "active")
iUserLen = Len(userName)
SessionID = CInt(Trim(Mid(sOutput, iUserPos+iUserLen, iStatePos-iUserPos-iUserLen)))
Changed the function from the previous post:
Function isProcessRunning(ByRef strComputer, ByRef strProcess, ByRef strUserName, byRef sessionID)
DIM objWMIService, strWMIQuery, objProcess, strOwner, Response
strWMIQuery = "SELECT * FROM Win32_Process WHERE SessionId = " & sessionID & " And NAME = '" & strProcess & "'"
SET objWMIService = GETOBJECT("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2").ExecQuery(strWMIQuery)
IF objWMIService.Count > 0 THEN
'msgbox "We have at least ONE instance of Notepad"
For Each objProcess in objWMIService
Response = objProcess.GetOwner(strOwner)
If Response = 0 Then
'Wscript.Echo "Process [" & objProcess.Name & "] is owned by [" & strOwner & "]" 'for debug you can remove it
if strUserName = strOwner Then
'msgbox "we have the user who is running notepad"
isProcessRunning = TRUE
Else
'do nothing as you only want to detect the current user running it
isProcessRunning = FALSE
End If
'else
'we didn't get any owner information - maybe not permitted by current user to ask for it
'Wscript.Echo "Could not get owner info for process [" & objProcess.Name & "]" & VBNewLine & "Error: " & Return
End If
Next
ELSE
'msgbox "We have NO instance of Notepad - Username is Irrelevant"
isProcessRunning = FALSE
END If
End Function
Does anyone know how I could go about finding out when a certificate for user is set to expire? I know I can get pull all of the certificates for a given user by usin the following code:
Set objUserTemplate = _
GetObject("LDAP://cn=userTemplate,OU=Management,dc=NA,dc=fabrikam,dc=com")
arrUserCertificates = objUserTemplate.GetEx("userCertificate")
But then how do I go about polling the expiration date for a given certificate? I did see this java code here: http://forums.novell.com/novell-developer-forums/dev-ldap/364977-q-retrieving-users-public-key-over-ldap.html,
X509Certificate cert = ( X509Certificate )it.next();
java.util.Date expires = cert.getNotAfter();
GregorianCalendar calNow = new GregorianCalendar();
GregorianCalendar calExp = new GregorianCalendar();
calExp.setTime( expires );
//issuerDN = cert.getIssuerDN().getName();
int daysTilExp = com.willeke.utility.DateUtils.daysPast( calExp );
long diffDays = com.willeke.utility.DateUtils.diffDayPeriods( calNow,
calExp );
if( diffDays <= 0 )
{
String mex = " Will expire in: " + diffDays + " days!";
but I'm not sure if I can use the getNotAfter method within VB, or how I would go about doing it. Does anyone have any ideas? If at all possible I would like help in doing this query in VBScript/VB.Net/VBA, etc.
I did find this VBScript code here which seems to be doing what I am trying to accomplish, but is seems pretty complex, where as the java code seemed much simpler. Is there an easier way to do this query in some flavor of VB?
From the cruto site:
On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Const ForWriting = 2
Const WshRunning = 0
Set objUser = GetObject _
("GC://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.GetInfoEx Array("userCertificate"), 0
arrUserCertificates = objUser.GetEx("userCertificate")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "No assigned certificates"
WScript.Quit
Else
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strPath = "."
intFileCounter = 0
For Each arrUserCertificate in arrUserCertificates
strFileName = "file" & intFileCounter
strFullName = objFSO.BuildPath(strPath, strFileName)
Set objFile = objFSO.OpenTextFile(strFullName, ForWriting, True)
For i = 1 To LenB(arrUserCertificate)
ReDim Preserve arrUserCertificatesChar(i - 1)
arrUserCertificatesChar(i-1) = _
Hex(AscB(MidB(arrUserCertificate, i, 3)))
Next
intCounter=0
For Each HexVal in arrUserCertificatesChar
intCounter=intCounter + 1
If Len(HexVal) = 1 Then
objFile.Write(0 & HexVal & " ")
Else
objFile.Write(HexVal & " ")
End If
Next
objFile.Close
Set objFile = Nothing
Set objExecCmd1 = objShell.Exec _
("certutil -decodeHex " & strFileName & " " & strFileName & ".cer")
Do While objExecCmd1.Status = WshRunning
WScript.Sleep 100
Loop
Set objExecCmd1 = Nothing
Set objExecCmd2 = objShell.Exec("certutil " & strFileName & ".cer")
Set objStdOut = objExecCmd2.StdOut
Set objExecCmd2 = Nothing
WScript.Echo VbCrLf & "Certificate " & intFileCounter + 1
While Not objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine
If InStr(strLine, "Issuer:") Then
WScript.Echo Trim(strLine)
WScript.Echo vbTab & Trim(objStdOut.ReadLine)
End If
If InStr(strLine, "Subject:") Then
Wscript.Echo Trim(strLine)
WScript.Echo vbTab & Trim(objStdOut.ReadLine)
End If
If InStr(strLine, "NotAfter:") Then
strLine = Trim(strLine)
WScript.Echo "Expires:"
Wscript.Echo vbTab & Mid(strLine, 11)
End If
Wend
objFSO.DeleteFile(strFullName)
objFSO.DeleteFile(strPath & "\" & strFileName & ".cer")
intFileCounter = intFileCounter + 1
Next
End If
Update I did see that I could import the certificate into the CAPICOM object to return back the ValidToDate Property, but apparently the format inwhich it is stored in AD is of the wrong format according to this posting here: http://www.powershellcommunity.org/Forums/tabid/54/aff/4/aft/1639/afv/topic/Default.aspx
Does anyone know what format is expected from the CAPICOM import function?
Microsoft has an ActiveX control called CAPICOM which allows you to programmatically access various properties of the certificate. The MSDN CAPICOM article details these functions. The Platform SDK (linked from the Where to get it link) includes samples, documentation and the redistributable control. The samples include VBScript examples. I found the download for the Platform SDK here.
In short, once you've retrieved the certificate, you're looking for the ValidFromDate and ValidToDate properties.