I'm having trouble making a Msgbox modal. Every time I add ', +vbSystemModal' to the end, it just breaks my script saying -Invalid procedure call or argument: 'Msgbox'-
I'm using something similar to the following code (but, longer, with more calls and stuff)
MsgBox "Hello " & objUser.givenName & ", Please note that your password Expires in " & daysLeft & " day(s)" & " at " & whenPasswordExpires & chr(13) & chr(13) & "You have less than one day left! It is advised that you update your password immediately to avoid network issues." & chr(13) & chr(13) & "Please press CTRL-ALT-DEL and select the 'Change a password' option before your password expires!", "PASSWORD EXPIRATION WARNING!", +vbSystemModal
Is it calling the daysleft and username that breaks it? How can I work around this to make it a modal message?
thanks in advance.
EDIT: As explained above, using ", +vbSystemModal" simply breaks the script.
Using the following worked:
MsgBox "Message goes here!", 4096, "Title of message!"
The 4096 sets it as a Msgbox with an 'OK' option and modal settings.
This works better than ", +vbSystemModal" when your message is broken up as you call information.
Related
I have a VBScript setup as a logon script in my GPO. I'm having an issue where every time it runs at logon, I get Permission Denied on the line:
set lf = fso.opentextfile(lfp, 2, true)
Points of interest:
Despite the error, the script completes successfully.
The script executes without error if I run it manually.
The lfp variable points to c:\folder\folder\file.log. The file is created (when necessary) and populated appropriately (overwritten, as expected when it does exist).
If the file is created, the fso is closed before trying to opentextfile.
The user logging in does have modify permission to the path and to the file being replaced when it exists via inherited Authenticated Users permission (from c:\folder1 - see below).
If I throw in a wscript.sleep 30000 just before that line, it just waits 30 seconds to throw permissions denied.
If user is a member of local administrators group on PC, I get no errors. Again, when user is not local admin, it errors, but completes successfully.
I see the same behavior under both Windows 7 and 10.
I'm at a loss here. Here's the pertinent section of code (please excuse any poor coding practice):
'notify robocopy log file location
function seelog(log)
lf.writeline "[" & now & "] " & "See log file for details: " & log
end function
'process robocopy exit codes and write log
function writeerrors(items)
docs = items(0)
retcode = items(1)
logfile = items(2)
if docs = "c" then
name = "some stuff"
else
name = "some other stuff"
end if
If retcode = 0 Then
lf.writeline "[" & now & "] " & name & " folder was already up to date."
elseif retcode = 1 then
lf.writeline "[" & now & "] " & name & " folder was updated."
seelog(logfile)
else
lf.writeline "[" & now & "] " & name & " folder update exited with robocopy error code: " & retcode
seelog(logfile)
End If
end function
'get logged in user
un = CreateObject("WScript.Network").UserName
'check for logfile, and if not exist, create
'folder1 always exists, no need to check or create
lfp = "c:\folder1\folder2\folder3\logfile1.log"
ld1 = "c:\folder1\folder2"
ld2 = "c:\folder1\folder2\folder3"
set fso = createobject("scripting.filesystemobject")
if not fso.fileexists(lfp) then
if not fso.folderexists(ld1) then
fso.createfolder(ld1)
end if
if not fso.folderexists(ld2) then
fso.createfolder(ld2)
end if
set cf = fso.createtextfile(lfp)
cf.close
end if
'open logfile (lfp variable)
'for writing (2)
'overwrite if already exists (true)
wscript.sleep 30000
'************permission denied happens on next line on lfp var*************
Set lf = fso.OpenTextFile(lfp, 2, True)
lf.writeline "[" & now & "] " & "Script started."
lf.writeline "[" & now & "] " & "Logged in user: " & un
lf.writeline "[" & now & "] " & "========================================================="
more code writing to log file and executing robocopy....
I suppose suppressing all errors is an option, but 1) I'd rather not, and 2) I'm not clear on how to accomplish that in VBScript.
ETA:
On Error Resume Next
Set lf = fso.OpenTextFile(lfp, 2, True)
On Error Goto 0
I tested this and it does break the script. lf is not set due to the error so the following lines error out with 'object required "lf"' code 800a01a8 as expected.
I don't like doing this, but my work around was to launch the .vbs from a .bat (personal preference - I like to keep everything from one job in one script so in the future I don't have to go chasing files around).
I placed a logon.bat file in my GPO as the logon script.
#echo off
echo Launching update script...
cscript c:\folder1\script.vbs
This seems to work around the (apparently false) permissions issue I was having. I'm still curious if anyone can tell me exactly why I was seeing the behavior I saw. Does the script engine write to a temp location maybe, when calling OpenTextFile (when launching directly from the GPO) that only admin users would have access to?
On Error Resume Next will ignore the error then On Error Goto 0 will turn normal error handling back on
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.
I cannot trap the 8004020f error generated by a script in Visual Basic (CDOSYS component).
I used the "on error resume next", it traps all errors except for this one.
This error is generated in this situation:
- the mailserver I use for sending hosts mailboxes belonging to #mydomain.abc
- I try to send mail to nonexistant#mydomain.abc
That is, if I try to send an email to a non-existant user of a domain hosted on the same mailserver used for sending, this action causes the error.
This is (almost) impossible to catch!! What can I do? I have a lot of databases and my old non-existant address is found in hundredths of tables and databases!
Thanks
Put in the following in order to find the real error code, which is a decimal number. For example, 13=type mismatch.
<%
response.write("err.number=" & err.number & "<br>")
%>
OR...
I looked at my own stuff and found this:
Select Case err.Number
Case -2147220973
strRet = " Failure to Send Report Message - Server Not Found" & vbCrLf & " Error: " & err.Number & " - " & err.Description
Case -2147220975
strRet = " Failure to Send Report Message - Server Authentication Failed" & vbCrLf & " Error: " & err.Number & " - " & err.Description
Case Else
strRet = " Failure to Send Report Message - Error: " & err.Number & " - " & err.Description
End Select
I have created an Inputbox to get the username entered but stuck with the cancel button
Private Sub Form_Load()
fsUserName = UCase(InputBox("Please Enter your name.", "User Name", _
"dc"))
If fsUserName = "" Then
MsgBox "No name Entered." & Chr(13) & Chr(13) & _
"You must enter a name.", vbExclamation, "ERROR"
Form_Load
ElseIf VarType(fsUserName) = 0 Then 'If cancel clicked
cmdQuit_Click
End If
Also is there a way that when the X button on the form is clicked it executes cmdQuit_Click so that if the userclicks the command button Quit or X ,the Quit script is run.In the quit script there are message boxes and cleanup.
You can use StrPtr() to detect if cancel was clicked;
Dim fsUserName As String
fsUserName = InputBox("Please Enter your name.", "User Name", "dc")
If (StrPtr(fsUserName) = 0&) Then
MsgBox "Cancelled or X clicked"
ElseIf fsUserName = "" Then
MsgBox "No name Entered." & vbCr & "You must enter a name.", vbExclamation, "ERROR"
Else
fsUserName = UCase$(fsUserName)
MsgBox fsUserName
End If
If you want to do something when the form unloads you can use the Form_Unload event or better the Form_QueryUnload event which fires before the actual unload & allows you to cancel it.
It will also tell you why the form is unloading (UnloadMode will be 0 if the red X is clicked)
Using "Unload Me" will raise both of the events.
Edit: Calling Form_Load in Form_Load like that will eventually fill up the stack, better to use a loop to look for a missing username.
Alex's answer using StrPtr, which I assume works as advertised, is good as far as it goes, but the better advice (IMO) is to avoid InputBox altogether. You can easily create your own using a dialog-style form, a textbox, and a couple of buttons, and maybe an icon if you like.
Rolling your own gives you complete flexibility and predictability, and once you have it you can use it in any future projects.
Excel InputBox and Application.InputBox are different functions.
Sub GetValue2()
Dim Monthly As Variant
Monthly = Application.InputBox _
(Prompt:="Podaj wysokość miesięcznej wypłaty:", _
Type:=1)
If Monthly = False Then Exit Sub
MsgBox "Zarobki rocznie: " & Monthly * 12
End Sub
Try this...
Name = Application.InputBox("Please enter Name")
If Name = "False" Then
MsgBox " Your message here"
Exit Sub
End If
I developed an application in VB6. In client's environment it raises runtime errors which I can't reproduce under debugger. Is there any way to get the stacktrace or location of error?
I created log file and
I used
Err.Description,Err.Source
but it gives blank values.
Please help me.
my method(......
On Error GoTo Error_Handler
.........
Error_Handler :
writeToLogFile(Err.Source,Err.Description)
You've probably done something to clear the Err object before writing to the log file. This is very, very easy to do. What you'll want to do is as soon as you detect an error has occurred, grab the error message before doing anything else. Then pass the error message to whatever logging routine you're using. E.g.:
Dim sMsg As String
On Error Goto ErrHandler
' ...code here...
Exit Function
ErrHandler:
sMsg = "Error #" & Err.Number & ": '" & Err.Description & "' from '" & Err.Source & "'"
GoLogTheError sMsg
BTW, thanks for your guys' answers helping me. I'm about half a decade late to the game of VB6. I don't do windows unless forced to. ;)
Anyhow, when doing your error checking, say among 3000 individual record query insertions, I learned a couple tricks. Consider this block of code:
'----- order number 1246-------
On Error Goto EH1246:
sSql="insert into SalesReceiptLine ( CustomerRefListID,TemplateRe..."
oConnection.Execute sSQL
sSql="SELECT TxnID FROM SalesReceiptLine WHERE RefNumber='1246'..."
oRecordset.Open sSQL, oConnection
sTxnId = oRecordset(0)
oRecordset.Close
sSql="INSERT INTO SalesReceiptLine (TxnId,SalesReceiptLineDesc,Sal..."
oConnection.Execute sSQL
EH1246:
IF Err.Number<>0 THEN
sMsg = sMsg & "Order # 1246; sTxnId = " & sTxnId & _
vbCrLf & Err.Number & ": " & Err.Description & vbCrLf
sErrOrders = sErrOrders & "1246,"
End If
On Error GoTo -1
'----- order number 1247-------
On Error Goto EH1247:
When not testing for Err.Number, you'll get a 0: on every order handled. (maybe you don't want that). The On Error GoTo -1 resets the error so that it will work again. Apparently, Err only works "once".
I wrote a php script to build the VB6 source code to run some 8000 odbc queries... :P
Do you definitely, positively have an Exit Function just above the Error_Handler:?
my method(......
On Error GoTo Error_Handler
........
Exit Sub
Error_Handler :
writeToLogFile(Err.Source,Err.Description)
"Exit Sub" should be added before you handle the Error_Handler function.....