locked
Vbcript to verify the local administrator password in remote server is set to correct RRS feed

  • General discussion

  • Hi ,

    I have a script ready to verify the localadmin password of the server set to correct or not. But the script which I have only works on local machine.

    I am not too good in scripting. Can anyone help me to correct the script, so that the script can run against remote server and output will store in another file ?

    Set fso = CreateObject("Scripting.FileSystemObject")
     Set WshNetwork = WScript.CreateObject("WScript.Network")
     
     username = "Administrator"
     password = "Password"
     objComput = WshNetwork.ComputerName

    wscript.echo objcomput
     

     on error resume next
     WshNetwork.MapNetworkDrive "R:", "\\" & objComput & "\C$",false, objComput & "\" & username, password
     
     If fso.FolderExists("R:\Windows") Then 
         wscript.echo "Credentials OK"
     Else
         Wscript.Echo "Credentials Bad"
     End If
    WshNetwork.RemoveNetworkDrive "R:"

    • Changed type Shalton Tuesday, February 9, 2016 6:53 AM
    Sunday, February 7, 2016 5:22 PM

All replies

  • just change the computer name


    \_(ツ)_/

    Sunday, February 7, 2016 6:08 PM
  • I have given like below. But I am not getting any proper output

         

    Set fso = CreateObject("Scripting.FileSystemObject")
     Set WshNetwork = WScript.CreateObject("WScript.Network")

     username = "Administrator"
     password = "Password"
     strSourceFile = "c:\servers.txt"
    ' strOutputFile = "c:\Admincheck.txt"

    wscript.echo objcomput

     on error resume next
     WshNetwork.MapNetworkDrive "R:", "\\" & strSourceFile & "\C$",false, strSourceFile & "\" & 

    username, password

     If fso.FolderExists("R:\Windows") Then 
         wscript.echo "Credentials OK"
     Else
         Wscript.Echo "Credentials Bad"
     End If

    output.WriteLine "Hostname,Credential Status"                            WshNetwork.RemoveNetworkDrive "R:"


    • Edited by Shalton Sunday, February 7, 2016 6:26 PM
    Sunday, February 7, 2016 6:16 PM
  • That is a file name and not a computer name.

    Yu need to start by learning how to use Windows and how basic computers work.  A computer name is a string that identifies a computer on a network. You cannot use a file name for a computer name.

    Ask you network administrator what the name of the computer is and use that.


    \_(ツ)_/

    Sunday, February 7, 2016 6:21 PM
  • I want the script to run on multiple remote servers a a time and get the output in ext file.

    Could you be able to help me to correct this ?

    Sunday, February 7, 2016 6:28 PM
  • You canot use a filename.

    Start here: https://technet.microsoft.com/en-us/scriptcenter/dd772284

    You need to learn how to use VBScript to read files and process things in a loop.


    \_(ツ)_/

    Sunday, February 7, 2016 6:39 PM
  • Some how I manged to write a vbscript. But it is throwing error.

    Can anyone help me to fix this error please.

    Option Explicit

    Dim strComputer,objOutputFile,Result,objSourceFile,objFSO,Username,Password,strSourceFile
    Dim strOutputFile,ForReading,WshNetwork
    Dim objShell, objShellExecute
    Dim strCommand, strOutput, strEventMessage

     username = "Administrator"
     password = "Password12"
     strSourceFile = "c:\servers.txt"
     strOutputFile = "c:\Admincheck.txt"

    Call ReadSourceFile(strSourceFile, strOutputFile)

    Public Function ReadSourceFile(strSourceFile, strOutputFile)

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objSourceFile = objFSO.OpenTextFile(strSourceFile, ForReading)
     Set WshNetwork = WScript.CreateObject("WScript.Network")
     
     Do Until objSourceFile.AtEndOfStream
    strComputer = UCase(objSourceFile.ReadLine)


     If VerifyConnectivity(strComputer, strOutputFile) Then
      
     Call RecordEvent(strEventMessage, strOutputFile)
     End If
     Loop

     Set objSourceFile = Nothing
     Set objFSO = Nothing
     Set Password = Nothing
    End Function

    Public Function VerifyConnectivity(strComputer, strOutputFile)

     
     VerifyConnectivity = False
     strCommand = "%comspec% /c ping -l 0 -n 2 -w 1500 " & strComputer & ""
     
     Set objShell = CreateObject("Wscript.Shell")
     Set objShellExecute = objShell.Exec(strCommand)
     
     Do Until objShellExecute.StdOut.AtEndOfStream
     strOutput = objShellExecute.StdOut.ReadAll

     If InStr(strOutput, "Reply") > 0 Then
     VerifyConnectivity = True
     Else
     VerifyConnectivity = False
     strEventMessage = strComputer & ",Unable to connect to system"
     Call RecordEvent(strEventMessage, strOutputFile)
     End If
     Loop
     
     Set objShellExecute = Nothing
     Set objShell = Nothing
    End Function

     on error resume next
     WshNetwork.MapNetworkDrive "R:", "\\" & strSourceFile & "\C$",false, strSourceFile & "\" & 

    username, password
     
     If fso.FolderExists("R:\Windows") Then 
         wscript.echo "Credentials OK"
         Result = "OK"
     Else
         Wscript.Echo "Credentials Bad"
         Result = "Bad"
     
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
     
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objOutputFile = objFSO.OpenTextFile(strOutputFile, ForAppending, True)
    objOutputFile.WriteLine(strComputer & Result)
    WScript.Echo(strComputer & Result)

    'WshNetwork.RemoveNetworkDrive "R:"
     End If
    Tuesday, February 9, 2016 6:22 AM
  • When you copied that you didn't copy all of it. It is missing a valid function.


    \_(ツ)_/

    Tuesday, February 9, 2016 6:29 AM
  • As you can see, copy and paste programming combined with guesswork is not an effective way to arrive at a solution.

    -- Bill Stewart [Bill_Stewart]

    Tuesday, February 9, 2016 3:32 PM
  • As you can see, copy and paste programming combined with guesswork is not an effective way to arrive at a solution.

    -- Bill Stewart [Bill_Stewart]

    You mean most of the IT populous are not fit for work? SHOCKER.
    Tuesday, February 9, 2016 3:46 PM
  • We often see posts here that contain a jumble of pasted code. Pasting a jumble of code does not really qualify as a "here's what I tried," because the poster really doesn't understand the jumble of code they posted. The poster is hoping that someone can somehow figure out what they want and rewrite the jumble of code for them into working code.

    Why is this a problem?

    1. The original poster isn't learning anything, because someone else is writing the code for them.

    2. It is not respectful of others' time. ("Here's a mess of code. I don't know how it works, but I have kind of an idea of what I want to do. Can someone write a working script for me?")

    Rewriting code for others based on vague specifications is not the purpose of this forum.

    That said, however, there is a script request form here:

    https://gallery.technet.microsoft.com/scriptcenter/site/requests

    However, I would recommend that if you post a script request here, you do a very thorough and specific job specifying the requirements. As with this forum, there is no guarantee that someone will have the time to write the code for you. In the long term, it's better to just learn how to do it yourself.


    -- Bill Stewart [Bill_Stewart]

    Tuesday, February 9, 2016 4:12 PM