Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script not completing

Status
Not open for further replies.

Meical

Technical User
Nov 13, 2007
3
GB
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?


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 following
msgbox "done."
oShell.Run "C:\Progra~1\applayer\App2.lnk"

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.

Thanks.
 
[tt]If Err.Number<>0 then
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

[red]Else[/red]
'If no errors I want it to run following
msgbox "done."
oShell.Run "C:\Progra~1\applayer\App2.lnk"
[red]End If[/red]
[/tt]
 
Thanks for your reply, you may not have read the last bit. I said in the bottom of my first message, the script doesn't pick up error number "80070035" for some weird reason. So I cannot use that code.



"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.
 
No reason not to pick up. Only possibility is that it picks up something else. Why don't you echo out the error as the first line within the if-end if.
[tt]
If Err.Number<>0 then
wscript.echo hex(err.number)
'etc etc
End If
[/tt]
 
Tsuji - thanks for your post - great idea. Even though when I run it manually, it came up with error 80070035, but when I put echo on script, it came woth different number! So I then just changed the error number on the code. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top