Prev: Enable/Disable NIC Script - Win 7
Next: Problems with VBScript - RegRead when running as a service
From: bforrest on 4 Feb 2010 07:45 I would like to use vbscript to move a text file from a share directory to specific users home directory whereby the script pulls from a list of names (text file) and uses the users homedir path to copy the file. -- bforrest
From: Pegasus [MVP] on 4 Feb 2010 08:50 "bforrest" <guest(a)unknown-email.com> said this in news item news:2fc01a8a5ba07582f3c2883053076693(a)nntp-gateway.com... > > I would like to use vbscript to move a text file from a share directory > to specific users home directory whereby the script pulls from a list of > names (text file) and uses the users homedir path to copy the file. > > > -- > bforrest Let's have a look at what you've got so far. Note that both the "copy" and "move" method and the file read method are described in detail in the help file script56.chm, which you can download from the Microsoft site.
From: bforrest on 4 Feb 2010 10:45 Ok here's what we have so far: ************************************************* on error resume next set objwshnetwork= createobject("wscript.network") set objdsfso = createobject ("scripting.filesystemobject") struser= objectwshnetwork.username struserCN = getattributefromsamid(struser, "CN" , "domain") strtextfile = "path" & struserCN & "file name" objdsFSO.copyfile strtextfile, "Z:\" ****************************************************** What I am looking for is a script that will reference names from a text file, pull the home directory path and copy a file from a share directory into that location instead of Z:\. Thanks -- bforrest
From: Pegasus [MVP] on 4 Feb 2010 13:03 "bforrest" <guest(a)unknown-email.com> said this in news item news:6391e72d21e261742b8ce4550b2e2af5(a)nntp-gateway.com... > > Ok here's what we have so far: > ************************************************* > on error resume next > set objwshnetwork= createobject("wscript.network") > set objdsfso = createobject ("scripting.filesystemobject") > struser= objectwshnetwork.username > struserCN = getattributefromsamid(struser, "CN" , "domain") > strtextfile = "path" & struserCN & "file name" > objdsFSO.copyfile strtextfile, "Z:\" > ****************************************************** > What I am looking for is a script that will reference names from a text > file, pull the home directory path and copy a file from a share > directory into that location instead of Z:\. > > Thanks > -- > bforrest When writing AD-related VB Script code then you can't really go past Richard Mueller's site (http://www.rlmueller.net/products.htm). He has free code that covers just about every situation. About your code: Having an "on error resume next" statement covering the whole script is deadly. It will hide most errors and you will never find out what's going on. In your code, for example, you create an object "objwshnetwork" but later on you call it "objectwshnetwork". If you run the code without the "on error" line then you will immediately get an error. "On Error" statements should be used sparingly and only above a line of code that could cause an error, e.g. due to a permission issue. Immediately after this line you deal with the error, then insert a line "on error goto 0". I also recommend that you use an "option explicit" statement to protect yourself against spelling errors. About reading reference names from a text file: Here is an example pulled verbatim from Script56.chm: Function ReadLineTextFile Const ForReading = 1, ForWriting = 2 Dim fso, MyFile Set fso = CreateObject("Scripting.FileSystemObject") Set MyFile = fso.OpenTextFile("c:\testfile.txt", ForWriting, True) MyFile.WriteLine "Hello world!" MyFile.WriteLine "The quick brown fox" MyFile.Close Set MyFile = fso.OpenTextFile("c:\testfile.txt", ForReading) ReadLineTextFile = MyFile.ReadLine ' Returns "Hello world!" End Function You obviously do not need the writeline stuff. Since you want to read several lines, you place your readline statements into a loop that runs until you reach the end of the text file. Again there are many examples in Script56.chm.
From: bforrest on 4 Feb 2010 13:45 Thank. that was a typo on my part. I have been having problems getting access to the script56.chm file. The biggest part of this is how to reference AD user profiles homedirectory to be used as the destination for the files to be copied too. This would be a unc mapping. -- bforrest
|
Next
|
Last
Pages: 1 2 Prev: Enable/Disable NIC Script - Win 7 Next: Problems with VBScript - RegRead when running as a service |