Kizer Posted August 19, 2004 Share Posted August 19, 2004 Hi all, I'm trying to modify this program (which simply copies a folder from a computer to a network folder)... // Copies a folder to another location. strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer) Set objFolder = objWMIService.Get("Win32_Directory.Name='C:\Documents and Settings\username\My Documents'") objFolder.Copy("P:\path...\") WScript.Echo "Your Files Have Been Copied." into the following program utilizing a str variable for the username in the Documents and Settings path, like so... strUser = "username" strComputer = "." strOnlineFolder = "P:\path...\" & strUser Set objWMIService = GetObject("winmgmts:\\" & strComputer) Set objFolder = objWMIService.Get("Win32_Directory.Name='C:\Documents and Settings\' & strUser & '\My Documents'") intReturn = objFolder.Copy(strOnlineFolder"\My Documents") Select Case intReturn Case 0 WScript.Echo "Copy successful" Case 2 WScript.Echo "Copy failed: access denied" Case 9 WScript.Echo "Copy failed: invalid name" Case 10 WScript.Echo "Copy failed: folder already exists" Case Else WScript.Echo "Copy failed: reason uncertain" End Select Well, I'm getting a run-time error with this line which I figured would give me trouble. Where do I need to put quotes (both single and double)? Set objFolder = objWMIService.Get("Win32_Directory.Name='C:\Documents and Settings\' & strUser & '\My Documents'") Thanks all! Link to comment Share on other sites More sharing options...
0 U.N.C.L.E. Posted August 19, 2004 Share Posted August 19, 2004 Use " (double quote as string delimiter instead of single quote). Set objFolder = objWMIService.Get("Win32_Directory.Name='C:\Documents and Settings\" & strUser & "\My Documents'") Link to comment Share on other sites More sharing options...
0 Kizer Posted August 19, 2004 Author Share Posted August 19, 2004 Use " (double quote as string delimiter instead of single quote).Set objFolder = objWMIService.Get("Win32_Directory.Name='C:\Documents and Settings\" & strUser & "\My Documents'") Thanks for the response U.N.C.L.E. When I use your example, I get a different error for the same line: Line 10 Character 115 "Unterminated string constant." Appreciating the help! Link to comment Share on other sites More sharing options...
0 John Veteran Posted August 19, 2004 Veteran Share Posted August 19, 2004 Set objFolder = objWMIService.Get("Win32_Directory.Name=""C:\Documents and Settings\" & strUser & "\My Documents""") Try that (Y) Link to comment Share on other sites More sharing options...
Question
Kizer
Hi all, I'm trying to modify this program (which simply copies a folder from a computer to a network folder)...
// Copies a folder to another location.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer)
Set objFolder = objWMIService.Get("Win32_Directory.Name='C:\Documents and Settings\username\My Documents'")
objFolder.Copy("P:\path...\")
WScript.Echo "Your Files Have Been Copied."
into the following program utilizing a str variable for the username in the Documents and Settings path, like so...
strUser = "username"
strComputer = "."
strOnlineFolder = "P:\path...\" & strUser
Set objWMIService = GetObject("winmgmts:\\" & strComputer)
Set objFolder = objWMIService.Get("Win32_Directory.Name='C:\Documents and Settings\' & strUser & '\My Documents'")
intReturn = objFolder.Copy(strOnlineFolder"\My Documents")
Select Case intReturn
Case 0
WScript.Echo "Copy successful"
Case 2
WScript.Echo "Copy failed: access denied"
Case 9
WScript.Echo "Copy failed: invalid name"
Case 10
WScript.Echo "Copy failed: folder already exists"
Case Else
WScript.Echo "Copy failed: reason uncertain"
End Select
Well, I'm getting a run-time error with this line which I figured would give me trouble. Where do I need to put quotes (both single and double)?
Set objFolder = objWMIService.Get("Win32_Directory.Name='C:\Documents and Settings\' & strUser & '\My Documents'")
Thanks all!
Link to comment
Share on other sites
3 answers to this question
Recommended Posts