Wątek przeniesiony 2021-01-28 13:23 z Inne języki programowania przez cerrato.

Auto-odliczanie(countdown) w VBS

0

To jest mój kawałek kodu....(słynna piosenka :) )

If GetOS = "Vista" Or GetOS = "Win7" Then
  If WScript.Arguments.length =0 Then
        Set objShell = CreateObject("Shell.Application")
        objShell.ShellExecute "wscript.exe", """" & _
            WScript.ScriptFullName & """" & " uac","", "runas", 1
	Else
        LogDateTime
        Set objFSO=CreateObject("Scripting.FileSystemObject")
        outFile="C:\Windows\RemoveSpy_AIO.log"
        Set objFile = objFSO.OpenTextFile(outFile, 8)
        objFile.Write LogDateTime+" Przywracanie systemu - uruchomienie CRP.VBS" & vbCrLf
        objFile.Close
            CreateSRP
    End If
End If
If GetOS = "Win81" Or GetOS = "Win10" Then
  If WScript.Arguments.length =0 Then
        Set objShell = CreateObject("Shell.Application")
        objShell.ShellExecute "wscript.exe", """" & _
        WScript.ScriptFullName & """" & " uac","", "runas", 1
  Else
        LogDateTime
        Set objFSO=CreateObject("Scripting.FileSystemObject")
        outFile="C:\Windows\RemoveSpy_AIO.log"
        Set objFile = objFSO.OpenTextFile(outFile, 8)
        objFile.Write LogDateTime+" Przywracanie systemu - uruchomienie CRP.VBS" & vbCrLf
        objFile.Close
          const HKEY_LOCAL_MACHINE = &H80000002
            strComputer = "."
            Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
            strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore"
            strValueName = "SystemRestorePointCreationFrequency"
            oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName, 0
                CreateSRP
       oReg.DeleteValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName
    End If
End If
Sub CreateSRP
  curDate = Year(Date) & "-" & Right(String(2, "0") & Month(Date),2) & "-" & Day(Date) & "_" & Time
  InputMy = InputBox (" Wpisz w³asn¹ nazwê dla punktu przywracania,"+vbCrLf+vbCrLf+" np. Mój Punkt Przywracania na wszelki wypadek "+vbCrLf+vbCrLf+" lub u¿yj nazwy sugerowanej przez skrypt:",GetOS+" RemoveSpy_AIO - Przywracanie systemu","RemoveSpy_AIO_"+CurDate)
  If InputMy = "" Then
        LogDateTime
			intTimeout = 2 
  		intType = 48 
  		strMessage = "     Anulowano tworzenie punktu przywracania !" 
  		strTitle = GetOS+" RemoveSpy_AIO - Przywracanie systemu" 
  		Set WshShell = CreateObject("WScript.Shell")
  		intResult = WshShell.Popup(strMessage, intTimeout, strTitle, intType)
        Set objFSO=CreateObject("Scripting.FileSystemObject")
        outFile="C:\Windows\RemoveSpy_AIO.log"
        Set objFile = objFSO.OpenTextFile(outFile, 8)
        objFile.Write LogDateTime+" Przywracanie systemu - anulowano tworzenie punktu przywracania!" & vbCrLf
        objFile.Close
    Wscript.Quit
  End If
        LogDateTime
        Set objFSO=CreateObject("Scripting.FileSystemObject")
        outFile="C:\Windows\RemoveSpy_AIO.log"
        Set objFile = objFSO.OpenTextFile(outFile, 8)
        objFile.Write LogDateTime+" Przywracanie systemu - uruchomienie tworzenia punktu przywracania systemu" & vbCrLf
        objFile.Close
  swinmgmts = "winmgmts:\\.\root\default:Systemrestore"
      GetObject(swinmgmts).CreateRestorePoint InputMy, 0, 100
        LogDateTime
			intTimeout = 3 
  		intType = 64 
  		strMessage = "             Punkt przywracania"+vbCrLf+InputMy+vbCrLf+"               zosta³ utworzony." 
  		strTitle = GetOS+" RemoveSpy_AIO - Przywracanie systemu" 
  		Set WshShell = CreateObject("WScript.Shell")
  		intResult = WshShell.Popup(strMessage, intTimeout, strTitle, intType)
        Set objFSO=CreateObject("Scripting.FileSystemObject")
        outFile="C:\Windows\RemoveSpy_AIO.log"
        Set objFile = objFSO.OpenTextFile(outFile, 8)
        objFile.Write LogDateTime+" Przywracanie systemu - punkt przywracania: """+InputMy+""" zosta³ utworzony" & vbCrLf 
        objFile.Close
End Sub
Function GetOS
    Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & _
    ".\root\cimv2")
    Set colOS = objWMI.ExecQuery("Select * from Win32_OperatingSystem")
    For Each objOS in colOS
  strOSName = objOS.Caption
        If instr(strOSName, "Windows 7") Then
          GetOS = "Win7"
        ElseIf instr(strOSName, "Vista") Then
          GetOS = "Vista"
        ElseIf instr(strOSName, "Windows XP") Then
          GetOS = "Windows XP"
        ElseIf instr(strOSName, "Windows 8.1") Then
          GetOS = "Win81"
        ElseIf instr(strOSName, "Windows 10") Then
          GetOS = "Win10"
        End If
  Next
End Function
Function LogDateTime
  LogDateTime = Year(Date) & "-" & Right(String(2, "0") & Month(Date),2) & "-" & Day(Date) & "_" & Right(String(2, "0") & Hour(Time),2) & "-" & Right(String(2, "0") & Minute(Time),2) & "-" & Right(String(2, "0") & Second(Time),2)
End Function

Skrypt tworzy punkt przywracania systemu z domyślna nazwa, fajnie by było gdyby po np. 10 sekundach bez interakcji użytkownika wykonał go

Czy używając funkcji InputMy = InputBox ()
da radę osiągnąć auto-odliczanie w dół np od 10 co 1 i czy będzie to widoczne na wywołanym oknie czy też nie?

Wiem że tutaj da radę: intResult = WshShell.Popup(strMessage, intTimeout, strTitle, intType)

1

Przepraszam, że nie zagłębiałem się w źródło które podesłałeś, ale na podstawie ostatnich akapitów przypomniałem sobie taki temat:
https://4programmers.net/Forum/Inne/332053-vbscript_szukam_materialow

Myślę, że to jest to czego szukasz

Paweł

Edit:

niestety licznik nie będzie widoczny w popup'ie

intButton = PopupBox ("This is message", "This is title", 5, vbInformation + vbOKCancel + vbDefaultButton2)
MsgBox ButtonCode2Text(intButton), vbInformation

intButton = PopupBox ("This is message", "This is title", 5, vbExclamation + vbAbortRetryIgnore + vbDefaultButton3)
MsgBox ButtonCode2Text (intButton), vbExclamation

intButton = PopupBox ("This is message", "This is title", 5, vbQuestion + vbYesNo + vbDefaultButton1)
MsgBox ButtonCode2Text (intButton), vbCritical + vbOKOnly


Function PopupBox (strMessage, strTitle, intTimeout, intDialogType)	
	Set objShell = CreateObject("Wscript.Shell")
	PopupBox = objShell.Popup (strMessage, intTimeout, strTitle, intDialogType)
	Set objShell = Nothing
End Function

Function ButtonCode2Text (intButtonCode)
	' returning Popup and MsgBox button text
	Select Case intButtonCode
		Case vbOK
			txtButton = "OK"
		Case vbCancel
			txtButton = "Cancel"
		Case vbAbort
			txtButton = "Abort"
		Case vbRetry
			txtButton = "Retry"
		Case vbIgnore
			txtButton = "Ignore"
		Case vbYes
			txtButton = "Yes"
		Case vbNo
			txtButton = "No"
		Case Else
			txtButton = intButtonCode
	End Select
	ButtonCode2Text = txtButton
End Function
0

Niestety nie działa to tak jak bym chciał.
Mam pomysł aby dać dwa okna pierwsze domyślne z automatu się zamykające p o10 sekundach i robiące Punkt Przywracania Systemu z domyślną nazwa.
i klawisz NIE odsyłałby do drugiego okna już z procedura INPUT(modyfikacja domyślnej nazwy)

1 użytkowników online, w tym zalogowanych: 0, gości: 1