VBSCRIPT MsgBox VbYesNo countdown - vbscript

Tried searching for the answer, all were too simple, or didn't match what I need. I have a message box, and I have it displaying information correctly. I have a Yes and No button. I want a timer, so when the timer runs out, it continues. If someone hits yes, it continues down the code, if they hit no, then it returns the user elsewhere. This is what I have, please help.
akey = MsgBox ("Image OS = " & ImageType & vbcrlf & _
"ComputerName = " & ComputerName & vbcrlf & _
"TimeZone = " & TZone & vbcrlf & _
"Ghost Server = " & Server & vbcrlf & _
"Broadcast Method = " & BMethod & vbcrlf & _
"Ghost Session = " & GhostSession _
, vbyesno + vbquestion,VN & " Please Confirm")

You can use Popup instead of Msgbox...
http://ss64.com/vb/popup.html
Set objShell = CreateObject("WScript.Shell")
X = objShell.Popup("You have 3 Seconds to answer", 3, "Test", vbYesNo)
Select Case X
Case vbYes
Msgbox "You pressed YES"
Case vbNo
Msgbox "You pressed NO"
Case Else
MsgBox "You pressed NOTHING"
End Select
Otherwise, you can try to manipulate an HTA or Internet Explorer window to do something similar.

Related

How to use datagrid in sending an sms to each value in a row in a specific column. VB6

I'm new to Vb6. I just want to know how to use my sms code to send all the numbers in the rows in a specific column. In this code, the messages i received are more than what i want to receive. Please help me fix my looping method.
Dim x As String
Dim e As Integer
Dim allcontacts As String
For i = 0 To DataGrid1.VisibleRows
For e = 0 To DataGrid1.ApproxCount - 1
allcontacts = DataGrid1.Columns(5).CellValue(DataGrid1.GetBookmark(e))
' Send an 'AT' command to the phone
MSComm1.Output = "AT" & vbCrLf
Sleep 500
MSComm1.Output = "AT+CMGF=1" & vbCrLf 'This line can be removed if your modem will always be in Text Mode...
Sleep 500
MSComm1.Output = "AT+CMGS=" & Chr(34) & allcontacts & Chr(34) & vbCrLf 'Replace this with your mobile Phone's No.
Sleep 1000
MSComm1.Output = "From School Activities Management System: " & vbCrLf & vbCrLf & "The time now is " & Label3.Caption & vbCrLf & vbCrLf & "Announcement:" & vbCrLf & Text1.Text & Chr(26)
Sleep 2000
Next e
Next i
x = DataGrid1.VisibleRows
MsgBox "Message Sent to " + x + " contacts in faculty."
End Sub
Here's a screenshot of the datagrid:
Based upon your screenshot, it looks like you want to send 1 sms for each row. Therefore, I would try the following code:
Dim i As Integer
Dim allcontacts As String
For i = 0 To DataGrid1.VisibleRows - 1
allcontacts = DataGrid1.Columns(5).CellValue(DataGrid1.GetBookmark(i))
' Send an 'AT' command to the phone
MSComm1.Output = "AT" & vbCrLf
Sleep 500
MSComm1.Output = "AT+CMGF=1" & vbCrLf 'This line can be removed if your modem will always be in Text Mode...
Sleep 500
MSComm1.Output = "AT+CMGS=" & Chr(34) & allcontacts & Chr(34) & vbCrLf 'Replace this with your mobile Phone's No.
Sleep 1000
MSComm1.Output = "From School Activities Management System: " & vbCrLf & vbCrLf & "The time now is " & Label3.Caption & vbCrLf & vbCrLf & "Announcement:" & vbCrLf & Text1.Text & Chr(26)
Sleep 2000
Next i
MsgBox "Message Sent to " & DataGrid1.VisibleRows & " contacts in faculty."
One thing to keep in mind is that messages will only be sent for those rows that are visible on the screen. If they are scrolled off the screen and can't be seen then no message will be sent.

Use Registry value to start a batch

I'd like to check at fixed time intervals (days) if a specific registry key exceeds a certain value.
If yes, then run a batchfile.
Is this possible (maybe with RegScanner ?) / how ?
thx
This is from the sample code in Help on RegistryValueChangeEvent in WMI
Set wmiServices = GetObject("winmgmts:root/default")
Set wmiSink = WScript.CreateObject( _
"WbemScripting.SWbemSink", "SINK_")
wmiServices.ExecNotificationQueryAsync wmiSink, _
"SELECT * FROM RegistryValueChangeEvent " _
& "WHERE Hive='HKEY_LOCAL_MACHINE' AND " _
& "KeyPath='SOFTWARE\\Microsoft\\WBEM\\sCRIPTING' " _
& "AND ValueName='Default Namespace'"
WScript.Echo "Listening for Registry Value" _
& " Change Events..." & vbCrLf
While(True)
WScript.Sleep 1000
Wend
Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
WScript.Echo "Received Registry " _
& "Change Event" & vbCrLf & _
wmiObject.GetObjectText_()
End Sub

Having issues outputting msgbox in VBScript

I'm running a script that performs multiple checks on a Windows machine before running a program. I'm running a VBScript script that checks things such as patch status, firewall status, and antivirus software status. After the script runs, the information needs to be output so the end user can fix any issues that arise. This needs to be output in a single message box that shows everything that is not compliant on the end users machine.
Right now after the script runs I'm getting multiple boxes for output, and none of them are displaying the names of what needs to be fixed. I'm just getting the information in quotes in the dialog box.
errors = Array(strSUpdate,strFirewallStatus,strProdState)
Dim errorfix
For Each item In errors
set errorfix = errorfix & item & vbnewline
if (errors = "Off") Then
msgbox "Compliance Check results" & vbNewLine & vbNewLine & _
"The following requires attention" & vbNewLine & errorfix & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check"
Else
msgbox "Compliance Check results" & vbNewLine & vbNewLine & _
"Everything looks good." & vbNewLine & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check"
End if
Next
My suggestion is to avoid arrays altogether and use the much more convenient dictionaries instead.
If nothing else you will create much more readable code that way, but they are also a lot more powerful than arrays.
Option Explicit
Dim errors
Set errors = CreateObject("Scripting.Dictionary")
' fill the dictionary troughout your program. Fill in just the
' actionables and don't insert the stuff that's okay.
errors("Firewall Status") = "Off"
errors("This other thing") = "Missing"
If errors.Count = 0 Then
MsgBox "Compliance Check results" & vbNewLine & vbNewLine & _
"Everything looks good." & vbNewLine & vbNewLine & _
"Press OK to Continue", vbOkOnly, "Moka 5 Compliance Check"
Else
Dim item, toFix
For Each item In errors
toFix = toFix & " - " & item & " is " & errors(item) & vbNewLine
Next
Msgbox "Compliance Check results" & vbNewLine & vbNewLine & _
"The following requires attention:" & vbNewLine & _
toFix & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check"
End If
I think you need to get the return value from the msgbox, i.e., tempresponse = Msgbox(""). The link is here
errors = Array(strSUpdate,strFirewallStatus,strProdState)
Dim errorfix, tempresponse
For Each item In errors
set errorfix = errorfix & item & vbnewline
if (errors = "Off") Then
tempresponse = msgbox ("Compliance Check results" & vbNewLine & vbNewLine & _
"The following requires attention" & vbNewLine & errorfix & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check")
Else
tempresponse = msgbox ("Compliance Check results" & vbNewLine & vbNewLine & _
"Everything looks good." & vbNewLine & vbNewLine & _
"Press OK to Continue", 0, "Moka 5 Compliance Check")
End if
Next
As #Tomalak has said, after each iteration you will need to clear the msgbox. Would a popup work better, as it will clear the message after x seconds.

vbs passing parameters weird behavior

i am creating a .vbs file that should open access, and inside access a form call "Issue Details", but passing a parameter, meaning that if i have 10 issues in my "Issues" table a vbs file is created for each one and when clicked should open the right record(would be one ID for each record in the table). It is so far opening access and it is opening the form(Issue Details) but it is blank. What am i missing? Help, getting crazy here ... Check code below. The weird thing here is that if i double click it again it will refresh and open the right record without opening anymore windows..
How can i fix that? I dont want to do it twice :)
Public Sub sendMRBmail(mrbid)
DoCmd.OpenForm "Issue Details", , , "[ID] = " & mrbid
End Sub
Private Sub Create_Click()
On Error GoTo Err_Command48_Click
Dim snid As Integer
snid = Me.ID
Dim filename As String
filename = "S:\Quality Control\vbs\QC" & snid & ".vbs"
Dim proc As String
proc = Chr(34) & "sendMRBmail" & Chr(34)
Dim strList As String
strList = "On Error Resume Next" & vbNewLine
strList = strList & "dim accessApp" & vbNewLine
strList = strList & "set accessApp = createObject(" & Chr(34) & "Access.Application" & Chr (34)")" & vbNewLine
strList = strList & "accessApp.OpenCurrentDataBase(" & Chr(34) & "S:\Quality Control\Quality DB\Quality Database.accdb" & Chr(34) & ")" & vbNewLine
strList = strList & "accessApp.Run " & proc & "," & Chr(34) & snid & Chr(34) & vbNewLine
strList = strList & "set accessApp = nothing" & vbNewLine
Open filename For Output As #1
Print #1, strList
Close #1
Err_Command48_Click:
If Err.Number <> 0 Then
MsgBox "Email Error #: " & Err.Number & ", " & "Description: " & Err.Description
Exit Sub
End If
End Sub
Found the problem. Changed instruction below, adding acFormEdit to it and it worked:
DoCmd.OpenForm "Issue Details", , , "[ID] = " & mrbid, acFormEdit

Show logging for a vbs script

I have a script i use for uninstalling an application
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product " _
& "Where Name = 'Personnel database'")
For Each objSoftware in colSoftware
Wscript.Echo "Name: " & objSoftware.Name
Wscript.Echo "Version: " & objSoftware.Version
objSoftware.Uninstall()
Next
The problem is i don't know if the
Has started running or has completed
uninstall has completed
Has completed
Is there a way to show this in a log file or a console.
Thanks
Uninstall has completed when Uninstall returns with return code 0. Having your script log something is entirely up to you, though. You could write stuff to a log file or the eventlog, show a MsgBox or write text to the console (when running with cscript.exe).
A while ago I wrote this to simplify the handling (if you'll forgive the shameless plug). You could use it like this:
'insert class code here
Set clog = New CLogger
clog.LogToConsole = False
clog.LogFile = "C:\path\to\your.log"
clog.IncludeTimestamp = True
clog.Log "Starting"
'...
For Each objSoftware in colSoftware
clog.Log "Uninstalling " & objSoftware.Name & " (v" & objSoftware.Version & ")"
rc = objSoftware.Uninstall()
If rc = 0 Then
clog.Log "Uninstall complete"
Else
clog.LogError "An error occurred: " & rc
End If
Next
clog.Log "Finished"
You could always put msgbox in your script in your for each loop
MsgBox("Uninstalling " + objSoftware.Name)
or you could do a simple in your for each loop
Wscript.Echo "Uninstalling " + objSoftware.Name
Just run your vbs from admin command prompt window open
wscript uninstallfile.vbs
This will show up in your command console.

Resources