Hi everybody,
we all like to play with code...
I've arrived at that:
Option Explicit
' ------------------------------------------------
Private Declare Function CloseHandle Lib "kernel32" ( _
ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" ( _
ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" ( _
ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
' ------------------------------------------------------
Public Function ShellX( _
ByVal PathName As String, _
Optional ByVal WindowStyle As VbAppWinStyle = vbMinimizedFocus, _
Optional ByVal Events As Boolean = True _
) As Long
'declarations:
Const STILL_ACTIVE = &H103&
Const PROCESS_QUERY_INFORMATION = &H400&
Dim ProcId As Long
Dim ProcHnd As Long
'Get process-handle:
ProcId = Shell(PathName, WindowStyle)
ProcHnd = OpenProcess(PROCESS_QUERY_INFORMATION, True, ProcId)
'Wait for prozess-end:
Do
If Events Then DoEvents
GetExitCodeProcess ProcHnd, ShellX
Loop While ShellX = STILL_ACTIVE
'clean up
CloseHandle ProcHnd
End Function
Sub Macro6TripleA()
Dim strA() As String
Dim sTmp As String
Dim vVar As Variant
Dim lTmp As Long
Dim lSec As Long
Dim z As Long
vVar = ShellX("cmd /C systeminfo > c:\test\system.txt")
Open "c:\test\system.txt" For Input As #1
While EOF(1) = False
Line Input #1, sTmp
If InStr(sTmp, "Up Time") Then
' MsgBox sTmp
strA() = Split(sTmp, " ")
GoTo myexit
End If
Wend
myexit:
Close #1
lSec = 0
For lTmp = 0 To UBound(strA) - 1
If IsNumeric(strA(lTmp)) Then
z = z + 1
Select Case z
Case 1: lSec = lSec + CLng(strA(lTmp)) * 86400
Case 2: lSec = lSec + CLng(strA(lTmp)) * 3600
Case 3: lSec = lSec + CLng(strA(lTmp)) * 60
Case 4: lSec = lSec + CLng(strA(lTmp))
End Select
End If
Next
MsgBox "active for " & CStr(lSec) & " seconds"
End Sub
I've split the string from systeminfo using spaces,
checked whether there were a numerical results in the array,
assuming that there are no such results
but days, hours, minutes and seconds
and added them all.
Have some fun.
Credits to Jost Schwider,
http://vb-tec.de/xshell.htm
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"