![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| XP Professional | Using FSO Copy Folder for Vista Hi All, I am new to VB Scripting, but have had to venture into it to create an interactive cd for work. I have created a "Copy Files" Function for people to copy the cd to their hard drive below: Code: Option Explicit
dim fs
dim fromdrive
dim todrive
dim frompath
dim topath
dim objShell, objDesktop, objLink
dim strAppPath, strWorkDir, strIconPath, DriveLetter
frompath = "\*"
fromdrive= inputbox ("enter your CD drive name like d or e")
frompath = fromdrive & ":" & frompath
topath = "\Documents and Settings\All Users\Desktop\"
DriveLetter = inputbox ("enter your hard drive name like c or f")
topath = DriveLetter & ":" & topath
set fs=CreateObject("Scripting.FileSystemObject")
fs.CopyFolder frompath,topath
MsgBox (frompath & " was copied to " & topath)
Code: Option Explicit
dim objFSO
dim oShell
dim fromdrive
dim todrive
dim frompath
dim topath
dim objShell, objDesktop, objLink
dim strAppPath, strWorkDir, strIconPath, DriveLetter
frompath = "\GA_Spares\*"
fromdrive= inputbox ("enter your CD drive name like d or e")
frompath = fromdrive & ":" & frompath
topath = "\Documents and Settings\All Users\Desktop\"
DriveLetter = inputbox ("enter your hard drive name like c or f")
topath = DriveLetter & ":" & topath
Set oShell = WScript.CreateObject("WScript.Shell")
oShell.Run "ROBOCOPY.exe frompath topath /R /Y"
MsgBox (frompath & " was copied to " & topath)
Any help will be greatly apppreciated. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Using FSO Copy Folder for Vista "jthor78" <guest@xxxxxx-email.com> wrote in message news:69db0f34c381cf3396e84591193c6ac2@xxxxxx-gateway.com... Quote: > > Hi All, > > I am new to VB Scripting, but have had to venture into it to create an > interactive cd for work. I have created a "Copy Files" Function for > people to copy the cd to their hard drive below: > > > Code: > -------------------- > > Option Explicit > dim fs > dim fromdrive > dim todrive > dim frompath > dim topath > dim objShell, objDesktop, objLink > dim strAppPath, strWorkDir, strIconPath, DriveLetter > frompath = "\*" > fromdrive= inputbox ("enter your CD drive name like d or e") > frompath = fromdrive & ":" & frompath > topath = "\Documents and Settings\All Users\Desktop\" > DriveLetter = inputbox ("enter your hard drive name like c or f") > topath = DriveLetter & ":" & topath > set fs=CreateObject("Scripting.FileSystemObject") > fs.CopyFolder frompath,topath > MsgBox (frompath & " was copied to " & topath) > > -------------------- > > > Works great in XP not at all in Vista. I get "Permissions Denied > 800A0046 Line 20 Char 1." So searched everywhere and even tried the > Robocopy.exe with no success below: > > > Code: > -------------------- > Option Explicit > dim objFSO > dim oShell > dim fromdrive > dim todrive > dim frompath > dim topath > dim objShell, objDesktop, objLink > dim strAppPath, strWorkDir, strIconPath, DriveLetter > frompath = "\GA_Spares\*" > fromdrive= inputbox ("enter your CD drive name like d or e") > frompath = fromdrive & ":" & frompath > topath = "\Documents and Settings\All Users\Desktop\" > DriveLetter = inputbox ("enter your hard drive name like c or f") > topath = DriveLetter & ":" & topath > Set oShell = WScript.CreateObject("WScript.Shell") > oShell.Run "ROBOCOPY.exe frompath topath /R /Y" > MsgBox (frompath & " was copied to " & topath) > > -------------------- > > > Ran from my desktop with ROBOCOPY.exe on the desktop as well. Brings up > the MsgBox that the files have been copied but they haven't. What am I > missing? > > Any help will be greatly apppreciated. > -- > jthor78 this command? copy Q:\* "\Documents and Settings\All Users\Desktop\" (Replace Q: with your CD drive letter) If this command fails then your problem is related to Vista, not to scripting. A Vista newsgroup would be a good place to post your question. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Using FSO Copy Folder for Vista Your trouble is that ther is no such path as "documents and settings" under vista! You'll need to research how to use environment variables from VB script (I've recently posted here with that info); then, you'll need to substitute the environment variable %UserProfile% for the c:\documents and settings\<user name> part of the path, in order for this to work properly under either OS. hth, Chip "jthor78" <guest@xxxxxx-email.com> wrote in message news:69db0f34c381cf3396e84591193c6ac2@xxxxxx-gateway.com... Quote: > > Hi All, > > I am new to VB Scripting, but have had to venture into it to create an > interactive cd for work. I have created a "Copy Files" Function for > people to copy the cd to their hard drive below: > > > Code: > -------------------- > > Option Explicit > dim fs > dim fromdrive > dim todrive > dim frompath > dim topath > dim objShell, objDesktop, objLink > dim strAppPath, strWorkDir, strIconPath, DriveLetter > frompath = "\*" > fromdrive= inputbox ("enter your CD drive name like d or e") > frompath = fromdrive & ":" & frompath > topath = "\Documents and Settings\All Users\Desktop\" > DriveLetter = inputbox ("enter your hard drive name like c or f") > topath = DriveLetter & ":" & topath > set fs=CreateObject("Scripting.FileSystemObject") > fs.CopyFolder frompath,topath > MsgBox (frompath & " was copied to " & topath) > > -------------------- > > > Works great in XP not at all in Vista. I get "Permissions Denied > 800A0046 Line 20 Char 1." So searched everywhere and even tried the > Robocopy.exe with no success below: > > > Code: > -------------------- > Option Explicit > dim objFSO > dim oShell > dim fromdrive > dim todrive > dim frompath > dim topath > dim objShell, objDesktop, objLink > dim strAppPath, strWorkDir, strIconPath, DriveLetter > frompath = "\GA_Spares\*" > fromdrive= inputbox ("enter your CD drive name like d or e") > frompath = fromdrive & ":" & frompath > topath = "\Documents and Settings\All Users\Desktop\" > DriveLetter = inputbox ("enter your hard drive name like c or f") > topath = DriveLetter & ":" & topath > Set oShell = WScript.CreateObject("WScript.Shell") > oShell.Run "ROBOCOPY.exe frompath topath /R /Y" > MsgBox (frompath & " was copied to " & topath) > > -------------------- > > > Ran from my desktop with ROBOCOPY.exe on the desktop as well. Brings up > the MsgBox that the files have been copied but they haven't. What am I > missing? > > Any help will be greatly apppreciated. > > > -- > jthor78 |
My System Specs![]() |
| | #4 (permalink) |
| XP Professional | Re: Using FSO Copy Folder for Vista Chip, Thanks for that! I managed to get 2 single scripts working using the different paths but trying to put the 2 together has been a nightmare. I have owrked all day on it and as far as I have got is Code: Option Explicit
dim fs
dim fromdrive
dim DriveLetter
dim frompath
dim dir
dim topathxp
dim topath
dim topathvis
frompath = "\*"
fromdrive= inputbox ("enter your CD drive name like d or e")
frompath = fromdrive & ":" & frompath
topathxp = "\Documents and Settings\All Users\Desktop\"
DriveLetter = inputbox ("enter your hard drive name like c or f")
topathvis = "\Users\Public\Desktop\"
topathxp = DriveLetter & ":" & topathxp
topathvis = DriveLetter & ":" & topathvis
set fs=CreateObject("Scripting.FileSystemObject")
if fs.folderexists(topathxp) then
dir = true
else
dir = false
end if
set fs = nothing 'Stop any memory leakage
if dir = true then
set fs=CreateObject("Scripting.FileSystemObject")
fs.CopyFolder frompath,topathxp
if dir = false then
set fs=CreateObject("Scripting.FileSystemObject")
fs.CopyFolder frompath,topathvis
set fs = nothing 'Stop any memory leakage
end if
set fs = nothing
end if
MsgBox (frompath & " was copied to " & topathxp)
Sorry I have not had enough experience to understand environmental variables and my reseach didnt really help. If I cant get this going we will have to have 2 discs one for XP and one for Vista not ideal situation I appreciate all you help |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Using FSO Copy Folder for Vista "jthor78" <guest@xxxxxx-email.com> wrote in message news:28eb4319e0f54cad515e18c018028edc@xxxxxx-gateway.com... Quote: > > Chip, > > Thanks for that! I managed to get 2 single scripts working using the > different paths but trying to put the 2 together has been a nightmare. > > I have owrked all day on it and as far as I have got is > > Code: > -------------------- > Option Explicit > dim fs > dim fromdrive > dim DriveLetter > dim frompath > dim dir > dim topathxp > dim topath > dim topathvis > > frompath = "\*" > fromdrive= inputbox ("enter your CD drive name like d or e") > frompath = fromdrive & ":" & frompath > > topathxp = "\Documents and Settings\All Users\Desktop\" > DriveLetter = inputbox ("enter your hard drive name like c or f") > topathvis = "\Users\Public\Desktop\" > topathxp = DriveLetter & ":" & topathxp > topathvis = DriveLetter & ":" & topathvis > > set fs=CreateObject("Scripting.FileSystemObject") > if fs.folderexists(topathxp) then > dir = true > else > dir = false > end if > set fs = nothing 'Stop any memory leakage > if dir = true then > set fs=CreateObject("Scripting.FileSystemObject") > fs.CopyFolder frompath,topathxp > if dir = false then > set fs=CreateObject("Scripting.FileSystemObject") > fs.CopyFolder frompath,topathvis > set fs = nothing 'Stop any memory leakage > end if > set fs = nothing > end if > MsgBox (frompath & " was copied to " & topathxp) > -------------------- > > > Works fine on xp but gets stuck on line 33 permission denied - goes to > XP Path rejects immeditately. > > Sorry I have not had enough experience to understand environmental > variables and my reseach didnt really help. If I cant get this going we > will have to have 2 discs one for XP and one for Vista not ideal > situation > > I appreciate all you help > > > -- > jthor78 quick way to isolate the cause of your problem! |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Using FSO Copy Folder for Vista "jthor78" <guest@xxxxxx-email.com> wrote in message news:28eb4319e0f54cad515e18c018028edc@xxxxxx-gateway.com... Quote: > > Chip, > > Thanks for that! I managed to get 2 single scripts working using the > different paths but trying to put the 2 together has been a nightmare. > > I have owrked all day on it and as far as I have got is > > Code: > -------------------- > Option Explicit > dim fs > dim fromdrive > dim DriveLetter > dim frompath > dim dir > dim topathxp > dim topath > dim topathvis > > frompath = "\*" > fromdrive= inputbox ("enter your CD drive name like d or e") > frompath = fromdrive & ":" & frompath > > topathxp = "\Documents and Settings\All Users\Desktop\" > DriveLetter = inputbox ("enter your hard drive name like c or f") > topathvis = "\Users\Public\Desktop\" > topathxp = DriveLetter & ":" & topathxp > topathvis = DriveLetter & ":" & topathvis > > set fs=CreateObject("Scripting.FileSystemObject") > if fs.folderexists(topathxp) then > dir = true > else > dir = false > end if > set fs = nothing 'Stop any memory leakage > if dir = true then > set fs=CreateObject("Scripting.FileSystemObject") > fs.CopyFolder frompath,topathxp > if dir = false then > set fs=CreateObject("Scripting.FileSystemObject") > fs.CopyFolder frompath,topathvis > set fs = nothing 'Stop any memory leakage > end if > set fs = nothing > end if > MsgBox (frompath & " was copied to " & topathxp) > -------------------- > > > Works fine on xp but gets stuck on line 33 permission denied - goes to > XP Path rejects immeditately. > > Sorry I have not had enough experience to understand environmental > variables and my reseach didnt really help. If I cant get this going we > will have to have 2 discs one for XP and one for Vista not ideal > situation > > I appreciate all you help > > > -- > jthor78 ======== Option Explicit Dim objShell, objFolder, objFolderItem Dim strSource, strTarget, objFSO Const ALL_USERS_APPLICATION_DATA = &H23& Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.Namespace(ALL_USERS_APPLICATION_DATA) Set objFolderItem = objFolder.Self strTarget = objFolderItem.Path & "\" strSource = InputBox("Enter source drive letter") If (Len(strSource) = 1) Then strSource = strSource & ":" End If Set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.CopyFolder strSource, strTarget ========= If you want to copy to the desktop, use: =========== Const DESKTOP = &H10& Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.Namespace(DESKTOP) ========= For more on "special folders" see this link: http://www.microsoft.com/technet/scr...l/default.mspx -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Using FSO Copy Folder for Vista Well, one thing I'm sure of is that you need to move an "end if" up to before the line: if dir = false then because right now you have the if false inside of the if true! I don't have a vista system here, so I'm not sure if the "\users\public" is the correct place for items shared by all. Unless your users are admins, I'm not sure even if it is, if they wil have the needed permissions to write to the \users\public dir area. I seem to recall a special dir with "shared" in it's name as being a place where all users of a pc can write to; maybe if you have to find and use it, maybe you can put a shortcut on each users desktop to this area. hth, Chip "jthor78" <guest@xxxxxx-email.com> wrote in message news:28eb4319e0f54cad515e18c018028edc@xxxxxx-gateway.com... Quote: > > Chip, > > Thanks for that! I managed to get 2 single scripts working using the > different paths but trying to put the 2 together has been a nightmare. > > I have owrked all day on it and as far as I have got is > > Code: > -------------------- > Option Explicit > dim fs > dim fromdrive > dim DriveLetter > dim frompath > dim dir > dim topathxp > dim topath > dim topathvis > > frompath = "\*" > fromdrive= inputbox ("enter your CD drive name like d or e") > frompath = fromdrive & ":" & frompath > > topathxp = "\Documents and Settings\All Users\Desktop\" > DriveLetter = inputbox ("enter your hard drive name like c or f") > topathvis = "\Users\Public\Desktop\" > topathxp = DriveLetter & ":" & topathxp > topathvis = DriveLetter & ":" & topathvis > > set fs=CreateObject("Scripting.FileSystemObject") > if fs.folderexists(topathxp) then > dir = true > else > dir = false > end if > set fs = nothing 'Stop any memory leakage > if dir = true then > set fs=CreateObject("Scripting.FileSystemObject") > fs.CopyFolder frompath,topathxp > if dir = false then > set fs=CreateObject("Scripting.FileSystemObject") > fs.CopyFolder frompath,topathvis > set fs = nothing 'Stop any memory leakage > end if > set fs = nothing > end if > MsgBox (frompath & " was copied to " & topathxp) > -------------------- > > > Works fine on xp but gets stuck on line 33 permission denied - goes to > XP Path rejects immeditately. > > Sorry I have not had enough experience to understand environmental > variables and my reseach didnt really help. If I cant get this going we > will have to have 2 discs one for XP and one for Vista not ideal > situation > > I appreciate all you help > > > -- > jthor78 |
My System Specs![]() |
| | #8 (permalink) |
| XP Professional | Re: Using FSO Copy Folder for Vista Thanks for your help guys. I found out what was causing the 800A0046 Permission Denied Error - Vistas UAC and not being logged in as administrator. For some reason Vista restricts the script from running under these conditions. But this was the final script that works on XP and Vista (admin accounts with UAC temporarily turned off) Code: Option Explicit
dim fs
dim fromdrive
dim DriveLetter
dim frompath
dim dir
dim topathxp
dim topath
dim topathvis
frompath = "\*"
fromdrive= inputbox ("enter your CD drive name like d or e")
frompath = fromdrive & ":" & frompath
topathxp = "\Documents and Settings\All Users\Desktop\"
topathvis = "\Users\Public\Desktop\"
DriveLetter = inputbox ("enter your hard drive name like c or f")
topathxp = DriveLetter & ":" & topathxp
topathvis = DriveLetter & ":" & topathvis
set fs=CreateObject("Scripting.FileSystemObject")
if fs.folderexists(topathxp) then
dir = true
end if
if fs.folderexists(topathvis) then
dir = false
end if
set fs = nothing 'Stop any memory leakage
if dir = true then
set fs=CreateObject("Scripting.FileSystemObject")
fs.CopyFolder frompath,topathxp
end if
if dir = false then
set fs=CreateObject("Scripting.FileSystemObject")
fs.CopyFolder frompath,topathvis
end if
MsgBox (frompath & " was copied to " & topathxp)
|
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Context Menu - Add COPY TO FOLDER and MOVE TO FOLDER | Tutorials | |||
| Vista Permissions Nightmare 2 - Cannot Copy to my own Folder | Vista General | |||
| Re: Copying CD files to folder, then copy folder to another hard drive, explorer hangs | Vista file management | |||
| File copy hangs from cingular 8525 to Vista folder using Sync Cent | Vista hardware & devices | |||
| Can't copy a folder like in XP | Vista General | |||