Avatar of RPUKsupport
RPUKsupport

asked on 

vbs to install reg keys and copy / delete files from client pcs

Hi there

I need some major help, I would like to incorporate some features into my currently existing vb logon script.

I need it to do the following:

* install reg keys from a folder on the network
* copy files from the network to the local machines
* delete files from local machines

There are alot of reg keys i need to install and data to copy, but is there a way to say if this already exists do not copy to local machine? (this is for the files)

Thanks
VB ScriptWindows XP

Avatar of undefined
Last Comment
RobSampson
Avatar of Shift-3
Shift-3
Flag of United States of America image

When you say "install reg keys from a folder on the network", do you mean you want to import .reg files, read keys and values out of text files, or something else?  For importing .reg files, this is probably the simplest method:
set objShell = CreateObject("Wscript.Shell")objShell.Run("regedit /s \\server\share\filename.reg")

To add individual values in vbscript, see the examples in these articles:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun08/hey0624.mspx
http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/hey0224.mspx

Keep in mind that since this is a logon script, users will have to have permission to the keys you're modifying.

For checking whether a file exists before copying it, see the example here:
http://www.devguru.com/Technologies/vbscript/QuickRef/filesystemobject_copyfile.html

 Change the If to If Not and use the path of the destination file instead of the source file.
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, here's a quick example of doing the three tasks you mentioned.

Regards,

Rob.
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
arrRegFiles = Array( _
	"\\server\share\RegFile1.reg", _
	"\\server\share\RegFile2.reg" _
	)
 
' Set <sourcefolder>;<targetfolder>
arrFoldersToCopy = Array( _
	"\\server\share\Folder1;C:\Files\Program1", _
	"\\server\share\Folder2;C:\Files\Program2" _
	)
 
arrFilesToDelete = Array( _
	"C:\Temp\*.tmp", _
	"C:\Temp\*.bak" _
	)
 
For Each strRegFile In arrRegFiles
	objShell.Run "regedit /s """ & strRegFile & """", 1, True
Next
 
For Each strCopyDef In arrFoldersToCopy
	strSource = Split(strCopyDef, ";")(0)
	strDest = Split(strCopyDef, ";")(1)
	objFSO.CopyFolder strSource, strDest, True
Next
 
For Each strDeleteDef In arrFilesToDelete
	objFSO.DeleteFile strDeleteDef, True
Next

Open in new window

Avatar of RPUKsupport
RPUKsupport

ASKER

I have incorporated some of that into my script but it doesnt work, but it does it i run this in a seperate vbs with nothing else in it.

This is the code that works in its own vbs:

==================================================================

Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "\\server\shared\theme\*.*" , "c:\windows\ctheme\" , OverwriteExisting

set objShell = CreateObject("Wscript.Shell")
objShell.Run("regedit /s \\server\shared\theme\reg\reg1.reg")
objShell.Run("regedit /s \\server\shared\theme\reg\reg2.reg")
objShell.Run("regedit /s \\server\shared\theme\reg\reg3.reg")

==================================================================

And attached below is my logon script without the above in and a line

WshShell.run "\\server1\netlogon\kidtheme.vbs", 0,

Which does not work either.

To tell the truth I dont know what alot of the mumbo jumbo means in the script, i know it maps drives according to groups etc but im not sure about much else.

i just want to add the following into the script and have it work
==================================================================

Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "\\server\shared\theme\*.*" , "c:\windows\ctheme\" , OverwriteExisting

set objShell = CreateObject("Wscript.Shell")
objShell.Run("regedit /s \\server\shared\theme\reg\reg1.reg")
objShell.Run("regedit /s \\server\shared\theme\reg\reg2.reg")
objShell.Run("regedit /s \\server\shared\theme\reg\reg3.reg")

==================================================================

i think i also need to add a line in there that adds a folder if it doesnt exist, before the copy of the files, as ive noticed that as well.

As you can tell im hopeless with this so any suggestions or better ways to get this working or editing my script would be greatly appreciated
Option Explicit ' Force explicit declarations
'
' Variables
'
Dim WSHNetwork
Dim FSO
Dim strUserName ' Current user
Dim strUserDomain ' Current User's domain name
Dim ObjGroupDict ' Dictionary of groups to which the user belongs
 
on error resume next
 
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set FSO = CreateObject("Scripting.FileSystemObject")
'
' Wait until the user is really logged in...
'
strUserName = ""
While strUserName = ""
WScript.Sleep 100 ' 1/10 th of a second
strUserName = WSHNetwork.UserName
Wend
strUserDomain = WSHNetwork.UserDomain
 
' WScript.Echo "Running from Sysvol\domain\Scripts"
 
 
' Read the user's account "Member Of" tab info across the network
' once into a dictionary object.
 
WshShell.run "\\server1\netlogon\kidtheme.vbs", 0
 
'Map  Common network Drives here, UNREM the below lines:
 
WSHNetwork.MapNetworkDrive "U:", "\\SERVER1\" & strUserName & "$"
WSHNetwork.MapNetworkDrive "S:", "\\SERVER1\Shared"
WSHNetwork.MapNetworkDrive "L:", "\\SERVER2\" & strUserName & "$"
 
Set ObjGroupDict = CreateMemberOfObject(strUserDomain, strUserName)
 
 
If Memberof(ObjGroupDict, "Accounts Users K") Then 
 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Accounts" 
 
else
 
End If 
 
If Memberof(ObjGroupDict, "IT Users K") Then 
 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\It" 
 
else
 
End If 
 
If Memberof(ObjGroupDict, "Analytical Services Users K") Then 
wshNetwork.MapNetworkDrive "J:","\\SERVER1\RootJ" 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\SAServices"
wshNetwork.MapNetworkDrive "V:","\\SERVER1\ASvcs" 
 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Administration Users S") Then 
' WScript.Echo "Admin Users S"
wshNetwork.MapNetworkDrive "G:","\\SERVER3\Admin" 
 
else
 
End If 
 
If Memberof(ObjGroupDict, "Sudops Users S") Then 
wshNetwork.MapNetworkDrive "F:","\\SERVER3\Sudops" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Management Users S") Then 
wshNetwork.MapNetworkDrive "H:","\\SERVER3\Management" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Engineer Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Engineer" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "MSDS Users K") Then 
wshNetwork.MapNetworkDrive "M:","\\SERVER1\MSDS" 
 
else
 
End If
 
'If Memberof(ObjGroupDict, "Engineer Proj Users K") Then 
'wshNetwork.MapNetworkDrive "P:","\\SERVER1\EngProj" 
 
'else
 
'End If
 
If Memberof(ObjGroupDict, "Base Colour & QC Users K") Then 
wshNetwork.MapNetworkDrive "T:","\\SERVER1\Base_Colour" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Base Colour Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Base_Colour" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "QCGrp Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\QC" 
wshNetwork.MapNetworkDrive "J:","\\SERVER1\RootJ" 
else
 
End If
 
If Memberof(ObjGroupDict, "AdminGrp Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\AdminGrp" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "PDSA2 Users K") Then 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\PDSA2" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Customer Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Customer" 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\eWork" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Marketing Users K") Then 
wshNetwork.MapNetworkDrive "N:","\\SERVER1\Marketing" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Sales Users K") Then 
wshNetwork.MapNetworkDrive "P:","\\SERVER1\Sales" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "C Of A Admin Users K") Then 
wshNetwork.MapNetworkDrive "T:","\\SERVER1\CofA" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "C of A View Users K") Then 
wshNetwork.MapNetworkDrive "T:","\\SERVER1\CofA" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "TechEnq Users K") Then 
wshNetwork.MapNetworkDrive "O:","\\SERVER1\TechEnq" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "TechEnqFA Users K") Then 
wshNetwork.MapNetworkDrive "O:","\\SERVER1\TechEnq" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Enquiry Users K") Then 
wshNetwork.MapNetworkDrive "Q:","\\SERVER1\Enquiry" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "KidOps Users K") Then 
wshNetwork.MapNetworkDrive "G:","\\SERVER1\KidOps" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Minitab Users K") Then 
wshNetwork.MapNetworkDrive "G:","\\SERVER1\Minitab" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "EssbaseGrp Users K") Then 
wshNetwork.MapNetworkDrive "X:","\\SERVER1\EssBaseBKP" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "H & S Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\H&S" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Quality Management Systems Users K") Then 
wshNetwork.MapNetworkDrive "R:","\\SERVER1\Quality Management Systems" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Work Instructions Users K") Then 
wshNetwork.MapNetworkDrive "I:","\\SERVER1\Work Instructions" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Complaints Users K") Then 
wshNetwork.MapNetworkDrive "K:","\\SERVER3\Complaints" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Finance Payroll Users K") Then 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\Statutory Financial" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Msds Uni read Only U") Then 
wshNetwork.MapNetworkDrive "M:","\\SERVER1\MSDS" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Management Team Users K") Then 
wshNetwork.MapNetworkDrive "X:","\\SERVER1\Management Team" 
 
else
 
End If
 
 
 
 
' Added By SJE
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
 
 
WshShell.run ("s:\share\client *echo-")
 
Function MemberOf(ObjDict, strKey)
' Given a Dictionary object containing groups to which the user
' is a member of and a group name, then returns True if the group
' is in the Dictionary else return False.
'
' Inputs:
' strDict - Input, Name of a Dictionary object
' strKey - Input, Value being searched for in
' the Dictionary object
' Sample Usage:
'
' If MemberOf(ObjGroupDict, "DOMAIN ADMINS") Then
' wscript.echo "Is a member of Domain Admins."
' End If
'
'
MemberOf = CBool(ObjGroupDict.Exists(strKey)) 
 
End Function
 
 
Function CreateMemberOfObject(strDomain, strUserName)
' Given a domain name and username, returns a Dictionary
' object of groups to which the user is a member of.
'
' Inputs:
'
' strDomain - Input, NT Domain name
' strUserName - Input, NT username
'
Dim objUser, objGroup
 
Set CreateMemberOfObject = CreateObject("Scripting.Dictionary")
CreateMemberOfObject.CompareMode = vbTextCompare
Set objUser = GetObject("WinNT://" _
& strDomain & "/" _
& strUserName & ",user")
For Each objGroup In objUser.Groups
CreateMemberOfObject.Add objGroup.Name, "-"
Next
Set objUser = Nothing
 
End Function

Open in new window

Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, I have added your desired bit of code to the script, which should work.

If you find it is still not working, please change this line:

on error resume next

to this

'on error resume next

to comment it out, and then you will probably receive an error at the point that the script is failing.  Then if you post that line number and error, we can help further.

Also, to be able to run another VBS file from within this script, add
WshShell.run "wscript.exe \\server1\netlogon\kidtheme.vbs", 1, True

Regards,

Rob.
Option Explicit ' Force explicit declarations
'
' Variables
'
Dim WSHNetwork
Dim FSO
Dim strUserName ' Current user
Dim strUserDomain ' Current User's domain name
Dim ObjGroupDict ' Dictionary of groups to which the user belongs
 
on error resume next
 
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set FSO = CreateObject("Scripting.FileSystemObject")
'
' Wait until the user is really logged in...
'
strUserName = ""
While strUserName = ""
WScript.Sleep 100 ' 1/10 th of a second
strUserName = WSHNetwork.UserName
Wend
strUserDomain = WSHNetwork.UserDomain
 
' WScript.Echo "Running from Sysvol\domain\Scripts"
 
 
' Read the user's account "Member Of" tab info across the network
' once into a dictionary object.
 
WshShell.run "\\server1\netlogon\kidtheme.vbs", 0
 
'Map  Common network Drives here, UNREM the below lines:
 
WSHNetwork.MapNetworkDrive "U:", "\\SERVER1\" & strUserName & "$"
WSHNetwork.MapNetworkDrive "S:", "\\SERVER1\Shared"
WSHNetwork.MapNetworkDrive "L:", "\\SERVER2\" & strUserName & "$"
 
Set ObjGroupDict = CreateMemberOfObject(strUserDomain, strUserName)
 
 
If Memberof(ObjGroupDict, "Accounts Users K") Then 
 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Accounts" 
 
else
 
End If 
 
If Memberof(ObjGroupDict, "IT Users K") Then 
 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\It" 
 
else
 
End If 
 
If Memberof(ObjGroupDict, "Analytical Services Users K") Then 
wshNetwork.MapNetworkDrive "J:","\\SERVER1\RootJ" 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\SAServices"
wshNetwork.MapNetworkDrive "V:","\\SERVER1\ASvcs" 
 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Administration Users S") Then 
' WScript.Echo "Admin Users S"
wshNetwork.MapNetworkDrive "G:","\\SERVER3\Admin" 
 
else
 
End If 
 
If Memberof(ObjGroupDict, "Sudops Users S") Then 
wshNetwork.MapNetworkDrive "F:","\\SERVER3\Sudops" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Management Users S") Then 
wshNetwork.MapNetworkDrive "H:","\\SERVER3\Management" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Engineer Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Engineer" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "MSDS Users K") Then 
wshNetwork.MapNetworkDrive "M:","\\SERVER1\MSDS" 
 
else
 
End If
 
'If Memberof(ObjGroupDict, "Engineer Proj Users K") Then 
'wshNetwork.MapNetworkDrive "P:","\\SERVER1\EngProj" 
 
'else
 
'End If
 
If Memberof(ObjGroupDict, "Base Colour & QC Users K") Then 
wshNetwork.MapNetworkDrive "T:","\\SERVER1\Base_Colour" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Base Colour Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Base_Colour" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "QCGrp Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\QC" 
wshNetwork.MapNetworkDrive "J:","\\SERVER1\RootJ" 
else
 
End If
 
If Memberof(ObjGroupDict, "AdminGrp Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\AdminGrp" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "PDSA2 Users K") Then 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\PDSA2" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Customer Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Customer" 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\eWork" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Marketing Users K") Then 
wshNetwork.MapNetworkDrive "N:","\\SERVER1\Marketing" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Sales Users K") Then 
wshNetwork.MapNetworkDrive "P:","\\SERVER1\Sales" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "C Of A Admin Users K") Then 
wshNetwork.MapNetworkDrive "T:","\\SERVER1\CofA" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "C of A View Users K") Then 
wshNetwork.MapNetworkDrive "T:","\\SERVER1\CofA" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "TechEnq Users K") Then 
wshNetwork.MapNetworkDrive "O:","\\SERVER1\TechEnq" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "TechEnqFA Users K") Then 
wshNetwork.MapNetworkDrive "O:","\\SERVER1\TechEnq" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Enquiry Users K") Then 
wshNetwork.MapNetworkDrive "Q:","\\SERVER1\Enquiry" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "KidOps Users K") Then 
wshNetwork.MapNetworkDrive "G:","\\SERVER1\KidOps" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Minitab Users K") Then 
wshNetwork.MapNetworkDrive "G:","\\SERVER1\Minitab" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "EssbaseGrp Users K") Then 
wshNetwork.MapNetworkDrive "X:","\\SERVER1\EssBaseBKP" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "H & S Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\H&S" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Quality Management Systems Users K") Then 
wshNetwork.MapNetworkDrive "R:","\\SERVER1\Quality Management Systems" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Work Instructions Users K") Then 
wshNetwork.MapNetworkDrive "I:","\\SERVER1\Work Instructions" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Complaints Users K") Then 
wshNetwork.MapNetworkDrive "K:","\\SERVER3\Complaints" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Finance Payroll Users K") Then 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\Statutory Financial" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Msds Uni read Only U") Then 
wshNetwork.MapNetworkDrive "M:","\\SERVER1\MSDS" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Management Team Users K") Then 
wshNetwork.MapNetworkDrive "X:","\\SERVER1\Management Team" 
 
else
 
End If
 
' **** ADDED SECTION by RobSampson ****
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CreateFolder "C:\Windows\ctheme"
objFSO.CopyFile "\\server\shared\theme\*.*" , "c:\windows\ctheme\" , OverwriteExisting
 
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "regedit /s \\server\shared\theme\reg\reg1.reg", 0, True
objShell.Run "regedit /s \\server\shared\theme\reg\reg2.reg", 0, True
objShell.Run "regedit /s \\server\shared\theme\reg\reg3.reg", 0, True
' ************************************* 
 
' Added By SJE
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
 
WshShell.run ("s:\share\client *echo-")
 
Function MemberOf(ObjDict, strKey)
' Given a Dictionary object containing groups to which the user
' is a member of and a group name, then returns True if the group
' is in the Dictionary else return False.
'
' Inputs:
' strDict - Input, Name of a Dictionary object
' strKey - Input, Value being searched for in
' the Dictionary object
' Sample Usage:
'
' If MemberOf(ObjGroupDict, "DOMAIN ADMINS") Then
' wscript.echo "Is a member of Domain Admins."
' End If
'
'
MemberOf = CBool(ObjGroupDict.Exists(strKey)) 
 
End Function
 
 
Function CreateMemberOfObject(strDomain, strUserName)
' Given a domain name and username, returns a Dictionary
' object of groups to which the user is a member of.
'
' Inputs:
'
' strDomain - Input, NT Domain name
' strUserName - Input, NT username
'
Dim objUser, objGroup
 
Set CreateMemberOfObject = CreateObject("Scripting.Dictionary")
CreateMemberOfObject.CompareMode = vbTextCompare
Set objUser = GetObject("WinNT://" _
& strDomain & "/" _
& strUserName & ",user")
For Each objGroup In objUser.Groups
CreateMemberOfObject.Add objGroup.Name, "-"
Next
Set objUser = Nothing
 
End Function

Open in new window

Avatar of RPUKsupport
RPUKsupport

ASKER

it doesnt seem to work, my drives map but nothing else, the files dont copy, and ideas why
Avatar of RobSampson
RobSampson
Flag of Australia image

Hmmm.  I have commented out On Error Resume Next here, so see if this gives you any error that might help us identify where the problem is...

Regards,

Rob.
Option Explicit ' Force explicit declarations
'
' Variables
'
Dim WSHNetwork
Dim FSO
Dim strUserName ' Current user
Dim strUserDomain ' Current User's domain name
Dim ObjGroupDict ' Dictionary of groups to which the user belongs
 
'on error resume next
 
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set FSO = CreateObject("Scripting.FileSystemObject")
'
' Wait until the user is really logged in...
'
strUserName = ""
While strUserName = ""
WScript.Sleep 100 ' 1/10 th of a second
strUserName = WSHNetwork.UserName
Wend
strUserDomain = WSHNetwork.UserDomain
 
' WScript.Echo "Running from Sysvol\domain\Scripts"
 
 
' Read the user's account "Member Of" tab info across the network
' once into a dictionary object.
 
WshShell.run "\\server1\netlogon\kidtheme.vbs", 0
 
'Map  Common network Drives here, UNREM the below lines:
 
WSHNetwork.MapNetworkDrive "U:", "\\SERVER1\" & strUserName & "$"
WSHNetwork.MapNetworkDrive "S:", "\\SERVER1\Shared"
WSHNetwork.MapNetworkDrive "L:", "\\SERVER2\" & strUserName & "$"
 
Set ObjGroupDict = CreateMemberOfObject(strUserDomain, strUserName)
 
 
If Memberof(ObjGroupDict, "Accounts Users K") Then 
 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Accounts" 
 
else
 
End If 
 
If Memberof(ObjGroupDict, "IT Users K") Then 
 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\It" 
 
else
 
End If 
 
If Memberof(ObjGroupDict, "Analytical Services Users K") Then 
wshNetwork.MapNetworkDrive "J:","\\SERVER1\RootJ" 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\SAServices"
wshNetwork.MapNetworkDrive "V:","\\SERVER1\ASvcs" 
 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Administration Users S") Then 
' WScript.Echo "Admin Users S"
wshNetwork.MapNetworkDrive "G:","\\SERVER3\Admin" 
 
else
 
End If 
 
If Memberof(ObjGroupDict, "Sudops Users S") Then 
wshNetwork.MapNetworkDrive "F:","\\SERVER3\Sudops" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Management Users S") Then 
wshNetwork.MapNetworkDrive "H:","\\SERVER3\Management" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Engineer Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Engineer" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "MSDS Users K") Then 
wshNetwork.MapNetworkDrive "M:","\\SERVER1\MSDS" 
 
else
 
End If
 
'If Memberof(ObjGroupDict, "Engineer Proj Users K") Then 
'wshNetwork.MapNetworkDrive "P:","\\SERVER1\EngProj" 
 
'else
 
'End If
 
If Memberof(ObjGroupDict, "Base Colour & QC Users K") Then 
wshNetwork.MapNetworkDrive "T:","\\SERVER1\Base_Colour" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Base Colour Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Base_Colour" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "QCGrp Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\QC" 
wshNetwork.MapNetworkDrive "J:","\\SERVER1\RootJ" 
else
 
End If
 
If Memberof(ObjGroupDict, "AdminGrp Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\AdminGrp" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "PDSA2 Users K") Then 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\PDSA2" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Customer Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Customer" 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\eWork" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Marketing Users K") Then 
wshNetwork.MapNetworkDrive "N:","\\SERVER1\Marketing" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Sales Users K") Then 
wshNetwork.MapNetworkDrive "P:","\\SERVER1\Sales" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "C Of A Admin Users K") Then 
wshNetwork.MapNetworkDrive "T:","\\SERVER1\CofA" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "C of A View Users K") Then 
wshNetwork.MapNetworkDrive "T:","\\SERVER1\CofA" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "TechEnq Users K") Then 
wshNetwork.MapNetworkDrive "O:","\\SERVER1\TechEnq" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "TechEnqFA Users K") Then 
wshNetwork.MapNetworkDrive "O:","\\SERVER1\TechEnq" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Enquiry Users K") Then 
wshNetwork.MapNetworkDrive "Q:","\\SERVER1\Enquiry" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "KidOps Users K") Then 
wshNetwork.MapNetworkDrive "G:","\\SERVER1\KidOps" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Minitab Users K") Then 
wshNetwork.MapNetworkDrive "G:","\\SERVER1\Minitab" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "EssbaseGrp Users K") Then 
wshNetwork.MapNetworkDrive "X:","\\SERVER1\EssBaseBKP" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "H & S Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\H&S" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Quality Management Systems Users K") Then 
wshNetwork.MapNetworkDrive "R:","\\SERVER1\Quality Management Systems" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Work Instructions Users K") Then 
wshNetwork.MapNetworkDrive "I:","\\SERVER1\Work Instructions" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Complaints Users K") Then 
wshNetwork.MapNetworkDrive "K:","\\SERVER3\Complaints" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Finance Payroll Users K") Then 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\Statutory Financial" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Msds Uni read Only U") Then 
wshNetwork.MapNetworkDrive "M:","\\SERVER1\MSDS" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Management Team Users K") Then 
wshNetwork.MapNetworkDrive "X:","\\SERVER1\Management Team" 
 
else
 
End If
 
' **** ADDED SECTION by RobSampson ****
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists("C:\Windows\ctheme") = False Then objFSO.CreateFolder "C:\Windows\ctheme"
objFSO.CopyFile "\\server\shared\theme\*" , "c:\windows\ctheme\" , OverwriteExisting
 
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "regedit /s \\server\shared\theme\reg\reg1.reg", 0, True
objShell.Run "regedit /s \\server\shared\theme\reg\reg2.reg", 0, True
objShell.Run "regedit /s \\server\shared\theme\reg\reg3.reg", 0, True
' ************************************* 
 
' Added By SJE
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
 
WshShell.run ("s:\share\client *echo-")
 
Function MemberOf(ObjDict, strKey)
' Given a Dictionary object containing groups to which the user
' is a member of and a group name, then returns True if the group
' is in the Dictionary else return False.
'
' Inputs:
' strDict - Input, Name of a Dictionary object
' strKey - Input, Value being searched for in
' the Dictionary object
' Sample Usage:
'
' If MemberOf(ObjGroupDict, "DOMAIN ADMINS") Then
' wscript.echo "Is a member of Domain Admins."
' End If
'
'
MemberOf = CBool(ObjGroupDict.Exists(strKey)) 
 
End Function
 
 
Function CreateMemberOfObject(strDomain, strUserName)
' Given a domain name and username, returns a Dictionary
' object of groups to which the user is a member of.
'
' Inputs:
'
' strDomain - Input, NT Domain name
' strUserName - Input, NT username
'
Dim objUser, objGroup
 
Set CreateMemberOfObject = CreateObject("Scripting.Dictionary")
CreateMemberOfObject.CompareMode = vbTextCompare
Set objUser = GetObject("WinNT://" _
& strDomain & "/" _
& strUserName & ",user")
For Each objGroup In objUser.Groups
CreateMemberOfObject.Add objGroup.Name, "-"
Next
Set objUser = Nothing
 
End Function

Open in new window

Avatar of RPUKsupport
RPUKsupport

ASKER

Hi, i have tested and the offending line is

WshShell.run "\\server1\netlogon\kidtheme.vbs", 0

I get the following message returned:

script:     c:\test.vbs
line:        31
char:       1
error:      object required: "
code:      800a01ab
source:   microsoft vbscript runtime error

hope this helps
Avatar of RobSampson
RobSampson
Flag of Australia image

OK, so that means that WshShell was undefined. Try this now...

Rob.
Option Explicit ' Force explicit declarations
'
' Variables
'
Dim WSHNetwork
Dim FSO
Dim strUserName ' Current user
Dim strUserDomain ' Current User's domain name
Dim ObjGroupDict ' Dictionary of groups to which the user belongs
 
'on error resume next
 
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set FSO = CreateObject("Scripting.FileSystemObject")
'
' Wait until the user is really logged in...
'
strUserName = ""
While strUserName = ""
WScript.Sleep 100 ' 1/10 th of a second
strUserName = WSHNetwork.UserName
Wend
strUserDomain = WSHNetwork.UserDomain
 
' WScript.Echo "Running from Sysvol\domain\Scripts"
 
 
' Read the user's account "Member Of" tab info across the network
' once into a dictionary object.
 
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
 
WshShell.run "\\server1\netlogon\kidtheme.vbs", 0
 
'Map  Common network Drives here, UNREM the below lines:
 
WSHNetwork.MapNetworkDrive "U:", "\\SERVER1\" & strUserName & "$"
WSHNetwork.MapNetworkDrive "S:", "\\SERVER1\Shared"
WSHNetwork.MapNetworkDrive "L:", "\\SERVER2\" & strUserName & "$"
 
Set ObjGroupDict = CreateMemberOfObject(strUserDomain, strUserName)
 
 
If Memberof(ObjGroupDict, "Accounts Users K") Then 
 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Accounts" 
 
else
 
End If 
 
If Memberof(ObjGroupDict, "IT Users K") Then 
 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\It" 
 
else
 
End If 
 
If Memberof(ObjGroupDict, "Analytical Services Users K") Then 
wshNetwork.MapNetworkDrive "J:","\\SERVER1\RootJ" 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\SAServices"
wshNetwork.MapNetworkDrive "V:","\\SERVER1\ASvcs" 
 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Administration Users S") Then 
' WScript.Echo "Admin Users S"
wshNetwork.MapNetworkDrive "G:","\\SERVER3\Admin" 
 
else
 
End If 
 
If Memberof(ObjGroupDict, "Sudops Users S") Then 
wshNetwork.MapNetworkDrive "F:","\\SERVER3\Sudops" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Management Users S") Then 
wshNetwork.MapNetworkDrive "H:","\\SERVER3\Management" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Engineer Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Engineer" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "MSDS Users K") Then 
wshNetwork.MapNetworkDrive "M:","\\SERVER1\MSDS" 
 
else
 
End If
 
'If Memberof(ObjGroupDict, "Engineer Proj Users K") Then 
'wshNetwork.MapNetworkDrive "P:","\\SERVER1\EngProj" 
 
'else
 
'End If
 
If Memberof(ObjGroupDict, "Base Colour & QC Users K") Then 
wshNetwork.MapNetworkDrive "T:","\\SERVER1\Base_Colour" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Base Colour Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Base_Colour" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "QCGrp Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\QC" 
wshNetwork.MapNetworkDrive "J:","\\SERVER1\RootJ" 
else
 
End If
 
If Memberof(ObjGroupDict, "AdminGrp Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\AdminGrp" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "PDSA2 Users K") Then 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\PDSA2" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Customer Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\Customer" 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\eWork" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Marketing Users K") Then 
wshNetwork.MapNetworkDrive "N:","\\SERVER1\Marketing" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Sales Users K") Then 
wshNetwork.MapNetworkDrive "P:","\\SERVER1\Sales" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "C Of A Admin Users K") Then 
wshNetwork.MapNetworkDrive "T:","\\SERVER1\CofA" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "C of A View Users K") Then 
wshNetwork.MapNetworkDrive "T:","\\SERVER1\CofA" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "TechEnq Users K") Then 
wshNetwork.MapNetworkDrive "O:","\\SERVER1\TechEnq" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "TechEnqFA Users K") Then 
wshNetwork.MapNetworkDrive "O:","\\SERVER1\TechEnq" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Enquiry Users K") Then 
wshNetwork.MapNetworkDrive "Q:","\\SERVER1\Enquiry" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "KidOps Users K") Then 
wshNetwork.MapNetworkDrive "G:","\\SERVER1\KidOps" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Minitab Users K") Then 
wshNetwork.MapNetworkDrive "G:","\\SERVER1\Minitab" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "EssbaseGrp Users K") Then 
wshNetwork.MapNetworkDrive "X:","\\SERVER1\EssBaseBKP" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "H & S Users K") Then 
wshNetwork.MapNetworkDrive "V:","\\SERVER1\H&S" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Quality Management Systems Users K") Then 
wshNetwork.MapNetworkDrive "R:","\\SERVER1\Quality Management Systems" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Work Instructions Users K") Then 
wshNetwork.MapNetworkDrive "I:","\\SERVER1\Work Instructions" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Complaints Users K") Then 
wshNetwork.MapNetworkDrive "K:","\\SERVER3\Complaints" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Finance Payroll Users K") Then 
wshNetwork.MapNetworkDrive "W:","\\SERVER1\Statutory Financial" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Msds Uni read Only U") Then 
wshNetwork.MapNetworkDrive "M:","\\SERVER1\MSDS" 
 
else
 
End If
 
If Memberof(ObjGroupDict, "Management Team Users K") Then 
wshNetwork.MapNetworkDrive "X:","\\SERVER1\Management Team" 
 
else
 
End If
 
' **** ADDED SECTION by RobSampson ****
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists("C:\Windows\ctheme") = False Then objFSO.CreateFolder "C:\Windows\ctheme"
objFSO.CopyFile "\\server\shared\theme\*" , "c:\windows\ctheme\" , OverwriteExisting
 
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "regedit /s \\server\shared\theme\reg\reg1.reg", 0, True
objShell.Run "regedit /s \\server\shared\theme\reg\reg2.reg", 0, True
objShell.Run "regedit /s \\server\shared\theme\reg\reg3.reg", 0, True
' ************************************* 
 
' Added By SJE
'Dim WshShell
'Set WshShell = WScript.CreateObject("WScript.Shell")
 
WshShell.run ("s:\share\client *echo-")
 
Function MemberOf(ObjDict, strKey)
' Given a Dictionary object containing groups to which the user
' is a member of and a group name, then returns True if the group
' is in the Dictionary else return False.
'
' Inputs:
' strDict - Input, Name of a Dictionary object
' strKey - Input, Value being searched for in
' the Dictionary object
' Sample Usage:
'
' If MemberOf(ObjGroupDict, "DOMAIN ADMINS") Then
' wscript.echo "Is a member of Domain Admins."
' End If
'
'
MemberOf = CBool(ObjGroupDict.Exists(strKey)) 
 
End Function
 
 
Function CreateMemberOfObject(strDomain, strUserName)
' Given a domain name and username, returns a Dictionary
' object of groups to which the user is a member of.
'
' Inputs:
'
' strDomain - Input, NT Domain name
' strUserName - Input, NT username
'
Dim objUser, objGroup
 
Set CreateMemberOfObject = CreateObject("Scripting.Dictionary")
CreateMemberOfObject.CompareMode = vbTextCompare
Set objUser = GetObject("WinNT://" _
& strDomain & "/" _
& strUserName & ",user")
For Each objGroup In objUser.Groups
CreateMemberOfObject.Add objGroup.Name, "-"
Next
Set objUser = Nothing
 
End Function

Open in new window

Avatar of RPUKsupport
RPUKsupport

ASKER

I get back a

line: 278
char: 1
error: variable is undefined 'objFSO'
code: 800a01f4
source: ms vsb runtime error
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of RPUKsupport
RPUKsupport

ASKER

perfect, sorry it took me so long to get round to finishing this, just been very busy

Thanks a million
Avatar of RobSampson
RobSampson
Flag of Australia image

No problem. Thanks for the grade.

Regards,

Rob.
Windows XP
Windows XP

Microsoft Windows XP is the sixth release of the NT series of operating systems, and was the first to be marketed in a variety of editions: XP Home and XP Professional, designed for business and power users. The advanced features in XP Professional are generally disabled in Home Edition, but are there and can be activated. There were two 64-bit editions, an embedded edition and a tablet edition.

119K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo