Solved

VBS script to connect via IPC and return "correct" or "failed" password

Posted on 2008-06-16
3
851 Views
Last Modified: 2010-04-21
I need to run a script that will tell me:
1 is the computer on and responding to IPC queries?
2 "is this username/password' I'm using valid?


Why?
I can get serials from computer that are on and I have the password to, the rest fail (of course)
The script I want to write will tell me if I'm looking for a turned off computer or do I need to find the correct password?


BTW: I don't need this really written *for* me, just need the code snippets and/or Google search terms to help me find what I'm missing:
Is this computer responding? (do I need to find its last logon, has it logged in)
Is my password wrong?  (error code and what the heck to do with one)

On Error Resume Next

set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.AppActivate("excel")
 

'file output

Set fs = CreateObject("Scripting.FileSystemObject")

Set a = fs.CreateTextFile("c:\Documents and Settings\All Users\Desktop\SERIALS.CSV", True)
 
 

Computers = Array("comp1","comp2")

For Each Computer in Computers

winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& Computer &""

'WScript.Echo winmgmt1

Set SNSet = nothing

Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")

for each SN in SNSet

REM	MsgBox "The serial number for the specified computer is: " & Computer & SN.SerialNumber

REM    WshShell.Sendkeys (Computer)

REM    WshShell.Sendkeys ("{tab}")

REM    WshShell.Sendkeys (SN.SerialNumber)

REM    WshShell.Sendkeys ("{ENTER}")
 

' Output

a.Writeline (Computer)&","& (SN.SerialNumber)

Next

Next

Open in new window

0
Comment
Question by:TechniMemphis
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 250 total points
ID: 21797705
Hi, try this. For requirement a) I've added a Ping function.
For requirement b) I've added an error check on the WMI connection....

Regards,

Rob.
On Error Resume Next

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.AppActivate("excel")

 

'file output

Set fs = CreateObject("Scripting.FileSystemObject")

Set a = fs.CreateTextFile("c:\Documents and Settings\All Users\Desktop\SERIALS.CSV", True)
 

Computers = Array("comp1","comp2")

For Each Computer In Computers

	If Ping(Computer) = True Then

		On Error Resume Next

		winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& Computer &""

		If Err.Number <> 0 Then

			MsgBox "Error connecting to " & Computer & VbCrLf & "Error: " & Err.Number & VbCrLf "Description: " & Err.Description

			Err.Clear

		Else

			Err.Clear

			On Error GoTo 0

			'WScript.Echo winmgmt1

			Set SNSet = Nothing

			Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")

			For Each SN In SNSet

				REM	MsgBox "The serial number for the specified computer is: " & Computer & SN.SerialNumber

				REM    WshShell.Sendkeys (Computer)

				REM    WshShell.Sendkeys ("{tab}")

				REM    WshShell.Sendkeys (SN.SerialNumber)

				REM    WshShell.Sendkeys ("{ENTER}")
 

				' Output

				a.Writeline (Computer)&","& (SN.SerialNumber)

			Next

		End If

	Else

		MsgBox Computer & " failed to respond to ping."

	End If

Next
 

Function Ping(strComputer)

	Dim objShell, boolCode

	Set objShell = CreateObject("WScript.Shell")

	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)

	If boolCode = 0 Then

		Ping = True

	Else

		Ping = False

	End If

End Function

Open in new window

0
 

Author Closing Comment

by:TechniMemphis
ID: 31467647
Absolutely perfect!!
Made a couple changes for my situation and it worked like a charm!
Thank you!
Chad

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 21818074
No problem. Thanks for the grade.

Regards,

Rob.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Call VB Script silently for 2 batch files 7 43
Vb script to unzip a files and rename the files 12 96
Script is being strange 8 63
Problem to open text file 11 70
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now