Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - VB scripting help

Reply
 
Old 06-15-2008   #1 (permalink)
David Rodriguez


 
 

VB scripting help

Hello all,
I am working on part of a VB logon script. This script will have to run
when the user logs in and I think I got it to were it will read a text file
of all computers (44) from a text then the part that I need help with is to
check to see if the computer name is in the list, if so then start the file
copy process. (I got this part done too).

My code isn't close to complete.

Dim strComp

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\scripts\servers.txt", ForReading)

strText = objTextFile.ReadAll
objTextFile.Close

arrComputers = Split(strText, vbCrLf)

For Each strComputer in arrComputers

Set FSO =CreateObject("scripting.FileSystemObject")
FSO.CopyFolder "\\SVR1\D$\Install\SEP" ,"c:\SEP_Install"

Next
--


My System SpecsSystem Spec
Old 06-15-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: VB scripting help

David Rodriguez wrote:
Quote:

> I am working on part of a VB logon script. This script will have to run
> when the user logs in and I think I got it to were it will read a text
> file
> of all computers (44) from a text then the part that I need help with is
> to
> check to see if the computer name is in the list, if so then start the
> file
> copy process. (I got this part done too).
>
> My code isn't close to complete.
>
> Dim strComp
>
> Const ForReading = 1
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile _
> ("c:\scripts\servers.txt", ForReading)
>
> strText = objTextFile.ReadAll
> objTextFile.Close
>
> arrComputers = Split(strText, vbCrLf)
>
> For Each strComputer in arrComputers
>
> Set FSO =CreateObject("scripting.FileSystemObject")
> FSO.CopyFolder "\\SVR1\D$\Install\SEP" ,"c:\SEP_Install"
>
> Next
> --
>
You can retrieve the NetBIOS name of the local computer from the wshNetwork
object. Assuming your text file has the NetBIOS names of computers, one per
line, you could use code similar to:
============
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\scripts\servers.txt", ForReading)

strText = objTextFile.ReadAll
objTextFile.Close
arrComputers = Split(strText, vbCrLf)

Set objNetwork = CreateObject("Wscript.Network")
strLocalComputer = objNetwork.ComputerName

For Each strComputer in arrComputers
If (LCase(strComputer) = LCase(strLocalComputer)) Then
objFSO.CopyFolder "\\SVR1\D$\Install\SEP" ,"c:\SEP_Install"
Exit For
End If
Next
=======
No need to bind to objFSO a second time in the "For Each" loop. I used the
LCase function to make the comparison case insensitive. I exit the "For
Each" loop after the copy since there is no point considering other names.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 06-15-2008   #3 (permalink)
David Rodriguez


 
 

Re: VB scripting help

Sorry for bugging so soon, I have one question about the script, would I be
able to change the location of the text file?

Like from...
("c:\scripts\servers.txt", ForReading)

to ..
("\\svr1\netlogon\SEP_Install\servers.txt", ForReading)

I do appreciate you helping me with this.

--

"Richard Mueller [MVP]" wrote:
Quote:

> David Rodriguez wrote:
>
Quote:

> > I am working on part of a VB logon script. This script will have to run
> > when the user logs in and I think I got it to were it will read a text
> > file
> > of all computers (44) from a text then the part that I need help with is
> > to
> > check to see if the computer name is in the list, if so then start the
> > file
> > copy process. (I got this part done too).
> >
> > My code isn't close to complete.
> >
> > Dim strComp
> >
> > Const ForReading = 1
> >
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > Set objTextFile = objFSO.OpenTextFile _
> > ("c:\scripts\servers.txt", ForReading)
> >
> > strText = objTextFile.ReadAll
> > objTextFile.Close
> >
> > arrComputers = Split(strText, vbCrLf)
> >
> > For Each strComputer in arrComputers
> >
> > Set FSO =CreateObject("scripting.FileSystemObject")
> > FSO.CopyFolder "\\SVR1\D$\Install\SEP" ,"c:\SEP_Install"
> >
> > Next
> > --
> >
>
> You can retrieve the NetBIOS name of the local computer from the wshNetwork
> object. Assuming your text file has the NetBIOS names of computers, one per
> line, you could use code similar to:
> ============
> Const ForReading = 1
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile _
> ("c:\scripts\servers.txt", ForReading)
>
> strText = objTextFile.ReadAll
> objTextFile.Close
> arrComputers = Split(strText, vbCrLf)
>
> Set objNetwork = CreateObject("Wscript.Network")
> strLocalComputer = objNetwork.ComputerName
>
> For Each strComputer in arrComputers
> If (LCase(strComputer) = LCase(strLocalComputer)) Then
> objFSO.CopyFolder "\\SVR1\D$\Install\SEP" ,"c:\SEP_Install"
> Exit For
> End If
> Next
> =======
> No need to bind to objFSO a second time in the "For Each" loop. I used the
> LCase function to make the comparison case insensitive. I exit the "For
> Each" loop after the copy since there is no point considering other names.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>
My System SpecsSystem Spec
Old 06-16-2008   #4 (permalink)
David Rodriguez


 
 

Re: VB scripting help

I was able to test it with the UNC path and it worked just fine.

Thank you,
--
David Rodriguez
C & D Computer Consulting
www.networking-help.biz
602-578-4516


"David Rodriguez" wrote:
Quote:

> Sorry for bugging so soon, I have one question about the script, would I be
> able to change the location of the text file?
>
> Like from...
> ("c:\scripts\servers.txt", ForReading)
>
> to ..
> ("\\svr1\netlogon\SEP_Install\servers.txt", ForReading)
>
> I do appreciate you helping me with this.
>
> --
>
> "Richard Mueller [MVP]" wrote:
>
Quote:

> > David Rodriguez wrote:
> >
Quote:

> > > I am working on part of a VB logon script. This script will have to run
> > > when the user logs in and I think I got it to were it will read a text
> > > file
> > > of all computers (44) from a text then the part that I need help with is
> > > to
> > > check to see if the computer name is in the list, if so then start the
> > > file
> > > copy process. (I got this part done too).
> > >
> > > My code isn't close to complete.
> > >
> > > Dim strComp
> > >
> > > Const ForReading = 1
> > >
> > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > Set objTextFile = objFSO.OpenTextFile _
> > > ("c:\scripts\servers.txt", ForReading)
> > >
> > > strText = objTextFile.ReadAll
> > > objTextFile.Close
> > >
> > > arrComputers = Split(strText, vbCrLf)
> > >
> > > For Each strComputer in arrComputers
> > >
> > > Set FSO =CreateObject("scripting.FileSystemObject")
> > > FSO.CopyFolder "\\SVR1\D$\Install\SEP" ,"c:\SEP_Install"
> > >
> > > Next
> > > --
> > >
> >
> > You can retrieve the NetBIOS name of the local computer from the wshNetwork
> > object. Assuming your text file has the NetBIOS names of computers, one per
> > line, you could use code similar to:
> > ============
> > Const ForReading = 1
> >
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > Set objTextFile = objFSO.OpenTextFile _
> > ("c:\scripts\servers.txt", ForReading)
> >
> > strText = objTextFile.ReadAll
> > objTextFile.Close
> > arrComputers = Split(strText, vbCrLf)
> >
> > Set objNetwork = CreateObject("Wscript.Network")
> > strLocalComputer = objNetwork.ComputerName
> >
> > For Each strComputer in arrComputers
> > If (LCase(strComputer) = LCase(strLocalComputer)) Then
> > objFSO.CopyFolder "\\SVR1\D$\Install\SEP" ,"c:\SEP_Install"
> > Exit For
> > End If
> > Next
> > =======
> > No need to bind to objFSO a second time in the "For Each" loop. I used the
> > LCase function to make the comparison case insensitive. I exit the "For
> > Each" loop after the copy since there is no point considering other names.
> >
> > --
> > Richard Mueller
> > MVP Directory Services
> > Hilltop Lab - http://www.rlmueller.net
> > --
> >
> >
> >
My System SpecsSystem Spec
Old 06-16-2008   #5 (permalink)
David Rodriguez


 
 

Re: VB scripting help

Hey Richard,
How would I add this email portion to this script that you helped me with?
Just so you know I am running the script 2 times, because there are 2 SEP
servers that will handle different workstations. The email portion is just to
confirm that the workstation is ready for phase 2.


Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("\\svr2\NETLOGON\RemoteComp.txt", ForReading)

strText = objTextFile.ReadAll
objTextFile.Close
arrComputers = Split(strText, vbCrLf)

Set objNetwork = CreateObject("Wscript.Network")
strLocalComputer = objNetwork.ComputerName

For Each strComputer in arrComputers
If (LCase(strComputer) = LCase(strLocalComputer)) Then
objFSO.CopyFolder "\\SVR1\netlogon\Install\SEP" ,"c:\SEP_Install"
Exit For
End If
Next

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("\\svr2\NETLOGON\HoustonComp.txt", ForReading)

strText = objTextFile.ReadAll
objTextFile.Close
arrComputers = Split(strText, vbCrLf)

Set objNetwork = CreateObject("Wscript.Network")
strLocalComputer = objNetwork.ComputerName

For Each strComputer in arrComputers
If (LCase(strComputer) = LCase(strLocalComputer)) Then
objFSO.CopyFolder "\\SVR2\netlogon\Install\SEP" ,"c:\SEP_Install"
Exit For
End If
Next

Email portion that I would like added to the script..

Set objNet = CreateObject("WScript.Network")
strLocalComputer = objNet.ComputerName
strTime = time
strDate = date

schema = "http://schemas.microsoft.com/cdo/configuration/"
Set objEmail = CreateObject("CDO.Message")
With objEmail
..From = "SEP_Auto@xxxxxx"
..To = "david.rodriguez@xxxxxx"
..Subject = "Workstation " & strLocalComputer & " Has recieved the
SEP_Install files."
..Textbody = "Workstation " & strLocalComputer & " Have successfully recieved
the install files and is ready for Phase2 deployment. The current time is " &
strTime & " " & strDate
With .Configuration.Fields
..Item (schema & "sendusing") = 2
..Item (schema & "smtpserver") = "relay.123.com"
..Item (schema & "smtpserverport") = 25
..Item (schema & "smtpauthenticate") = cdoBasic
' .Item (schema & "sendusername") = "username"
' .Item (schema & "sendpassword") = "password"
End With
..Configuration.Fields.Update
..Send
End With

Thank you for all the help.

David

--
"Richard Mueller [MVP]" wrote:
Quote:

> David Rodriguez wrote:
>
Quote:

> > I am working on part of a VB logon script. This script will have to run
> > when the user logs in and I think I got it to were it will read a text
> > file
> > of all computers (44) from a text then the part that I need help with is
> > to
> > check to see if the computer name is in the list, if so then start the
> > file
> > copy process. (I got this part done too).
> >
> > My code isn't close to complete.
> >
> > Dim strComp
> >
> > Const ForReading = 1
> >
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > Set objTextFile = objFSO.OpenTextFile _
> > ("c:\scripts\servers.txt", ForReading)
> >
> > strText = objTextFile.ReadAll
> > objTextFile.Close
> >
> > arrComputers = Split(strText, vbCrLf)
> >
> > For Each strComputer in arrComputers
> >
> > Set FSO =CreateObject("scripting.FileSystemObject")
> > FSO.CopyFolder "\\SVR1\D$\Install\SEP" ,"c:\SEP_Install"
> >
> > Next
> > --
> >
>
> You can retrieve the NetBIOS name of the local computer from the wshNetwork
> object. Assuming your text file has the NetBIOS names of computers, one per
> line, you could use code similar to:
> ============
> Const ForReading = 1
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile _
> ("c:\scripts\servers.txt", ForReading)
>
> strText = objTextFile.ReadAll
> objTextFile.Close
> arrComputers = Split(strText, vbCrLf)
>
> Set objNetwork = CreateObject("Wscript.Network")
> strLocalComputer = objNetwork.ComputerName
>
> For Each strComputer in arrComputers
> If (LCase(strComputer) = LCase(strLocalComputer)) Then
> objFSO.CopyFolder "\\SVR1\D$\Install\SEP" ,"c:\SEP_Install"
> Exit For
> End If
> Next
> =======
> No need to bind to objFSO a second time in the "For Each" loop. I used the
> LCase function to make the comparison case insensitive. I exit the "For
> Each" loop after the copy since there is no point considering other names.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>
My System SpecsSystem Spec
Old 06-16-2008   #6 (permalink)
Pegasus \(MVP\)


 
 

Re: VB scripting help

Have a look at the item "Help emailing this script", posted
here a few minutes after yours. It deals with almost the
same subject.


"David Rodriguez" <DavidRodriguez@xxxxxx> wrote in
message news:BC45FCB1-2B82-40F6-9DE8-DB7789F7E36C@xxxxxx
Quote:

> Hey Richard,
> How would I add this email portion to this script that you helped me with?
> Just so you know I am running the script 2 times, because there are 2 SEP
> servers that will handle different workstations. The email portion is just
> to
> confirm that the workstation is ready for phase 2.
>
>
> Const ForReading = 1
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile _
> ("\\svr2\NETLOGON\RemoteComp.txt", ForReading)
>
> strText = objTextFile.ReadAll
> objTextFile.Close
> arrComputers = Split(strText, vbCrLf)
>
> Set objNetwork = CreateObject("Wscript.Network")
> strLocalComputer = objNetwork.ComputerName
>
> For Each strComputer in arrComputers
> If (LCase(strComputer) = LCase(strLocalComputer)) Then
> objFSO.CopyFolder "\\SVR1\netlogon\Install\SEP" ,"c:\SEP_Install"
> Exit For
> End If
> Next
>
> Const ForReading = 1
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile _
> ("\\svr2\NETLOGON\HoustonComp.txt", ForReading)
>
> strText = objTextFile.ReadAll
> objTextFile.Close
> arrComputers = Split(strText, vbCrLf)
>
> Set objNetwork = CreateObject("Wscript.Network")
> strLocalComputer = objNetwork.ComputerName
>
> For Each strComputer in arrComputers
> If (LCase(strComputer) = LCase(strLocalComputer)) Then
> objFSO.CopyFolder "\\SVR2\netlogon\Install\SEP" ,"c:\SEP_Install"
> Exit For
> End If
> Next
>
> Email portion that I would like added to the script..
>
> Set objNet = CreateObject("WScript.Network")
> strLocalComputer = objNet.ComputerName
> strTime = time
> strDate = date
>
> schema = "http://schemas.microsoft.com/cdo/configuration/"
> Set objEmail = CreateObject("CDO.Message")
> With objEmail
> .From = "SEP_Auto@xxxxxx"
> .To = "david.rodriguez@xxxxxx"
> .Subject = "Workstation " & strLocalComputer & " Has recieved the
> SEP_Install files."
> .Textbody = "Workstation " & strLocalComputer & " Have successfully
> recieved
> the install files and is ready for Phase2 deployment. The current time is
> " &
> strTime & " " & strDate
> With .Configuration.Fields
> .Item (schema & "sendusing") = 2
> .Item (schema & "smtpserver") = "relay.123.com"
> .Item (schema & "smtpserverport") = 25
> .Item (schema & "smtpauthenticate") = cdoBasic
> ' .Item (schema & "sendusername") = "username"
> ' .Item (schema & "sendpassword") = "password"
> End With
> .Configuration.Fields.Update
> .Send
> End With
>
> Thank you for all the help.
>
> David
>
> --
> "Richard Mueller [MVP]" wrote:
>
Quote:

>> David Rodriguez wrote:
>>
Quote:

>> > I am working on part of a VB logon script. This script will have to run
>> > when the user logs in and I think I got it to were it will read a text
>> > file
>> > of all computers (44) from a text then the part that I need help with
>> > is
>> > to
>> > check to see if the computer name is in the list, if so then start the
>> > file
>> > copy process. (I got this part done too).
>> >
>> > My code isn't close to complete.
>> >
>> > Dim strComp
>> >
>> > Const ForReading = 1
>> >
>> > Set objFSO = CreateObject("Scripting.FileSystemObject")
>> > Set objTextFile = objFSO.OpenTextFile _
>> > ("c:\scripts\servers.txt", ForReading)
>> >
>> > strText = objTextFile.ReadAll
>> > objTextFile.Close
>> >
>> > arrComputers = Split(strText, vbCrLf)
>> >
>> > For Each strComputer in arrComputers
>> >
>> > Set FSO =CreateObject("scripting.FileSystemObject")
>> > FSO.CopyFolder "\\SVR1\D$\Install\SEP" ,"c:\SEP_Install"
>> >
>> > Next
>> > --
>> >
>>
>> You can retrieve the NetBIOS name of the local computer from the
>> wshNetwork
>> object. Assuming your text file has the NetBIOS names of computers, one
>> per
>> line, you could use code similar to:
>> ============
>> Const ForReading = 1
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> Set objTextFile = objFSO.OpenTextFile _
>> ("c:\scripts\servers.txt", ForReading)
>>
>> strText = objTextFile.ReadAll
>> objTextFile.Close
>> arrComputers = Split(strText, vbCrLf)
>>
>> Set objNetwork = CreateObject("Wscript.Network")
>> strLocalComputer = objNetwork.ComputerName
>>
>> For Each strComputer in arrComputers
>> If (LCase(strComputer) = LCase(strLocalComputer)) Then
>> objFSO.CopyFolder "\\SVR1\D$\Install\SEP" ,"c:\SEP_Install"
>> Exit For
>> End If
>> Next
>> =======
>> No need to bind to objFSO a second time in the "For Each" loop. I used
>> the
>> LCase function to make the comparison case insensitive. I exit the "For
>> Each" loop after the copy since there is no point considering other
>> names.
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Registry scripting VB Script
Re: batch scripting VB Script
Scripting question Vista General
UAC and scripting Vista General
Scripting bug? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46