Jump to content

Recommended Posts

Posted

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

Posted
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.
Posted (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 by mac_shinobi
  • Thanks 1
Posted

Thank You mac_shinobi :D

 

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

Posted (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 by mac_shinobi

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...