simons2009 Posted February 26, 2010 Posted February 26, 2010 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 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) 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
DrPerceptron Posted February 28, 2010 Posted February 28, 2010 What happens if you remove the following line on error resume next it's a bad line to have if you're trying to debug something.
simons2009 Posted March 2, 2010 Author Posted March 2, 2010 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.
simons2009 Posted March 2, 2010 Author Posted March 2, 2010 Any ideas why i cant get it to working in Windows 7?
mac_shinobi Posted March 2, 2010 Posted March 2, 2010 (edited) 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 set [b]oFSO[/b]=createobject("scripting.filesystemobject") set oShell=createobject("wscript.shell") Dim objFSO Then when you come to try and use it you are doing the following [b]ofso[/b].copyfolder strEnv & "\tempkcs" , sFolder & "\session", true [b]ofso[/b].copyfolder strEnv & "\tempkcs" , sFolder & "\KCS\Session605", true [b]-->> oFSO[/b].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 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) Edited March 2, 2010 by mac_shinobi 1
simons2009 Posted March 3, 2010 Author Posted March 3, 2010 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
mac_shinobi Posted March 3, 2010 Posted March 3, 2010 (edited) 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/infocenter/cqhelp/v7r0m0/index.jsp?topic=/com.ibm.rational.clearquest.apiref.doc/c_vbscript_err_hndlng.htm Edited March 3, 2010 by mac_shinobi
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now