Line: 4
Char: 1
Error: 0x80041021
Code: 80041021
Source: (null)
Anyone know what's causing this error? Here's the code for my inputbox:
dim objProcess, strComputer, strProcess
strComputer = InputBox("Enter computer name or IP address", "Identify PC to
receive GPupdate /force")
Set objProcess = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
_
strComputer & "\root\cimv2:Win32_Process")
Dim intResult, intProcessID
intResult = objProcess.Create("gpupdate /force", null, null, intProcessID)
MsgBox"GPupdate has completed on the machine you
specified",vbInformation,"GPupdate Complete!"
This is one of the problems with the InputBox function. If the user clicks
"cancel" the function returns a zero-length string, so you have to check for
that before proceeding. The problem is that you don't know if the user
clicked "cancel" or just left the textbox blank and clicked "OK". The result
is the same. You'd be better off creating your own input form.
--
Björn Holmgren
Sorry! Forgot this is a scripting NG. Just forget the part about creating a
custom input form.
--
Björn Holmgren
You'll see that:
If the user clicks OK or presses ENTER, the InputBox function returns whatever is in the text box. If the user clicks Cancel, the function returns a zero-length string ("").
You need to verify the value of strComputer before calling GetObject
Keith
"D.P. Roberts" <dpro...@pbride.com> wrote in message news:eoxTZP4K...@TK2MSFTNGP14.phx.gbl...
Dim vResponse
vResponse = InputBox("Enter Name:", "Data Entry")
If IsEmpty(vResponse) Then
MsgBox "No data entered", vbExclamation, "Cancel Pressed"
ElseIf Len(vResponse) = 0 Then
MsgBox "Ah! The man with no name.", vbInformation, "OK pressed"
Else
MsgBox "Greetings '" & vResponse & "'.", vbInformation, "OK pressed"
End If
--
Joe (MVP)
Interesting. In VB, Inputbox always returns a zero-length string, even when
cancel is pressed. I had assumed it would be the same in VBScript, but
obviously not. I've learned something new. Thanx for that, Joe!
--
Björn Holmgren
If strComputer = vbNullString Then
wscript.quit(1)
End If
"Keith Miller" <k.mil...@verizon.net> wrote in message
news:e4KmDP5K...@TK2MSFTNGP10.phx.gbl...
EXAMPLE:
usrSelect = InputBox("Select a number:" & VbCrLf & _
VbCrLf & "1. Option 1" & _
VbCrLf & "2. Option 2" & _
VbCrLf & "3. Option 3", strScriptName," ")
If usrSelect = vbNullString then
MsgBox "CANCEL was selected.", vbOKOnly, strScriptName
WScript.Quit
ElseIf trim(usrTermSelect) = "" Then
MsgBox "Please enter a value before clicking OK.", vbOKOnly,
strScriptName
Else
Select Case usrTermSelect
Case 1
Case 2
Case 3
Case Else 'for all out of range values
MsgBox "Invalid selection. Please try again.", vbOKOnly, strScriptName
End Select
End If
END EXAMPLE
The key to this is the space character that is used as default text for the
input box. Technically, having anything in the input box as a default
(including out of range values, or a special string such as "DEFAULT") can
help with this situation as you can check to see if the default has been
changed. If not, then the user likely did not enter anything before
clicking OK. However, if you are looking to have no visible text in the
input box, use the method above. It will only put a space character in the
input area of the dialog box, although the space will be highlighted for
selection. If CANCEL is selected, then a null string is returned. If OK is
selected without the user entering anything, then the space character is
returned (not an empty string).
The line:
ElseIf trim(usrTermSelect) = "" Then
could easily be replaced with:
ElseIf usrTermSelect = " " Then
or this:
ElseIf usrTermSelect = "default" Then
if you choose the default text to be "default" as in the following:
usrSelect = InputBox("Select a number:" & VbCrLf & _
VbCrLf & "1. Option 1" & _
VbCrLf & "2. Option 2" & _
VbCrLf & "3. Option 3", strScriptName, "default")
Hope this helps!