artfulmatt Posted June 30, 2010 Posted June 30, 2010 Hi Guys, Got an odd problem - but persistent whereby a script we use to copy the profile from a network share runs, but occasionally (like today) it won't? Give the machines a reboot (or two) and it will - logon locally and run the script and it runs fine? Any ideas or direction would be great as this is now causing me a headache Cheers :-) Script is as follows:- On Error Resume Next Set shell = CreateObject("Wscript.Shell") Set WshNetwork = WScript.CreateObject("WScript.Network") Set objFSO = CreateObject("Scripting.FileSystemObject") shell.Popup "Waiting 2 seconds....", 2, Timer, 64 wscript.sleep(2000) 'Delete profile if it already exists: If objFSO.FolderExists("C:\Documents and Settings\Default User") Then objFSO.DeleteFolder("C:\Documents and Settings\Default User") objFSO.CopyFolder "\\server.domain.local\profile$\Default User", "C:\Documents and Settings\Default User", True objFSO.CopyFile "\\server.domain.local\profile$\version.txt", "C:\Documents and Settings\version.txt", True objFSO.CopyFile "\\server.domain.local\profile$\wallpaper.bmp", "C:\wallpaper.bmp", True ' Error Handling: If Err.Number <> 0 Then shell.Popup "An error occured replacing an existing profile on: "& WshNetwork.ComputerName &". Please report this error message to ITS: "& CStr(Err.Number) & " " & Err.Description, 30, Timer, 64 Set objMessage = CreateObject("CDO.Message") objMessage.Subject = "Profile Problems - " & WshNetwork.ComputerName objMessage.From = "[email protected]" objMessage.To = "[email protected]" objMessage.TextBody = "There is an issue replacing an existing profile on : "& WshNetwork.ComputerName &" - Error Message: "& CStr(Err.Number) & " " & Err.Description objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "[email protected]" objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objMessage.Configuration.Fields.Update objMessage.Send 'Clear the error message Err.Clear End If shell.Popup "Default User Profile Replaced", 2, Timer, 64 'Copy profile if it doesnt exist: Else objFSO.CopyFolder "\\server.domain.local\profile$\Default User", "C:\Documents and Settings\Default User", True objFSO.CopyFile "\\server.domain.local\profile$\version.txt", "C:\Documents and Settings\version.txt", True objFSO.CopyFile "\\server.domain.local\profile$\wallpaper.bmp", "C:\wallpaper.bmp", True ' Error Handling: If Err.Number <> 0 Then shell.Popup "An error occured copying a new profile on: "& WshNetwork.ComputerName &". Please report this error message to ITS: "& CStr(Err.Number) & " " & Err.Description, 30, Timer, 64 Set objMessage = CreateObject("CDO.Message") objMessage.Subject = "Profile Problems - " & WshNetwork.ComputerName objMessage.From = "[email protected]" objMessage.To = "[email protected]" objMessage.TextBody = "There is an copying a new profile on : "& WshNetwork.ComputerName &" - Error Message: "& CStr(Err.Number) & " " & Err.Description objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.blah.co.uk" objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objMessage.Configuration.Fields.Update objMessage.Send 'Clear the error message Err.Clear End If shell.Popup "New Default User Copied", 2, Timer, 64 End If 'Set Default Background const HKEY_USERS = &H80000003 strComputer = "." Set StdOut = WScript.StdOut Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ strComputer & "\root\default:StdRegProv") strKeyPath = ".DEFAULT\Control Panel\Desktop" strValueName = "Wallpaper" strValue = "C:\wallpaper.bmp" oReg.SetStringValue HKEY_USERS,strKeyPath,strValueName,strValue ' Error Handling: If Err.Number <> 0 Then shell.Popup "An error occured setting the wallpaper on: "& WshNetwork.ComputerName &". Please report this error message to ITS: "& CStr(Err.Number) & " " & Err.Description, 30, Timer, 64 Set objMessage = CreateObject("CDO.Message") objMessage.Subject = "Profile Problems - " & WshNetwork.ComputerName objMessage.From = "[email protected]" objMessage.To = "[email protected]" objMessage.TextBody = "An error occured setting the wallpaper on : "& WshNetwork.ComputerName &" - Error Message: "& CStr(Err.Number) & " " & Err.Description objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "[email protected]" objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objMessage.Configuration.Fields.Update 'objMessage.Send 'Clear the error message Err.Clear End If shell.Popup "Wallpaper set", 2, Timer, 64 On Error GoTo 0
SkreeM1980 Posted July 6, 2010 Posted July 6, 2010 Would suggest it's possibly more of a GPO issue, have you got "Wait for Network at computer startup" enabled somewhere on the computers OU's if not give it a go.
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