Solved

Needs domain\username & password

Posted on 2011-03-16
3
457 Views
Last Modified: 2012-05-11
I'm having a permission problem to get the following script to work.Can someone fix the
script for me

eg strUsername = "domain\username"
     strPassword = "password"


strInputFile = "ComputerUsers.txt"

Dim objShell, objFSO, objInput, strComputer, strUser, objShortcut, strLine
Const ForReading = 1

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objInput = objFSO.OpenTextFile(strInputFile, ForReading, False)
While Not objInput.AtEndOfStream
      strLine = objInput.ReadLine
      If InStr(strLine, ":") > 0 Then
            strComputer = Split(strLine, ":")(0)
            strUser = Split(strLine, ":")(1)
            If Ping(strComputer) = True Then
                  If objFSO.FolderExists("\\" & strComputer & "\C$\Documents and Settings\" & strUser & "\Desktop") = True Then
                        Set objShortcut = objShell.CreateShortcut("\\" & strComputer & "\C$\Documents and Settings\" & strUser & "\Desktop\My_Documents.lnk")
                        objShortcut.Description = "Network Source File Storage"
                        objShortcut.TargetPath = "\\tyrenet-14\transfer\" & strUser & "\my_documents"
                        objShortcut.IconLocation = "C:\Windows\System32\shell32.dll, 19"
                        objShortcut.Save
                  End If
            End If
      End If
Wend
objInput.Close

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
0
Comment
Question by:Bianchi928
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 250 total points
ID: 35152715
Hi, you're not actually using the credentials.  Try this, which will map a drive to the IPC$ share of each computer as it goes.

Regards,

Rob.
strInputFile = "ComputerUsers.txt"
strLocalUser = "administrator"
strLocalPassword = "localpassword"

Dim objShell, objFSO, objInput, strComputer, strUser, objShortcut, strLine
Const ForReading = 1

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")

Set objInput = objFSO.OpenTextFile(strInputFile, ForReading, False)
While Not objInput.AtEndOfStream
	strLine = objInput.ReadLine
	If InStr(strLine, ":") > 0 Then
		strComputer = Split(strLine, ":")(0)
		strUser = Split(strLine, ":")(1)
		If Ping(strComputer) = True Then
			On Error Resume Next
			objNetwork.MapNetworkDrive "", "\\" & strComputer & "\IPC$", False, strLocalUser, strLocalPassword
			If objFSO.FolderExists("\\" & strComputer & "\C$\Documents and Settings\" & strUser & "\Desktop") = True Then
				Set objShortcut = objShell.CreateShortcut("\\" & strComputer & "\C$\Documents and Settings\" & strUser & "\Desktop\My_Documents.lnk")
				objShortcut.Description = "Network Source File Storage"
				objShortcut.TargetPath = "\\tyrenet-14\transfer\" & strUser & "\my_documents" 
				objShortcut.IconLocation = "C:\Windows\System32\shell32.dll, 19"
				objShortcut.Save 
			End If
			objNetwork.RemoveNetworkDrive "\\" & strComputer & "\IPC$", True, False
			If Err.Number <> 0 Then
				WScript.Echo "Error connecting to " & strComputer & VbCrLf & "Error " & Err.Number & ": " & Err.Description
				Err.Clear
			End If
			On Error GoTo 0
		End If
	End If
Wend
objInput.Close

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:Bianchi928
ID: 35153511
All good
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35153517
Glad to help. Thanks for the grade.

Rob.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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