Hi,

I have the following code, where user gets added to local domain admin if required.

If there are errors i.e. User already local admin, or user not on domain, I need it to display the relevant error message (this bit works).

If there are no errors, I just want it to run the bottom line i.e. oShell.Run "C:\Progra~1\applayer\App2.lnk".

The problem I'm having is that the script doesn't run the bottom 2 lines, if there are no errors it just quits. Can anyone see where I'm going wrong?

Thanks.


On error resume next
Set oShell = CreateObject("WScript.Shell")
strComputer = "."
Set objArgs = WScript.Arguments
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
Set objUser = GetObject("WinNT://domain/" & objArgs(0))

objGroup.Add(objUser.ADsPath)
If Err.Number <> 0 Then
If Hex(Err.Number) = "80070562" Then
MsgBox "Username already added - Re enter Username"
Else
MsgBox "User not on Domain - Re enter Username"
End If
oShell.Run "C:\Progra~1\UserForm\ver1c\WinApp1.exe"

End if
'If no errors I want it to run the following - this is the bit that doesn't work:
msgbox "done."
oShell.Run "C:\Progra~1\applayer\App2.lnk"
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
Right off hand I see a couple of problems with this. You use hard coded short paths, and you don't confirm or error check the existence of the EXE or the .lnk file

Look in script56.chm for ways to derive the ProgramFiles folder.

To check for a file's existence the pseudocode is

If FileExists("WinApp1.exe") Then
Run Winapp1.exe
End If

same for the link file
Answered 12/12/2007 by: aogilmor
Ninth Degree Black Belt

Please log in to comment
0
Hi,

Thanks for your reply - this is just a draft for the time being.

I would just like to add that I have tried the following code:

If Hex(Err.Number) = "80070562" Then
MsgBox "Username already added - Re enter Username"
oShell.Run "C:\Progra~1\UserForm\ver1c\WinApp1.exe"
End If

If Hex(Err.Number) = "80070035" Then
MsgBox "User not on Domain - Re enter Username"
oShell.Run "C:\Progra~1\UserForm\ver1c\WinApp1.exe"
End If

'If no errors I want it to run following
msgbox "done."
oShell.Run "C:\Progra~1\applayer\App2.lnk"

But for some reason, the script doesn't pick up error code "80070035" (as a test, I just had that error number checked - still doesn't do it). That is why I have the script the way it is.
Answered 12/12/2007 by: Meic
Second Degree Blue Belt

Please log in to comment
0
First, it's inefficient to use multiple 'If' constructs. Use 'Select Case' instead. Next, numbers aren't strings: remove the quotes. Lastly, you need to prefix the number with the 'hex' prefix:

[font="courier new"]Dim strMsg
strMsg = " re-enter the user name"

Select Case Hex(Err.Number)
Case &H80070562
MsgBox "Username already added -" & strMsg
Case &H80070035
MsgBox "User not on Domain -" & strMsg
Case Else
MsgBox "Some generic error message
'// Possible exit from this routine or function
End Select

oShell.Run "C:\Progra~1\UserForm\ver1c\WinApp1.exe"

Answered 12/13/2007 by: VBScab
Red Belt

Please log in to comment
0
vb, I can't believe you let him get away with hardcoded paths [font="courier new"]"C:\Progra~1\UserForm\ver1c\WinApp1.exe"
[;)]
Answered 12/13/2007 by: aogilmor
Ninth Degree Black Belt

Please log in to comment
0
Thanks for your advice - I will take on board.

Just so you know, so I could check error number, I entered following code. For some strange reason it showed different error number from when I ran it manually. That seemed to be half the problem:

[font="courier new"]If Err.Number<>0 then
wscript.echo hex(err.number)
'etc etc
End If
[font="courier new"]
Answered 12/13/2007 by: Meic
Second Degree Blue Belt

Please log in to comment
0
ORIGINAL: aogilmor

vb, I can't believe you let him get away with hardcoded paths [font="courier new"]"C:\Progra~1\UserForm\ver1c\WinApp1.exe"
[;)]
Slowly, slowly...
Answered 12/14/2007 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity