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 - Sending computer name to txt file if file didnt copy?

Reply
 
Old 08-26-2008   #1 (permalink)
Carito


 
 

Sending computer name to txt file if file didnt copy?

Not sure if that is confusing. I got some vb code from another post here but
want to make it dom some extra stuff that I dont know how to handle.
Basically it reads a list of computer names from a text file then copies a
file (ie shortcut in this case) to each of those remote computer's desktops.

Problem I have is if the computer is turned off or inaccessible for whatever
reason, I dont have any way of knowing it since the vb error that might pop
up doesnt reference the computer name and there is no log file created.

So basically I just want to have it create a log file and enter in the names
of the computers based on what it pulled from the text file and indicate
whether it was successful or not. Not sure how easy that is. Can someone help?

Here is the code so far that works.
'On Error Resume Next

Const ForReading = 1
Const OverwriteExisting = True

Set objFSO = CreateObject("Scripting.FileSystemObject")
'Read from file list name and location
Set objFile = objFSO.OpenTextFile("C:\mob.txt")
Do Until objFile.AtEndOfStream
strComputer = objFile.ReadLine

'Amend text name and set path to remote location
strRemoteFile = "\\" & strComputer & "\C$\Documents and Settings\All
Users\Desktop\New Icon.url"
'File to Copy
objFSO.CopyFile "C:\3M MNO.url", strRemoteFile, OverwriteExisting

Loop






My System SpecsSystem Spec
Old 08-26-2008   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: Sending computer name to txt file if file didnt copy?


"Carito" <Carito@xxxxxx> wrote in message
news:71D6D242-CD00-4214-9467-98EB49D82848@xxxxxx
Quote:

> Not sure if that is confusing. I got some vb code from another post here
> but
> want to make it dom some extra stuff that I dont know how to handle.
> Basically it reads a list of computer names from a text file then copies a
> file (ie shortcut in this case) to each of those remote computer's
> desktops.
>
> Problem I have is if the computer is turned off or inaccessible for
> whatever
> reason, I dont have any way of knowing it since the vb error that might
> pop
> up doesnt reference the computer name and there is no log file created.
>
> So basically I just want to have it create a log file and enter in the
> names
> of the computers based on what it pulled from the text file and indicate
> whether it was successful or not. Not sure how easy that is. Can someone
> help?
>
> Here is the code so far that works.
> 'On Error Resume Next
>
> Const ForReading = 1
> Const OverwriteExisting = True
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> 'Read from file list name and location
> Set objFile = objFSO.OpenTextFile("C:\mob.txt")
> Do Until objFile.AtEndOfStream
> strComputer = objFile.ReadLine
>
> 'Amend text name and set path to remote location
> strRemoteFile = "\\" & strComputer & "\C$\Documents and Settings\All
> Users\Desktop\New Icon.url"
> 'File to Copy
> objFSO.CopyFile "C:\3M MNO.url", strRemoteFile, OverwriteExisting
>
> Loop
You need to make your scripts a little more robust. Instead of assuming that
all will go well, assume that it won't and deal with these cases
accordingly. This modified version of your script will inform you if there
is a problem with your CopyFile method (ANY problem, not just a target PC
that cannot be reached!).

You should also close your files when you're finished with them.

Const ForReading = 1
Const OverwriteExisting = True

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Read from file list name and location
Set objFile = objFSO.OpenTextFile("C:\mob.txt")
Do Until objFile.AtEndOfStream
strComputer = objFile.ReadLine

'Append text name and set path to remote location
strRemoteFile = "\\" & strComputer & "\C$\Documents and Settings\All
Users\Desktop\New Icon.url"
'File to Copy
On Error Resume Next
objFSO.CopyFile "C:\3M MNO.url", strRemoteFile, OverwriteExisting
If Err.number > 0 then WScript.Echo "Problem with COPY command on """ &
strComputer & """."
On Error Goto 0
Loop
objFile.Close


My System SpecsSystem Spec
Old 08-26-2008   #3 (permalink)
Owen Gilmore


 
 

Re: Sending computer name to txt file if file didnt copy?

On Aug 26, 2:55*pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:
Quote:

> "Carito" <Car...@xxxxxx> wrote in message
>
> news:71D6D242-CD00-4214-9467-98EB49D82848@xxxxxx
>
>
>
>
>
Quote:

> > Not sure if that is confusing. I got some vb code from another post here
> > but
> > want to make it dom some extra stuff that I dont know how to handle.
> > Basically it reads a list of computer names from a text file then copies a
> > file (ie shortcut in this case) to each of those remote computer's
> > desktops.
>
Quote:

> > Problem I have is if the computer is turned off or inaccessible for
> > whatever
> > reason, I dont have any way of knowing it since the vb error that might
> > pop
> > up doesnt reference the computer name and there is no log file created.
>
Quote:

> > So basically I just want to have it create a log file and enter in the
> > names
> > of the computers based on what it pulled from the text file and indicate
> > whether it was successful or not. Not sure how easy that is. Can someone
> > help?
>
Quote:

> > Here is the code so far that works.
> > 'On Error Resume Next
>
Quote:

> > Const ForReading = 1
> > Const OverwriteExisting = True
>
Quote:

> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > 'Read from file list name and location
> > Set objFile = objFSO.OpenTextFile("C:\mob.txt")
> > Do Until objFile.AtEndOfStream
> > * *strComputer = objFile.ReadLine
>
Quote:

> > 'Amend text name and set path to remote location
> > strRemoteFile = "\\" & strComputer & "\C$\Documents and Settings\All
> > Users\Desktop\New Icon.url"
> > 'File to Copy
> > * *objFSO.CopyFile "C:\3M MNO.url", strRemoteFile, OverwriteExisting
>
Quote:

> > Loop
>
> You need to make your scripts a little more robust. Instead of assuming that
> all will go well, assume that it won't and deal with these cases
> accordingly. This modified version of your script will inform you if there
> is a problem with your CopyFile method (ANY problem, not just a target PC
> that cannot be reached!).
>
> You should also close your files when you're finished with them.
>
> Const ForReading = 1
> Const OverwriteExisting = True
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
>
> 'Read from file list name and location
> Set objFile = objFSO.OpenTextFile("C:\mob.txt")
> Do Until objFile.AtEndOfStream
> * * strComputer = objFile.ReadLine
>
> *'Append text name and set path to remote location
> *strRemoteFile = "\\" & strComputer & "\C$\Documents and Settings\All
> Users\Desktop\New Icon.url"
> *'File to Copy
> *On Error Resume Next
> *objFSO.CopyFile "C:\3M MNO.url", strRemoteFile, OverwriteExisting
> *If Err.number > 0 then WScript.Echo "Problem with COPY command on """ &
> strComputer & """."
> *On Error Goto 0
> Loop
> objFile.Close- Hide quoted text -
>
> - Show quoted text -
I also suspect that hard coding in a c$ share, and a "documents and
settings\all users" path is probably not the best way to go about it.
There must be some way to resolve and localize the %ALLUSERSPROFILE%
environment variable and key off of that.

If all you're trying to do is copy a shortcut I'd be tempted to create
a wise script or an MSI to do it. Lots easier than wrestling with VB
Script.
-OG
My System SpecsSystem Spec
Old 08-27-2008   #4 (permalink)
Carito


 
 

Re: Sending computer name to txt file if file didnt copy?

Thanks for the help guys. I'll give it a try. Pretty new to this. I'll also
look intot he MSI etc suggestion. Never had to push out something to close to
150 computers and dont have access to AD to do it that way.

"Owen Gilmore" wrote:
Quote:

> On Aug 26, 2:55 pm, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:
Quote:

> > "Carito" <Car...@xxxxxx> wrote in message
> >
> > news:71D6D242-CD00-4214-9467-98EB49D82848@xxxxxx
> >
> >
> >
> >
> >
Quote:

> > > Not sure if that is confusing. I got some vb code from another post here
> > > but
> > > want to make it dom some extra stuff that I dont know how to handle.
> > > Basically it reads a list of computer names from a text file then copies a
> > > file (ie shortcut in this case) to each of those remote computer's
> > > desktops.
> >
Quote:

> > > Problem I have is if the computer is turned off or inaccessible for
> > > whatever
> > > reason, I dont have any way of knowing it since the vb error that might
> > > pop
> > > up doesnt reference the computer name and there is no log file created.
> >
Quote:

> > > So basically I just want to have it create a log file and enter in the
> > > names
> > > of the computers based on what it pulled from the text file and indicate
> > > whether it was successful or not. Not sure how easy that is. Can someone
> > > help?
> >
Quote:

> > > Here is the code so far that works.
> > > 'On Error Resume Next
> >
Quote:

> > > Const ForReading = 1
> > > Const OverwriteExisting = True
> >
Quote:

> > > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > > 'Read from file list name and location
> > > Set objFile = objFSO.OpenTextFile("C:\mob.txt")
> > > Do Until objFile.AtEndOfStream
> > > strComputer = objFile.ReadLine
> >
Quote:

> > > 'Amend text name and set path to remote location
> > > strRemoteFile = "\\" & strComputer & "\C$\Documents and Settings\All
> > > Users\Desktop\New Icon.url"
> > > 'File to Copy
> > > objFSO.CopyFile "C:\3M MNO.url", strRemoteFile, OverwriteExisting
> >
Quote:

> > > Loop
> >
> > You need to make your scripts a little more robust. Instead of assuming that
> > all will go well, assume that it won't and deal with these cases
> > accordingly. This modified version of your script will inform you if there
> > is a problem with your CopyFile method (ANY problem, not just a target PC
> > that cannot be reached!).
> >
> > You should also close your files when you're finished with them.
> >
> > Const ForReading = 1
> > Const OverwriteExisting = True
> >
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> >
> > 'Read from file list name and location
> > Set objFile = objFSO.OpenTextFile("C:\mob.txt")
> > Do Until objFile.AtEndOfStream
> > strComputer = objFile.ReadLine
> >
> > 'Append text name and set path to remote location
> > strRemoteFile = "\\" & strComputer & "\C$\Documents and Settings\All
> > Users\Desktop\New Icon.url"
> > 'File to Copy
> > On Error Resume Next
> > objFSO.CopyFile "C:\3M MNO.url", strRemoteFile, OverwriteExisting
> > If Err.number > 0 then WScript.Echo "Problem with COPY command on """ &
> > strComputer & """."
> > On Error Goto 0
> > Loop
> > objFile.Close- Hide quoted text -
> >
> > - Show quoted text -
>
> I also suspect that hard coding in a c$ share, and a "documents and
> settings\all users" path is probably not the best way to go about it.
> There must be some way to resolve and localize the %ALLUSERSPROFILE%
> environment variable and key off of that.
>
> If all you're trying to do is copy a shortcut I'd be tempted to create
> a wise script or an MSI to do it. Lots easier than wrestling with VB
> Script.
> -OG
>
My System SpecsSystem Spec
Old 08-27-2008   #5 (permalink)
Owen Gilmore


 
 

Re: Sending computer name to txt file if file didnt copy?

On Aug 27, 6:24*am, Carito <Car...@xxxxxx> wrote:
Quote:

> Thanks for the help guys. I'll give it a try. Pretty new to this. I'll also
> look intot he MSI etc suggestion. Never had to push out something to close to
> 150 computers and dont have access to AD to do it that way.
>
If you're responsible a smaller dist or handling multiple roles your
main challenge may be the distribution, not the scripting itself (as I
say, pretty easy with decent tools). If you don't have access to AD,
maybe a logon script or remote commands run by a WMI script (but
again, back to VB to do that!)....

Good luck!
Owen
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Copy File to users home drives if a certain file exists VB Script
Vista cannot copy file from computer on intranet Vista networking & sharing
copy file from a remote computer PowerShell
File Copy Issues Computer to Computer Vista file management
file copy operations using source file input and script? 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