+ Post New Thread
Results 1 to 7 of 7
Scripts Thread, ofso.copyfolder - Windows 7 in Coding and Web Development; Here is my script that works on Windows XP etc but on windows 7 it does not copy the files ...
  1. #1

    Join Date
    May 2009
    Posts
    20
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    ofso.copyfolder - Windows 7

    Here is my script that works on Windows XP etc but on windows 7 it does not copy the files only deletes the folder in the temp area.

    SessionBackup.vbs - Working

    VSB 1 is the backup and works on Windows7 saves to the following path:
    C:\Users\Simon\AppData\Local\Temp\tempkcs


    Code:
    set oFSO=createobject("scripting.filesystemobject")
    set oShell=createobject("wscript.shell")
    Dim objFSO, objFiles, objShell, intCount
    Dim strFile, strName, strLongName, strDirectory, strEnv, strExt
    Set objShell = CreateObject("Wscript.Shell")
    strEnv = objShell.ExpandEnvironmentStrings("%temp%")
    intcount = 0
    
    
    on error resume next
    sFile=oShell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\IbsFont")
    on error goto 0
    if sFile="" then 
    else
    set oFile=ofso.getfile(sFile)
    sfolder=oFile.parentfolder & "\session"
    ofso.copyfolder sFolder , strEnv & "\tempkcs" , true
    end if

    Ok Script 2 - Not working on Windows 7 (only deletes the folder)

    Code:
    set oFSO=createobject("scripting.filesystemobject")
    set oShell=createobject("wscript.shell")
    
    Dim objFSO, objFiles, objShell, intCount
    Dim strFile, strName, strLongName, strDirectory, strEnv, strExt
    Set objShell = CreateObject("Wscript.Shell")
    strEnv = objShell.ExpandEnvironmentStrings("%temp%")
    intcount = 0
    
    on error resume next
    
    sFile=oShell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\IbsFont")
    on error goto 0
    if sFile="" then 
    ' DO NOTHING
    else
    ' Copy files from source to destination
    set oFile=ofso.getfile(sFile)
    sfolder=oFile.parentfolder 
    ofso.copyfolder strEnv & "\tempkcs" , sFolder & "\session", true
    ofso.copyfolder strEnv & "\tempkcs" , sFolder & "\KCS\Session605", true
    oFSO.DeleteFolder strEnv & "\tempkcs", True
    end if



    Hope you can help

  2. #2
    DrPerceptron's Avatar
    Join Date
    Dec 2008
    Location
    In a house
    Posts
    932
    Thank Post
    37
    Thanked 135 Times in 115 Posts
    Rep Power
    42
    What happens if you remove the following line

    Code:
    on error resume next
    it's a bad line to have if you're trying to debug something.

  3. #3

    Join Date
    May 2009
    Posts
    20
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    No Change i get no error it does not copy back to C:\Program Files\wIntegrate\Session but it still deletes the folder in the temp area like i want it to.

  4. #4

    Join Date
    May 2009
    Posts
    20
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Any ideas why i cant get it to working in Windows 7?

  5. #5

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,977
    Thank Post
    3,528
    Thanked 1,107 Times in 1,014 Posts
    Rep Power
    374
    Quote Originally Posted by simons2009 View Post
    Any ideas why i cant get it to working in Windows 7?
    Also you are declaring your objFSO as something different to what you are setting it to and you are delcaring it after creating it , I normally do

    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")

    you are setting / creating your file system object as

    Code:
    set oFSO=createobject("scripting.filesystemobject")
    set oShell=createobject("wscript.shell")
    
    Dim objFSO
    Then when you come to try and use it you are doing the following

    Code:
    ofso.copyfolder strEnv & "\tempkcs" , sFolder & "\session", true
    ofso.copyfolder strEnv & "\tempkcs" , sFolder & "\KCS\Session605", true
    -->>  oFSO.DeleteFolder strEnv & "\tempkcs", True  '<<--- notice how the deletion works but not the copy operation
    You have done a similiar sort of thing in the other script.

    I normally declare the fso as fso so

    Code:
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    'all my other code to do what I need to do ie with registry etc
    
    fso.CopyFolder yada yada
    If you get an error message on windows 7 then it may either be down to UAC or permissions because I think vista / windows 7 has stricter permissions on the system root / windows directory and program files directory now

    Might be worth trying to use wmi to copy the folders ??

    Scripting Files and Folders using VBScript

    Think there are one or two other examples on there like using the shell object etc so maybe worth trying the different methods as well.

    If you are still stuck then maybe try having a copy of robocopy in the sysvol / net logon area and use the robocopy switches etc - also if you are using wmi you may be able to change the authentication level but obviously this may be a security risk as you will now have a script with account details ie username and password.

    With ref to using wmi to authenticate see here

    Connecting to WMI on a Remote Computer (Windows)
    Last edited by mac_shinobi; 2nd March 2010 at 09:25 AM.

  6. Thanks to mac_shinobi from:

    simons2009 (3rd March 2010)

  7. #6

    Join Date
    May 2009
    Posts
    20
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    THANKS

    Thank You mac_shinobi

    You where 100% correct Windows 7 has stricter permissions on the system root / windows directory and program files directory now.

    I found if i create a batch file and run it as admin it will allow copy the files into the folder.

    Also thanks you for showing me to declare it before i create the Dim.

    Again thanks again for your help.

    Thanks,
    Simon

  8. #7

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,977
    Thank Post
    3,528
    Thanked 1,107 Times in 1,014 Posts
    Rep Power
    374
    no problem - I normally create all my variables first whether they are const's , dimmed ( dim ) etc and then go through the code that way, just makes it a bit neater so I know whats where, I also try to keep my code close together so if I do get an error ie line 72 or whatever it makes it slightly easier to find roughly where its erroring out.

    I think you can do your own error handling so that it gives you a more specific error message as apposed to the usual line x.

    http://publib.boulder.ibm.com/infoce...err_hndlng.htm
    Last edited by mac_shinobi; 3rd March 2010 at 08:46 AM.



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 4
    Last Post: 19th March 2012, 09:58 AM
  2. Replies: 4
    Last Post: 26th May 2010, 06:29 PM
  3. Replies: 63
    Last Post: 2nd December 2009, 05:50 PM
  4. Replies: 0
    Last Post: 4th September 2009, 01:48 AM
  5. Install Windows Server 2003 admin pack on Windows Vista
    By FN-GM in forum Wiki Announcements
    Replies: 0
    Last Post: 27th March 2008, 05:19 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •