Skip to content

Commit f523db0

Browse files
committed
Get service installation date (in theory)
1 parent 0ef6660 commit f523db0

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
Function GetServiceInstallDateUsingServiceInstance(ByRef strServiceInstallDate, ByVal objServiceInstance)
2+
'region FunctionMetadata #######################################################
3+
' Assuming that objServiceInstance represents an instance of the WMI service class
4+
' (of type Win32_Service), this function obtains the service's installation date
5+
' and time in DMTF CIM_DATETIME string format.
6+
'
7+
' Note: the author believes that this property is always null, therefore this
8+
' function would not return any data.
9+
'
10+
' A CIM_DATETIME object is a string in the following format:
11+
' yyyymmddHHMMSS.mmmmmmsUUU
12+
' yyyy = Four-digit year (0000 through 9999)
13+
' mm = Two-digit month (01 through 12)
14+
' dd = Two-digit day of the month (01 through 31). This value must be appropriate
15+
' for the month. For example, February 31 is invalid
16+
' HH = Two-digit hour of the day using the 24-hour clock (00 through 23)
17+
' MM = Two-digit minute in the hour (00 through 59)
18+
' SS = Two-digit number of seconds in the minute (00 through 59)
19+
' mmmmmm = Six-digit number of microseconds in the second (000000 through 999999).
20+
' This field must always be present to preserve the fixed-length nature of
21+
' the string
22+
' s = Plus sign (+) or minus sign (-) to indicate a positive or negative offset
23+
' from Universal Time Coordinates (UTC)
24+
' UUU = Three-digit offset indicating the number of minutes that the originating
25+
' time zone deviates from UTC
26+
'
27+
' The function takes two positional arguments:
28+
' - The first argument (strServiceInstallDate) is populated upon success with a
29+
' string in CIM_DATETIME format (see above) containing the date and time when
30+
' the service was installed
31+
' - The second argument (objServiceInstance) is an array/collection of objects of
32+
' class Win32_OperatingSystem
33+
'
34+
' The function returns a 0 if the function could determine the value of the
35+
' service's installation date and time. It returns a negative integer if an error
36+
' occurred determining the service's installation date and time.
37+
'
38+
' Example:
39+
' intReturnCode = GetServiceInstances(arrServiceInstances)
40+
' If intReturnCode > 0 Then
41+
' ' At least one Win32_Service instance was retrieved successfully
42+
' For Each objServiceInstance In arrServiceInstances
43+
' intReturnCode = GetServiceInstallDateUsingServiceInstance(strServiceInstallDate, objServiceInstance)
44+
' If intReturnCode = 0 Then
45+
' ' The service installation date string was retrieved successfully
46+
' ' and is stored in strServiceInstallDate
47+
' End If
48+
' Next
49+
' End If
50+
'
51+
' Version: 1.0.20230815.0
52+
'endregion FunctionMetadata #######################################################
53+
54+
'region License ################################################################
55+
' Copyright 2023 Frank Lesniak
56+
'
57+
' Permission is hereby granted, free of charge, to any person obtaining a copy of
58+
' this software and associated documentation files (the "Software"), to deal in the
59+
' Software without restriction, including without limitation the rights to use,
60+
' copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
61+
' Software, and to permit persons to whom the Software is furnished to do so,
62+
' subject to the following conditions:
63+
'
64+
' The above copyright notice and this permission notice shall be included in all
65+
' copies or substantial portions of the Software.
66+
'
67+
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68+
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
69+
' FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
70+
' COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
71+
' AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
72+
' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
73+
'endregion License ################################################################
74+
75+
'region DownloadLocationNotice #################################################
76+
' The most up-to-date version of this script can be found on the author's GitHub
77+
' repository at https://github.com/franklesniak/sysadmin-accelerator
78+
'endregion DownloadLocationNotice #################################################
79+
80+
'region Acknowledgements #######################################################
81+
' None!
82+
'endregion Acknowledgements #######################################################
83+
84+
'region DependsOn ##############################################################
85+
' TestObjectForData()
86+
' TestObjectIsStringContainingData()
87+
'endregion DependsOn ##############################################################
88+
89+
Dim intFunctionReturn
90+
Dim intReturnMultiplier
91+
Dim strInterimResult
92+
Dim strResultToReturn
93+
94+
Err.Clear
95+
96+
intFunctionReturn = 0
97+
intReturnMultiplier = 128
98+
strInterimResult = ""
99+
strResultToReturn = ""
100+
101+
If TestObjectForData(objServiceInstance) <> True Then
102+
intFunctionReturn = intFunctionReturn + (-1 * intReturnMultiplier)
103+
Else
104+
On Error Resume Next
105+
strInterimResult = objServiceInstance.InstallDate
106+
If Err Then
107+
Err.Clear
108+
On Error GoTo 0
109+
intFunctionReturn = intFunctionReturn + (-2 * intReturnMultiplier)
110+
Else
111+
On Error GoTo 0
112+
If TestObjectIsStringContainingData(strInterimResult) <> True Then
113+
intFunctionReturn = intFunctionReturn + (-3 * intReturnMultiplier)
114+
Else
115+
strResultToReturn = strInterimResult
116+
End If
117+
End If
118+
End If
119+
120+
If intFunctionReturn >= 0 Then
121+
strServiceInstallDate = strResultToReturn
122+
End If
123+
124+
GetServiceInstallDateUsingServiceInstance = intFunctionReturn
125+
End Function

0 commit comments

Comments
 (0)