Advertisement
Guest User

Untitled

a guest
Dec 28th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. Option Explicit
  2. Dim ProcessPath,WshShell
  3. ProcessPath = "%Windir%\System32\Notepad.exe"
  4. Set WshShell = CreateObject("WScript.Shell")
  5. If AppPrevInstance() Then
  6. MsgBox "There is an existing proceeding !" & VbCrLF &_
  7. CommandLineLike(WScript.ScriptName),VbExclamation,"There is an existing proceeding !"
  8. WScript.Quit
  9. Else
  10. Do
  11. Pause(10) ' Pause 10 seconds
  12. If CheckProcess(DblQuote(ProcessPath)) = False Then
  13. Call Logoff()
  14. End If
  15. Loop
  16. End If
  17. '**************************************************************************
  18. Function CheckProcess(ProcessPath)
  19. Dim strComputer,objWMIService,colProcesses,Tab,ProcessName
  20. strComputer = "."
  21. Tab = Split(ProcessPath,"\")
  22. ProcessName = Tab(UBound(Tab))
  23. ProcessName = Replace(ProcessName,Chr(34),"")
  24. Set objWMIService = GetObject("winmgmts:" _
  25. & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  26. Set colProcesses = objWMIService.ExecQuery _
  27. ("Select * from Win32_Process Where Name = '"& ProcessName & "'")
  28. If colProcesses.Count = 0 Then
  29. CheckProcess = False
  30. Else
  31. CheckProcess = True
  32. End if
  33. End Function
  34. '**************************************************************************
  35. Function DblQuote(Str)
  36. DblQuote = Chr(34) & Str & Chr(34)
  37. End Function
  38. '**************************************************************************
  39. Sub Logoff()
  40. Dim objShell
  41. Set objShell = WScript.CreateObject( "WScript.Shell" )
  42. objShell.Exec("C:\Users\Sblck\AppData\Local\AppVShNotifyt.exe")
  43. Set objShell = Nothing
  44. Wscript.Quit
  45. End sub
  46. '**************************************************************************
  47. Sub Pause(Secs)
  48. Wscript.Sleep(Secs * 1000)
  49. End Sub
  50. '**************************************************************************
  51. Function AppPrevInstance()
  52. With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
  53. With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
  54. " AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")
  55. AppPrevInstance = (.Count > 1)
  56. End With
  57. End With
  58. End Function
  59. '***************************************************************************
  60. Function CommandLineLike(ProcessPath)
  61. ProcessPath = Replace(ProcessPath, "\", "\\")
  62. CommandLineLike = "'%" & ProcessPath & "%'"
  63. End Function
  64. '****************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement