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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need Windows exit codes after running cmd command in vbscript

Status
Not open for further replies.

Associate_Engineer

Systems Engineer
Jul 9, 2019
3
US
The only thing I can return is basically a "true/false aka a 1 or 0"

I need the windows error codes such as:
1787 The security database on the server does not have a computer account for this workstation trust relationship.
1326 Logon failure: unknown user name or bad password.

runCmd ="runas /profile /user:DOMAIN\" & userName & " notepad"
retResults = WshShell.Run (runCmd,1,True)
If retResults <> 0 Then
usrName.value = ""​
MsgBox "error: " & (retResults)​
End If
 
Have a look at the Exec method rather than the Run method.
 
@strongm Can you elaborate a little more or show me an example on you to re-write my code to implement this Exec.
Thanks in advance.
 
Here is my code atm. I can not figure out how to implement Exec as you suggested....

<HEAD>
<TITLE>IT - Cache Credentials</TITLE>
<HTA:APPLICATION
icon="e-icon-new-round.ico"
ID="InstallApps"
BORDER="thin"
CAPTION="yes"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SCROLL="yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
</HEAD>
<hta:application icon="e-icon.ico" />

<script language="VBScript">

ON ERROR RESUME Next

Set WshShell = CreateObject("WScript.Shell")
Set objExplorer = CreateObject ("InternetExplorer.Application")
Set fso = CreateObject("scripting.filesystemobject")

'_______________________________________________________________________________________
'Resize the window when the app starts
'_______________________________________________________________________________________
Sub window_onload
centerWindow
usrName.focus()
End Sub

'_______________________________________________________________________________________
'Center and size the window
'_______________________________________________________________________________________
sub centerWindow
window.resizeTo 600,675
window.moveTo (screen.width - 600) / 2, (screen.height - 675) /2
End sub

'_______________________________________________________________________________________
'Closes the application if the Exit button is clicked
'_______________________________________________________________________________________
sub killApp
If fso.FileExists ("c:\Cache Credentials.lnk") Then
fso.DeleteFile ("c:\Cache Credentials.lnk")
End If
window.close
End sub

'_______________________________________________________________________________________
'Runas command to cache credentials.
'_______________________________________________________________________________________
Sub cacheCreds
On Error Resume Next
Err.Clear

userName = usrName.value

If userName = "" Then
MsgBox ("Error: Username and password are required")
Exit Sub
End If

If Right(Left(userName,4),1) = "\" Then
userName = Mid(userName,5,(Len(userName)))
usrName.value = userName
End If

runCmd ="runas /profile /user:DOMAIN\" & userName & " notepad"
retResults = WshShell.Run (runCmd,1,True)

If retResults <> 0 Then
MsgBox ("Incorrect password, please try again.")
usrName.value = ""
MsgBox "error: " & (retResults)
Exit Sub
End If

killApp
End Sub
</script>

<body bgcolor="#f1f2f2">
<font color = "black">
<font size ="4" face = "arial"><center><u><b>Cache Domain Credentials<br><br></b></u></font>
<font size ="2" face = "arial"><b>You must be connected to the internal network either at an office or with VPN before you continue.</b></font size face = "arial"></center></b><br><hr>
<font size ="2" face = "arial">Enter your domain username and password and then click continue. Do not enter the DOMAIN\ prefix before your username. After you click continue, you will be prompted again for your password.<br><br></font>
<font size ="2" face = "arial"><left>Domain Username: <br>
<input type="textbox" name="usrName"><br>
<br>
<input type="image" src="continue.gif" name="next_event" onClick="cacheCreds">
<input type="image" src="cancel.gif" name="run_button" onClick="killApp">
</font>
</body>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top