+ Post New Thread
Results 1 to 2 of 2
Scripts Thread, VBScript to copy profile on Startup (GPO) not always running? in Coding and Web Development; Hi Guys, Got an odd problem - but persistent whereby a script we use to copy the profile from a ...
  1. #1

    Join Date
    Jun 2008
    Location
    Norwich
    Posts
    29
    Thank Post
    1
    Thanked 1 Time in 1 Post
    Rep Power
    0

    VBScript to copy profile on Startup (GPO) not always running?

    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 = "blah@blah.co.uk"
    objMessage.To = "blah@blah.co.uk"
    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") = "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 "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 = "blah@blah.co.uk"
    objMessage.To = "blah@blah.co.uk"
    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=imper sonate}!\\" &_
    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 = "blah@blah.co.uk"
    objMessage.To = "blah@blah.co.uk"
    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") = "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 "Wallpaper set", 2, Timer, 64

    On Error GoTo 0

  2. #2

    Join Date
    Jan 2009
    Location
    Northants
    Posts
    143
    Thank Post
    5
    Thanked 11 Times in 10 Posts
    Rep Power
    13
    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.

SHARE:
+ Post New Thread

Similar Threads

  1. Startup Script Running after login
    By glennda in forum Windows
    Replies: 6
    Last Post: 17th November 2009, 11:54 PM
  2. Scripting challenge: Copy files into profile
    By tmcd35 in forum Windows Server 2000/2003
    Replies: 0
    Last Post: 26th August 2009, 02:22 PM
  3. 2003 GPO location enhanced startup screen
    By RabbieBurns in forum Windows Server 2000/2003
    Replies: 3
    Last Post: 16th February 2009, 03:43 PM
  4. vbscript to copy a folder & delete a folder
    By MicrodigitUK in forum Scripts
    Replies: 2
    Last Post: 29th January 2009, 12:43 PM
  5. Running a program at startup in CC3?
    By reggiep in forum Network and Classroom Management
    Replies: 2
    Last Post: 17th July 2008, 01:02 PM

Thread Information

Users Browsing this Thread

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

Posting Permissions

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