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!

Handling Error When Authentication Is Incorrect 1

Status
Not open for further replies.

JustScriptIt

Technical User
Oct 28, 2011
73
0
0
US
Hello,

I am running a script to read a certain registry value on remote computers in the domain.

When I open command prompt, I right-click, select "Run as another user", and enter in the credentials.

The command prompt opens, I go to the directory with the script, and I type in

cscript scriptname.vbs

The script then prompts me for the filename with the list of computers, no problem, the script executes and outputs the values.

In the middle of execution, I get

"Microsoft VBScript runtime error: The remote
server machine does not exist or is unavailable: 'GetObject'"

Then, the execution terminates.

I believe this is because the credentials I entered are incorrect for one of the computers.

How do I handle the error such that

- It outputs an understandable error message
- The script continues execution
 
See the On Error instruction.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Seeing the source script would be useful....

I'm relatively new to scripting, but the error you're having could be caused as you suggested by lack of access but can also be caused, I believe, by the PC not being on the network. Again, without seeing source code, it's a little hard to diagnose.

To rule out the PC not being on the network though, I use a ping test to see if it's there and if so, perform the necessary code. Source for the ping function I use is:

Function Ping(PC)
Set objWshScriptExec = objShell.Exec("ping.exe -n 1 " & PC)
Set objStdOut = objWshScriptExec.StdOut
awake=False
Do Until objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine
awake = awake Or InStr(LCase(strLine), "bytes=") > 0
Loop
Ping = awake
End Function

The other thing I could suggest (depends on the policies of your workplace I guess) is running the script with an even higher level of access on your domain.

In my work environment for example, I only have admin rights to the PC's in one Org Unit, however, the local admin password on all desktops is the same. If I log into the command prompt as the local desktop administrator account, I can run my scripts across PC's I normally wouldn't have access to
 
Here's the original code

Code:
' Incomplete because it needs to include error handling in case of wrong credentials

Option Explicit

Dim objInputFSO, strInputFile, strData, arrLines, strLine
Dim strComputer, strKeyPath, strValueName, oReg, strValue

const HKEY_LOCAL_MACHINE = &H80000002

'Create a Input File System Object
Set objInputFSO = CreateObject("Scripting.FileSystemObject")

'name of the input text file
strInputFile = InputBox("What is the name of file with list of computers?")

'Open the text file - strData now contains the whole file
strData = objInputFSO.OpenTextFile(strInputFile,1).ReadAll

'Split the text file into lines
arrLines = Split(strData,vbCrLf)

'Step through the lines
For Each strLine in arrLines

  strComputer = strLine
  Set oReg=GetObject( _
   "winmgmts:{impersonationLevel=impersonate}!\\" &_
    strComputer & "\root\default:StdRegProv")

  strKeyPath = "SOFTWARE\Symantec\Symantec Endpoint Protection\SMC"
  strValueName = "ProductVersion"
  oReg.GetStringValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  Wscript.echo strLine & " " & "Current SEP Version: " & strValue 

Next

'Cleanup
Set objInputFSO=Nothing
 
Really appreciate the feedback!

Will incorporate the ping test and work on "on error
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top