I'm running this script but it doesn't create the registry key. I can manually run the command (same user, to the same location etc) and it works. The script doesn't error and the file copies that occur after the reg export work ok. The part that doesn't work starts at line 52
'XenAppLogin-2003.vbs' Define Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
Set objConn = CreateObject("ADODB.Connection")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
'Define Variables
ProfilesDir = "\\datasvr\tsprofiles\"
'Domain server
Server = "adc2.xnth.nhs.uk"
' Get Logged in username
strUserName = objShell.ExpandEnvironmentStrings("%USERNAME%")
'strUserName = "erez_test4"
strFolderV1 = ProfilesDir & strUserName
strFolderV2 = ProfilesDir & strUserName & ".V2"
Base = "<LDAP://" & Server & "/DC=xnth,DC=nhs,DC=uk>;"
Filter2 = "(&(objectClass=user)(objectCategory=person)(sAMAccountName=" & strUserName & "));"
Attr = "distinguishedName;"
Level = "SubTree"
Set RecordSet = objConn.Execute(Base & Filter2 & Attr & Level)
If (Not RecordSet.EOF) Then
RecordSet.MoveFirst
While Not RecordSet.EOF
Set objUser = GetObject("LDAP://"& RecordSet.Fields(0).Value)
strFolderV1 = objUser.TerminalServicesProfilePath
strFolderV2 = objUser.TerminalServicesProfilePath & ".V2"
RecordSet.MoveNext
Wend
End If
' Check If V2 folder exists
If (objFSO.FolderExists(strFolderV2 & "\AppData\Roaming\Microsoft\Outlook")) Then
Wscript.echo "do nothing"
Else
' Export Outlook Settings
' Create Folder and make it hidden
If (NOT objFso.FolderExists(strFolderV1 & "\OutlookBackupSettings")) Then objFSO.CreateFolder(strFolderV1 & "\OutlookBackupSettings")
Set objFolder = objFSO.GetFolder(strFolderV1 & "\OutlookBackupSettings")
If objFolder.Attributes = objFolder.Attributes AND 2 Then
objFolder.Attributes = objFolder.Attributes Xor 2
End If
strRegPath = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
strCommand = "cmd /c REG EXPORT " & """" & strRegPath & """" & " " & strFolderV1 & "\OutlookBackupSettings" & "\outlookprofile.reg /y"
objShell.Run strCommand, 0, True
If (Not objFso.FolderExists(strFolderV1 & "\OutlookBackupSettings\Outlook")) Then objFSO.CreateFolder(strFolderV1 & "\OutlookBackupSettings\Outlook")
strCommand = "cmd /c xcopy " & """" & strFolderV1 & "\Application Data\Microsoft\Outlook\*" & """" & " " & """" & strFolderV1 & "\OutlookBackupSettings\Outlook\"& """" & " /i /y /c /e"
objShell.Run strCommand, 0, True
strCommand = "cmd /c xcopy " & """" & strFolderV1 & "\Application Data\Microsoft\Signatures\*" & """" & " " & """" & strFolderV1 & "\OutlookBackupSettings\Signatures\"& """" & " /i /y /c /e"
objShell.Run strCommand, 0, True
strCommand = "cmd /c xcopy " & """" & strFolderV1 & "\Application Data\Microsoft\Office\*" & """" & " " & """" & strFolderV1 & "\OutlookBackupSettings\Office\"& """" & " /i /y /c /e"
objShell.Run strCommand, 0, True
End If