/build/static/layout/Breadcrumb_cap_w.png

Script doesn't complete?

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

Answers (6)

Posted by: aogilmor 13 years ago
9th Degree Black Belt
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
Posted by: Meic 13 years ago
Second Degree Blue Belt
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.
Posted by: anonymous_9363 13 years ago
Red Belt
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"

Posted by: aogilmor 13 years ago
9th Degree Black Belt
0
vb, I can't believe you let him get away with hardcoded paths [font="courier new"]"C:\Progra~1\UserForm\ver1c\WinApp1.exe"
[;)]
Posted by: Meic 13 years ago
Second Degree Blue Belt
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"]
Posted by: anonymous_9363 13 years ago
Red Belt
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...
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ