'*================================================================== '* Titel : Journal3Wrapper '* Purpose : Wrapper for Journal 3 and Pelo '* Author : Johan Eksberg '* Mail : johan.eksberg@advance.se '*================================================================== On Error Resume Next Init() Sub Init() On Error Resume Next Dim iInt For iInt = 1 To 10 If IsFolder ("P:\Journal3") and IsFolder("T:\Labbest") Then Exit Sub Else wscript.sleep 1000 iInt = iInt + 1 End If Next PopupMessage "Kunde inte starta Journal 3. Hittar inte följande mappar" & vbcrlf & _ "P:\Journal3" & vbcrlf & _ "T:\Labbtest", 5 wscript.sleep 5000 RunApp "%comspec% /c %systemroot%\system32\logoff.exe", False, False End Sub Main() 'Starta Journal3 Sub Main() On Error Resume Next Dim iContinue, sMessage, iInt If IsFile ("C:\J3P.CMD") Then Runapp "%comspec% /c C:\J3P.CMD", True, False Else PopupMessage "Hittade inte följande fil: C:\J3P.CMD", 5 wscript.sleep 5000 RunApp "%comspec% /c %systemroot%\system32\logoff.exe", False, False wscript.quit End If 'Ge NTVDM lite tid att starta For iInt = 1 To 10 If IsProcessRunning("ntvdm.exe") Then iInt = 10 Else wscript.sleep 1000 iInt = iInt + 1 End If Next 'Kolla upp om Pelo körs, om inte strarta Pelo While IsProcessRunning("ntvdm.exe") If Not IsProcessRunning("javaw.exe") Then If IsFile ("P:\Journal3\pelo.bat") Then 'Vänta 5 sekunder wscript.sleep 5000 RunApp "%comspec% /c Start /DP:\Journal3 /B P:\Journal3\pelo.bat order P:\Journal3", False, False 'Sov en halv minut Zzzzz wscript.sleep 30000 Else PopupMessage "Hittade inte följande fil: P:\Journal3\pelo.bat", 5 Exit Sub End If End If Wend 'Journal 3 avslutades (ntvdm.exe är inte igång längre) sMessage = "Journal 3 avslutades" & VbCrLf & VbCrLf & _ "Vill du starta Journal 3 igen?" & VbCrLf & _ "Om du väljer Nej så kommer du att loggas ut" iContinue = MsgBox(sMessage, vbYesNo + vbInformation, "Info") If iContinue = vbNo Then RunApp "%comspec% /c %systemroot%\system32\logoff.exe", False, False wscript.quit Else Main() End If End Sub '*================================================================== '* Functions (Routines with return values) '*================================================================== '*================================================================== '* Name : IsFile '* In : sPath '* Out : True/False '* Purpose : Check whether a file exist or Not '* Comment : '*================================================================== Function IsFile(sPath) On Error Resume Next Dim oFSO, sFile IsFile = False Set oFSO = CreateObject("Scripting.FileSystemobject") ' Filesystem object sFile = Trim(sPath) If oFSO.FileExists(sPath) Then IsFile = True Else IsFile = False End If Set oFSO = Nothing End Function '*================================================================== '* Name : IsFolder '* In : sPath '* Out : True/False '* Purpose : Check whether a folder exist or Not '* Comment : '*================================================================== Function IsFolder(sPath) On Error Resume Next Dim oFSO, sFolder IsFolder = False Set oFSO = CreateObject("Scripting.FileSystemobject") ' Filesystem object sFolder = Trim(sPath) If Right(sFolder, 1) = "\" Then sFolder = Left(sFolder, Len(sFolder) - 1) End If If oFSO.FolderExists(sFolder) Then IsFolder = True Else IsFolder = False End If Set oFSO = Nothing End Function '*================================================================== '* Name : IsProcessRunning '* In : Process name (look in task manager) '* Out : True/False '* Purpose : Check if a process is running '* Comment : Checks only processes owned by the current user '*================================================================== Function IsProcessRunning(sProcess) On Error Resume Next Dim oProcess, oWshell, sUser, sWMIUser, sWMIDomain, cProperties Set oWshell = CreateObject("WScript.Shell") sUser = oWShell.ExpandEnvironmentStrings("%USERNAME%") Set oWshell = Nothing IsProcessRunning = False For Each oProcess In GetObject("winmgmts://").InstancesOf("win32_process") If UCase(oProcess.Name) = UCase(sProcess) Then cProperties = oProcess.GetOwner(sWMIUser,sWMIDomain) If UCase(sUser) = UCase(sWMIUser) Then IsProcessRunning = True End If End If Next Set oProcess = Nothing End Function '*================================================================== '* Subroutines (Routines without return values) '*================================================================== '*================================================================== '* Name : KillProcess '* In : Process name (look in task manager) '* Out : - '* Purpose : Kill a process by name '* Comment : Kills only processes owned by the current user '*================================================================== Sub KillProcess(sName) On Error Resume Next Dim oProcesses, oProcess, oWshell, sUser, sWMIUser, sWMIDomain, cProperties Set oWshell = CreateObject("WScript.Shell") sUser = oWShell.ExpandEnvironmentStrings("%USERNAME%") Set oWshell = Nothing Set oProcesses = GetObject("WinMgmts:root/CIMV2").ExecQuery( _ "SELECT * FROM Win32_Process WHERE Name='" & sName &"'") For Each oProcess In oProcesses If UCase(oProcess) = UCase(sProcess) Then cProperties = oProcess.GetOwner(sWMIUser,sWMIDomain) If UCase(sUser) = UCase(sWMIUser) Then oProcess.Terminate End If End If Next Set oProcesses = Nothing End Sub '*================================================================== '* Name : RunApp '* In : Path, Visible/Hidden, Wait '* Out : - '* Purpose : Runs an application '* Comment : Please use the correct syntax for paths With space '* such as "Program Files". Google it up :-) '* Example: '* RunApp """c:\Progam Files\MyApp\myapp.exe"" myparameters" '* RunApp """c:\Program Files\My App\myapp.exe""" '* RunApp chr(34) & "c:\Progam Files\MyApp\myapp.exe" & chr(34) '* '* Window State: '* 1 = Runs the application and displays a window '* 0 = Runs the application hidden '*================================================================== Sub RunApp(sApplication, bVisible, bWait) On Error Resume Next Dim iState If bVisible Then iState = 1 Else iState = 0 End IF Set oWShell = CreateObject("WScript.Shell") ' WScript Shell oWShell.Run sApplication,iState,bWait Set oWShell = Nothing End Sub '*================================================================== '* Name : PopupMessage '* In : SMessage. The message to display '* : sTime. How long the popup will display before closing '* Out : - '* Purpose : Pops up a message to the user '* Comment : '*================================================================== Sub PopupMessage(sMessage, sTime) Dim oWShell Set oWShell = CreateObject("WScript.Shell") ' WScript Shell oWShell.Popup sMessage & vbCRLF & vbCRLF & "(Detta meddelande kommer att stängas automatiskt om " & sTime & " sekunder)", sTime, "Info", vbInformation Set oWShell = Nothing End Sub