• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1524
  • Last Modified:

HELP: Convert VBS script WINNT to LDAP

Hi Everyone,

We have upgarded our domain and now have subdomains, unfortunately the script below does not work now any more, it would seem that winnt doesnt work very well with subdomains, so i am looking at converting the code to LDAP.

All the code does is look at a users groups and add a folder to start menu with shortcuts.
'Script Syntax:
'  GroupMember <GroupName> - returns a boolean value
'  CreateSMFolder <FolderName> 
'  CreateSMIcon <Destination>, <Icon Name>, <Program Location>, <Working Directory>, <Icon Path>
 
Option Explicit
 
'On Error Resume Next
 
Dim WSHENV, WSHShell
set wshshell=createobject("wscript.shell")
set wshenv=wshshell.Environment("PROCESS")
Dim UserGroups(2000)
Dim GroupCount
 
ClearStartMenu
EnumGroups
 
If GroupMember("XEN-IFS Cosalt") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Cosalt", "D:\Program Files\IFS Applications\IFS Cosalt.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\IFS Cosalt.exe"
End If
 
If GroupMember("XEN-IFS Financials") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Financials", "D:\Program Files\IFS Applications\IFS Financials.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\IFS Financials.exe"
End If
 
If GroupMember("XEN-IFS Payroll") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Payroll", "D:\Program Files\IFS Applications\payroll.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\payroll.exe"
End If
 
If GroupMember("XEN-IFS Admin") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Admin", "D:\Program Files\IFS Applications\admin.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\admin.exe"
End If
 
If GroupMember("XEN-IFS HR") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Human Resources", "D:\Program Files\IFS Applications\IFS Human Resources.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\IFS Human Resources.exe"
End If
 
If GroupMember("XEN-IFS TEST") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "__TEST__IFS Cosalt", "D:\Program Files\IFS Applications\__TEST__IFS Cosalt.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\__TEST__IFS Cosalt.exe"
   CreateSMIcon "IFS Applications", "__TEST__IFS Financials", "D:\Program Files\IFS Applications\__TEST__IFS Financials.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\__TEST__IFS Financials.exe"
End If
 
If GroupMember("XEN-IFS Sales and Marketing") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Sales & Marketing", "D:\Program Files\IFS Applications\Sales and Marketing\Vendimo313.exe", "D:\Program Files\IFS Applications\Sales and Marketing","", "D:\Program Files\IFS Applications\Sales and Marketing\Vendimo313.exe"
End If
 
If GroupMember("XEN-IFS Sales and Marketing Admin") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Sales & Marketing Admin", "D:\Program Files\IFS Applications\Sales and Marketing\VendimoAdmin.exe", "D:\Program Files\IFS Applications\Sales and Marketing","", "D:\Program Files\IFS Applications\Sales and Marketing\VendimoAdmin.exe"
End If
 
If GroupMember("XEN-PBX Xarios") Then
   CreateSMFolder "Xarios"
   CreateSMIcon "Xarios", "Xarios Phone Manager", "D:\Program Files\Xarios\Phone Manager\PhoneManager.exe", "D:\Program Files\Xarios\Phone Manager","", "D:\Program Files\Xarios\Phone Manager\PhoneManager.exe"
End If
 
If GroupMember("XEN-Office2003-Word") Then
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "Word 2003", "D:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE"
End If
 
If GroupMember("XEN-Office2003-Excel") Then
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "Excel 2003", "D:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE"
End If
 
If GroupMember("XEN-Office2003-Powerpoint") Then
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "PowerPoint 2003", "D:\Program Files\Microsoft Office\OFFICE11\POWERPNT.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\POWERPNT.EXE"
End If
 
If GroupMember("XEN-Office2003-Access") Then
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "Access 2003", "D:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"
End If
 
If GroupMember("XEN-Office2003-Outlook") Then
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "Outlook 2003", "D:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE"
End If
 
If GroupMember("XEN-Adobe-Reader") Then
   CreateSMFolder "Adobe"
   CreateSMIcon "Adobe", "Adobe Reader 8.0", "D:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe", "D:\Program Files\Adobe\Reader 8.0\Reader","", "D:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe"
End If
 
If GroupMember("XEN-TMS-Glasgow") Then
   CreateSMFolder "Cosalt Applications"
   CreateSMIcon "Cosalt Applications", "T.M.S Glasgow", "\\ho-storage-01\Glasgow\AST\TMS\T.M.S Glasgow.mdb", "\\ho-storage-01\Glasgow\AST\TMS","", "\\ho-storage-01\Glasgow\AST\TMS\T.M.S Glasgow.mdb"
End If
 
If GroupMember("XEN-Standard") Then
   CreateSMFolder "Utilities"
   CreateSMIcon "Utilities", "Calculator", "C:\WINDOWS\system32\calc.exe", "C:\WINDOWS\system32","", "C:\WINDOWS\system32\calc.exe"
   CreateSMIcon "Utilities", "Internet Explorer", "c:\Program Files\Internet Explorer\iexplore.exe", "C:\WINDOWS\system32","", "c:\Program Files\Internet Explorer\iexplore.exe"
   CreateSMIcon "Utilities", "Paint", "C:\WINDOWS\system32\mspaint.exe", "C:\WINDOWS\system32","", "C:\WINDOWS\system32\mspaint.exe"
   CreateSMIcon "Utilities", "Regional Settings", "C:\WINDOWS\system32\intl.cpl", "C:\WINDOWS\system32","", "C:\WINDOWS\system32\intl.cpl"
   CreateSMIcon "Utilities", "Windows Explorer", "C:\WINDOWS\explorer.exe", "C:\WINDOWS\","", "C:\WINDOWS\explorer.exe"
End If
 
If GroupMember("XEN-Standard") Then
   CreateSMFolder "Cosalt Info"
   CreateSMIcon "Cosalt Info", "Rope Master Price List", "\\ho-storage-01\Public\Rope Master Price List.xls", "P:\National Rope\Price List","", "\\ho-storage-01\Public\Rope Master Price List.xls"
End If
 
If GroupMember("XEN-ZetaFax") Then
   CreateSMFolder "Zetafax"
   CreateSMIcon "Zetafax", "Zetafax Client", "D:\Program Files\Zetafax\ZETAFAX.EXE", "D:\Program Files\Zetafax","", "D:\Program Files\Zetafax\ZETAFAX.EXE"
   CreateSMIcon "Zetafax", "Zetafax Status", "D:\Program Files\Zetafax Information Program\ZETAFAX.EXE", "D:\Program Files\Zetafax Information Program","", "D:\Program Files\Zetafax Information Program\ZETAFAX.EXE"
End If
 
If GroupMember("XEN-DWFViewer") Then
   CreateSMFolder "Autodesk"
   CreateSMIcon "Autodesk", "DWF Viewer", "D:\Program Files\Autodesk\Autodesk DWF Viewer\DWFViewer.exe", "D:\Program Files\Autodesk\Autodesk DWF Viewer","", "D:\Program Files\Autodesk\Autodesk DWF Viewer\DWFViewer.exe"
End If
 
If GroupMember("XEN-QuickShadow") Then
   CreateSMFolder "Utilities"
   CreateSMIcon "Utilities", "Quick Shadow", "D:\Program Files\Citrix\System32\wshadow.exe", "D:\Program Files\Citrix\System32","", "D:\Program Files\Citrix\System32\wshadow.exe"
End If
 
If GroupMember("XEN-Management Console") Then
   CreateSMFolder "Utilities"
   CreateSMIcon "Utilities", "Citrix Management Console", "C:\Program Files\Common Files\Citrix\Access Management Console - Framework\CmiLaunch.exe", "C:\Program Files\Common Files\Citrix\Access Management Console - Framework\","", "C:\Program Files\Common Files\Citrix\Access Management Console - Framework\CmiLaunch.exe"
End If
 
Private Sub CreateSMIcon(Destination, Name, Path, WorkDir, Arguments, IconPath)
  Dim WshShell, FSO, StartMenu, Icon
  Set WshShell = CreateObject("WScript.Shell")
  Set FSO = CreateObject("WScript.Shell")
  StartMenu = WshShell.SpecialFolders("Programs")
  Set Icon = WshShell.CreateShortcut(StartMenu & "\" & Destination & "\" & Name & ".lnk")
  Icon.TargetPath = Path
  Icon.Arguments = Arguments
  Icon.Description = "Created By Dynamic Desktop"
  Icon.WorkingDirectory = WorkDir
  Icon.IconLocation = IconPath
  Icon.Save
End Sub
 
Private Sub CreateSMFolder(FolderName)
  Dim WshShell, FSO, StartMenu
  Set WshShell = CreateObject("WScript.Shell")
  Set FSO = CreateObject("Scripting.FileSystemObject")
  StartMenu = WshShell.SpecialFolders("Programs")
  If Not FSO.FolderExists(StartMenu & "\" & FolderName) Then _
     FSO.CreateFolder StartMenu & "\" & FolderName
End SUb
  
Private Function GroupMember(GroupName)
  Dim Counter
  GroupMember = False
  For Counter = 1 to GroupCount
    If Ucase(UserGroups(Counter)) = Ucase(GroupName) Then GroupMember = True
  Next    
End Function
 
Private Sub EnumGroups
  Dim WshNetwork, Domain, User, Groups, Group, Counter
  Set WshNetwork = CreateObject("WScript.Network")
  Domain = WshNetwork.UserDomain
  Set User = GetObject("WinNT://" & Domain & "/" & WshNetwork.Username)
  Counter = 0
  For Each Group In User.Groups
    Counter = Counter + 1
    UserGroups(Counter) = Group.Name
  Next
  GroupCount = Counter
End Sub
 
Private Sub ClearStartMenu
  Dim FSO, WshShell, Files, Folders, File, Folder, StartMenu
  Set FSO = CreateObject("Scripting.FileSystemObject")
  Set WshShell = CreateObject("WScript.Shell")
  Set StartMenu = Fso.GetFolder(WshShell.SpecialFolders("Programs"))
  Set Files = StartMenu.Files
  Set Folders = StartMenu.SubFolders
  For Each Folder In Folders
    If Ucase(Folder.Name) <> "STARTUP" Then FSO.DeleteFolder Folder, True
  Next
  For Each File In Files
    FSO.DeleteFile File, True
  Next
End Sub

Open in new window

0
cosalt123
Asked:
cosalt123
  • 2
  • 2
2 Solutions
 
Chris DentPowerShell DeveloperCommented:

When you mention subdomains, do you mean the groups you're checking might not be within the users domain? If they're not, we'll have to change the script below slightly.

Chris
Option Explicit
 
' Usage for GetAllGroups
'
' Set objUsersGroups = GetAllGroups
 
' Using .Exists (case-insensitive)
' If objUsersGroups.Exists("some group") Then
'   Do stuff
' End If
 
' Using a loop and select case (case-sensitive)
' For Each strGroup in objUsersGroups
'   Select Case strGroup
'     Case "DOMAIN ADMINS"
'       Do stuff
'     Case "LONDON USERS"
'       Do stuff
'    End Select
' Next
'
' Note: The group name used above matches the group name as seen in AD Users and Computers.
 
Function GetAllGroups
  ' Returns a dictionary object containing all groups for the current AD user
 
  Dim objADSysInfo : Set objADSysInfo = CreateObject("ADSystemInfo")
  Dim strUserDN : strUserDN = objADSysInfo.UserName
  Set objADSysInfo = Nothing
 
  Dim strFilter : strFilter = "(&(objectClass=group)(member=" & strUserDN & "))"
  ' Alternative search filter to test nested groups
  ' Dim strFilter : strFilter = "(member:1.2.840.113556.1.4.1941:=" & strUserDN & ")"
 
  Dim objConnection : Set objConnection = CreateObject("ADODB.Connection")
  objConnection.Provider = "ADsDSOObject"
  objConnection.Open "Active Directory Provider"
 
  Dim objRootDSE : Set objRootDSE = GetObject("LDAP://RootDSE")
  Dim objRecordSet : Set objRecordSet = objConnection.Execute( _
    "<LDAP://" & objRootDSE.Get("defaultNamingContext") & ">;" & _
    strFilter & ";distinguishedName,name;subtree")
  Set objRootDSE = Nothing
 
  Dim objGroups : Set objGroups = CreateObject("Scripting.Dictionary")
  objGroups.CompareMode = VbTextCompare
 
  While Not objRecordSet.EOF
    Dim strGroup : strGroup = objRecordSet.Fields("name").Value
    If Not objGroups.Exists(strGroup) Then
      objGroups.Add UCase(strGroup), ""
    End If
    objRecordSet.MoveNext
  WEnd
 
  Set GetAllGroups = objGroups
 
  Set objGroups = Nothing
End Function
 
 
'Script Syntax:
'  CreateSMFolder <FolderName> 
'  CreateSMIcon <Destination>, <Icon Name>, <Program Location>, <Working Directory>, <Icon Path>
 
 
'On Error Resume Next
 
Dim WSHENV, WSHShell
set wshshell=createobject("wscript.shell")
set wshenv=wshshell.Environment("PROCESS")
Dim UserGroups(2000)
Dim GroupCount
 
ClearStartMenu
 
' Replacement for EnumGroups
Dim objUsersGroups : Set objUsersGroups = GetAllGroups
 
If objUsersGroups.Exists("XEN-IFS Cosalt") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Cosalt", "D:\Program Files\IFS Applications\IFS Cosalt.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\IFS Cosalt.exe"
End If
 
If objUsersGroups.Exists("XEN-IFS Financials") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Financials", "D:\Program Files\IFS Applications\IFS Financials.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\IFS Financials.exe"
End If
 
If objUsersGroups.Exists("XEN-IFS Payroll") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Payroll", "D:\Program Files\IFS Applications\payroll.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\payroll.exe"
End If
 
If objUsersGroups.Exists("XEN-IFS Admin") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Admin", "D:\Program Files\IFS Applications\admin.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\admin.exe"
End If
 
If objUsersGroups.Exists("XEN-IFS HR") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Human Resources", "D:\Program Files\IFS Applications\IFS Human Resources.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\IFS Human Resources.exe"
End If
 
If objUsersGroups.Exists("XEN-IFS TEST") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "__TEST__IFS Cosalt", "D:\Program Files\IFS Applications\__TEST__IFS Cosalt.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\__TEST__IFS Cosalt.exe"
   CreateSMIcon "IFS Applications", "__TEST__IFS Financials", "D:\Program Files\IFS Applications\__TEST__IFS Financials.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\__TEST__IFS Financials.exe"
End If
 
If objUsersGroups.Exists("XEN-IFS Sales and Marketing") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Sales & Marketing", "D:\Program Files\IFS Applications\Sales and Marketing\Vendimo313.exe", "D:\Program Files\IFS Applications\Sales and Marketing","", "D:\Program Files\IFS Applications\Sales and Marketing\Vendimo313.exe"
End If
 
If objUsersGroups.Exists("XEN-IFS Sales and Marketing Admin") Then
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Sales & Marketing Admin", "D:\Program Files\IFS Applications\Sales and Marketing\VendimoAdmin.exe", "D:\Program Files\IFS Applications\Sales and Marketing","", "D:\Program Files\IFS Applications\Sales and Marketing\VendimoAdmin.exe"
End If
 
If objUsersGroups.Exists("XEN-PBX Xarios") Then
   CreateSMFolder "Xarios"
   CreateSMIcon "Xarios", "Xarios Phone Manager", "D:\Program Files\Xarios\Phone Manager\PhoneManager.exe", "D:\Program Files\Xarios\Phone Manager","", "D:\Program Files\Xarios\Phone Manager\PhoneManager.exe"
End If
 
If objUsersGroups.Exists("XEN-Office2003-Word") Then
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "Word 2003", "D:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE"
End If
 
If objUsersGroups.Exists("XEN-Office2003-Excel") Then
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "Excel 2003", "D:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE"
End If
 
If objUsersGroups.Exists("XEN-Office2003-Powerpoint") Then
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "PowerPoint 2003", "D:\Program Files\Microsoft Office\OFFICE11\POWERPNT.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\POWERPNT.EXE"
End If
 
If objUsersGroups.Exists("XEN-Office2003-Access") Then
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "Access 2003", "D:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"
End If
 
If objUsersGroups.Exists("XEN-Office2003-Outlook") Then
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "Outlook 2003", "D:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE"
End If
 
If objUsersGroups.Exists("XEN-Adobe-Reader") Then
   CreateSMFolder "Adobe"
   CreateSMIcon "Adobe", "Adobe Reader 8.0", "D:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe", "D:\Program Files\Adobe\Reader 8.0\Reader","", "D:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe"
End If
 
If objUsersGroups.Exists("XEN-TMS-Glasgow") Then
   CreateSMFolder "Cosalt Applications"
   CreateSMIcon "Cosalt Applications", "T.M.S Glasgow", "\\ho-storage-01\Glasgow\AST\TMS\T.M.S Glasgow.mdb", "\\ho-storage-01\Glasgow\AST\TMS","", "\\ho-storage-01\Glasgow\AST\TMS\T.M.S Glasgow.mdb"
End If
 
If objUsersGroups.Exists("XEN-Standard") Then
   CreateSMFolder "Utilities"
   CreateSMIcon "Utilities", "Calculator", "C:\WINDOWS\system32\calc.exe", "C:\WINDOWS\system32","", "C:\WINDOWS\system32\calc.exe"
   CreateSMIcon "Utilities", "Internet Explorer", "c:\Program Files\Internet Explorer\iexplore.exe", "C:\WINDOWS\system32","", "c:\Program Files\Internet Explorer\iexplore.exe"
   CreateSMIcon "Utilities", "Paint", "C:\WINDOWS\system32\mspaint.exe", "C:\WINDOWS\system32","", "C:\WINDOWS\system32\mspaint.exe"
   CreateSMIcon "Utilities", "Regional Settings", "C:\WINDOWS\system32\intl.cpl", "C:\WINDOWS\system32","", "C:\WINDOWS\system32\intl.cpl"
   CreateSMIcon "Utilities", "Windows Explorer", "C:\WINDOWS\explorer.exe", "C:\WINDOWS\","", "C:\WINDOWS\explorer.exe"
End If
 
If objUsersGroups.Exists("XEN-Standard") Then
   CreateSMFolder "Cosalt Info"
   CreateSMIcon "Cosalt Info", "Rope Master Price List", "\\ho-storage-01\Public\Rope Master Price List.xls", "P:\National Rope\Price List","", "\\ho-storage-01\Public\Rope Master Price List.xls"
End If
 
If objUsersGroups.Exists("XEN-ZetaFax") Then
   CreateSMFolder "Zetafax"
   CreateSMIcon "Zetafax", "Zetafax Client", "D:\Program Files\Zetafax\ZETAFAX.EXE", "D:\Program Files\Zetafax","", "D:\Program Files\Zetafax\ZETAFAX.EXE"
   CreateSMIcon "Zetafax", "Zetafax Status", "D:\Program Files\Zetafax Information Program\ZETAFAX.EXE", "D:\Program Files\Zetafax Information Program","", "D:\Program Files\Zetafax Information Program\ZETAFAX.EXE"
End If
 
If objUsersGroups.Exists("XEN-DWFViewer") Then
   CreateSMFolder "Autodesk"
   CreateSMIcon "Autodesk", "DWF Viewer", "D:\Program Files\Autodesk\Autodesk DWF Viewer\DWFViewer.exe", "D:\Program Files\Autodesk\Autodesk DWF Viewer","", "D:\Program Files\Autodesk\Autodesk DWF Viewer\DWFViewer.exe"
End If
 
If objUsersGroups.Exists("XEN-QuickShadow") Then
   CreateSMFolder "Utilities"
   CreateSMIcon "Utilities", "Quick Shadow", "D:\Program Files\Citrix\System32\wshadow.exe", "D:\Program Files\Citrix\System32","", "D:\Program Files\Citrix\System32\wshadow.exe"
End If
 
If objUsersGroups.Exists("XEN-Management Console") Then
   CreateSMFolder "Utilities"
   CreateSMIcon "Utilities", "Citrix Management Console", "C:\Program Files\Common Files\Citrix\Access Management Console - Framework\CmiLaunch.exe", "C:\Program Files\Common Files\Citrix\Access Management Console - Framework\","", "C:\Program Files\Common Files\Citrix\Access Management Console - Framework\CmiLaunch.exe"
End If
 
Private Sub CreateSMIcon(Destination, Name, Path, WorkDir, Arguments, IconPath)
  Dim WshShell, FSO, StartMenu, Icon
  Set WshShell = CreateObject("WScript.Shell")
  Set FSO = CreateObject("WScript.Shell")
  StartMenu = WshShell.SpecialFolders("Programs")
  Set Icon = WshShell.CreateShortcut(StartMenu & "\" & Destination & "\" & Name & ".lnk")
  Icon.TargetPath = Path
  Icon.Arguments = Arguments
  Icon.Description = "Created By Dynamic Desktop"
  Icon.WorkingDirectory = WorkDir
  Icon.IconLocation = IconPath
  Icon.Save
End Sub
 
Private Sub CreateSMFolder(FolderName)
  Dim WshShell, FSO, StartMenu
  Set WshShell = CreateObject("WScript.Shell")
  Set FSO = CreateObject("Scripting.FileSystemObject")
  StartMenu = WshShell.SpecialFolders("Programs")
  If Not FSO.FolderExists(StartMenu & "\" & FolderName) Then _
     FSO.CreateFolder StartMenu & "\" & FolderName
End SUb
  
Private Sub ClearStartMenu
  Dim FSO, WshShell, Files, Folders, File, Folder, StartMenu
  Set FSO = CreateObject("Scripting.FileSystemObject")
  Set WshShell = CreateObject("WScript.Shell")
  Set StartMenu = Fso.GetFolder(WshShell.SpecialFolders("Programs"))
  Set Files = StartMenu.Files
  Set Folders = StartMenu.SubFolders
  For Each Folder In Folders
    If Ucase(Folder.Name) <> "STARTUP" Then FSO.DeleteFolder Folder, True
  Next
  For Each File In Files
    FSO.DeleteFile File, True
  Next
End Sub

Open in new window

0
 
cosalt123Author Commented:
thanks for a reply,
i have created duplicate groups both in the parent domain and submain.
i had a go at converting it myself and below seems to work ok, i use case statments insted of IF's
what do you think of the code??
ClearStartMenu
 
On Error Resume Next
 
Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")
Set WshNetwork = WScript.CreateObject("WScript.Network")
 
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)
 
For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN
 
 
Select Case strGroupName
 
Case "XEN-IFS Cosalt"
CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Cosalt", "D:\Program Files\IFS Applications\IFS Cosalt.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\IFS Cosalt.exe"
 
 
Case "XEN-IFS Financials"
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Financials", "D:\Program Files\IFS Applications\IFS Financials.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\IFS Financials.exe"
 
 
Case "XEN-IFS Payroll"
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Payroll", "D:\Program Files\IFS Applications\payroll.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\payroll.exe"
 
 
Case "XEN-IFS Admin"
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Admin", "D:\Program Files\IFS Applications\admin.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\admin.exe"
 
 
Case "XEN-IFS HR"
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Human Resources", "D:\Program Files\IFS Applications\IFS Human Resources.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\IFS Human Resources.exe"
 
 
Case "XEN-IFS TEST"
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "__TEST__IFS Cosalt", "D:\Program Files\IFS Applications\__TEST__IFS Cosalt.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\__TEST__IFS Cosalt.exe"
   CreateSMIcon "IFS Applications", "__TEST__IFS Financials", "D:\Program Files\IFS Applications\__TEST__IFS Financials.exe", "D:\Program Files\IFS Applications","", "D:\Program Files\IFS Applications\__TEST__IFS Financials.exe"
 
 
Case "XEN-IFS Sales and Marketing"
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Sales & Marketing", "D:\Program Files\IFS Applications\Sales and Marketing\Vendimo313.exe", "D:\Program Files\IFS Applications\Sales and Marketing","", "D:\Program Files\IFS Applications\Sales and Marketing\Vendimo313.exe"
 
 
Case "XEN-IFS Sales and Marketing Admin"
   CreateSMFolder "IFS Applications"
   CreateSMIcon "IFS Applications", "IFS Sales & Marketing Admin", "D:\Program Files\IFS Applications\Sales and Marketing\VendimoAdmin.exe", "D:\Program Files\IFS Applications\Sales and Marketing","", "D:\Program Files\IFS Applications\Sales and Marketing\VendimoAdmin.exe"
 
 
Case "XEN-PBX Xarios"
   CreateSMFolder "Xarios"
   CreateSMIcon "Xarios", "Xarios Phone Manager", "D:\Program Files\Xarios\Phone Manager\PhoneManager.exe", "D:\Program Files\Xarios\Phone Manager","", "D:\Program Files\Xarios\Phone Manager\PhoneManager.exe"
 
 
Case "XEN-Office2003-Word"
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "Word 2003", "D:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE"
 
 
Case "XEN-Office2003-Excel"
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "Excel 2003", "D:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE"
 
 
Case "XEN-Office2003-Powerpoint"
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "PowerPoint 2003", "D:\Program Files\Microsoft Office\OFFICE11\POWERPNT.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\POWERPNT.EXE"
 
 
Case "XEN-Office2003-Access"
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "Access 2003", "D:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"
 
 
Case "XEN-Office2003-Outlook"
   CreateSMFolder "MS Office 2003"
   CreateSMIcon "MS Office 2003", "Outlook 2003", "D:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE", "D:\Program Files\Microsoft Office\OFFICE11","", "D:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE"
 
 
Case "XEN-Adobe-Reader"
   CreateSMFolder "Adobe"
   CreateSMIcon "Adobe", "Adobe Reader 8.0", "D:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe", "D:\Program Files\Adobe\Reader 8.0\Reader","", "D:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe"
 
 
Case "XEN-TMS-Glasgow"
   CreateSMFolder "Cosalt Applications"
   CreateSMIcon "Cosalt Applications", "T.M.S Glasgow", "\\ho-storage-01\Glasgow\AST\TMS\T.M.S Glasgow.mdb", "\\ho-storage-01\Glasgow\AST\TMS","", "\\ho-storage-01\Glasgow\AST\TMS\T.M.S Glasgow.mdb"
 
 
Case "XEN-Standard"
   CreateSMFolder "Utilities"
   CreateSMIcon "Utilities", "Calculator", "C:\WINDOWS\system32\calc.exe", "C:\WINDOWS\system32","", "C:\WINDOWS\system32\calc.exe"
   CreateSMIcon "Utilities", "Internet Explorer", "c:\Program Files\Internet Explorer\iexplore.exe", "C:\WINDOWS\system32","", "c:\Program Files\Internet Explorer\iexplore.exe"
   CreateSMIcon "Utilities", "Paint", "C:\WINDOWS\system32\mspaint.exe", "C:\WINDOWS\system32","", "C:\WINDOWS\system32\mspaint.exe"
   CreateSMIcon "Utilities", "Regional Settings", "C:\WINDOWS\system32\intl.cpl", "C:\WINDOWS\system32","", "C:\WINDOWS\system32\intl.cpl"
   CreateSMIcon "Utilities", "Windows Explorer", "C:\WINDOWS\explorer.exe", "C:\WINDOWS\","", "C:\WINDOWS\explorer.exe"
 
 
Case "XEN-Standard"
   CreateSMFolder "Cosalt Info"
   CreateSMIcon "Cosalt Info", "Rope Master Price List", "\\ho-storage-01\Public\Rope Master Price List.xls", "P:\National Rope\Price List","", "\\ho-storage-01\Public\Rope Master Price List.xls"
 
 
Case "XEN-ZetaFax"
   CreateSMFolder "Zetafax"
   CreateSMIcon "Zetafax", "Zetafax Client", "D:\Program Files\Zetafax\ZETAFAX.EXE", "D:\Program Files\Zetafax","", "D:\Program Files\Zetafax\ZETAFAX.EXE"
   CreateSMIcon "Zetafax", "Zetafax Status", "D:\Program Files\Zetafax Information Program\ZETAFAX.EXE", "D:\Program Files\Zetafax Information Program","", "D:\Program Files\Zetafax Information Program\ZETAFAX.EXE"
 
 
Case "XEN-DWFViewer"
   CreateSMFolder "Autodesk"
   CreateSMIcon "Autodesk", "DWF Viewer", "D:\Program Files\Autodesk\Autodesk DWF Viewer\DWFViewer.exe", "D:\Program Files\Autodesk\Autodesk DWF Viewer","", "D:\Program Files\Autodesk\Autodesk DWF Viewer\DWFViewer.exe"
 
 
Case "XEN-QuickShadow"
   CreateSMFolder "Utilities"
   CreateSMIcon "Utilities", "Quick Shadow", "D:\Program Files\Citrix\System32\wshadow.exe", "D:\Program Files\Citrix\System32","", "D:\Program Files\Citrix\System32\wshadow.exe"
 
 
Case "XEN-Management Console"
   CreateSMFolder "Utilities"
   CreateSMIcon "Utilities", "Citrix Management Console", "C:\Program Files\Common Files\Citrix\Access Management Console - Framework\CmiLaunch.exe", "C:\Program Files\Common Files\Citrix\Access Management Console - Framework\","", "C:\Program Files\Common Files\Citrix\Access Management Console - Framework\CmiLaunch.exe"
 
End Select
Next
 
 
 
Private Sub CreateSMIcon(Destination, Name, Path, WorkDir, Arguments, IconPath)
  Dim WshShell, FSO, StartMenu, Icon
  Set WshShell = CreateObject("WScript.Shell")
  Set FSO = CreateObject("WScript.Shell")
  StartMenu = WshShell.SpecialFolders("Programs")
  Set Icon = WshShell.CreateShortcut(StartMenu & "\" & Destination & "\" & Name & ".lnk")
  Icon.TargetPath = Path
  Icon.Arguments = Arguments
  Icon.Description = "Created By Dynamic Desktop"
  Icon.WorkingDirectory = WorkDir
  Icon.IconLocation = IconPath
  Icon.Save
End Sub
 
Private Sub CreateSMFolder(FolderName)
  Dim WshShell, FSO, StartMenu
  Set WshShell = CreateObject("WScript.Shell")
  Set FSO = CreateObject("Scripting.FileSystemObject")
  StartMenu = WshShell.SpecialFolders("Programs")
  If Not FSO.FolderExists(StartMenu & "\" & FolderName) Then _
     FSO.CreateFolder StartMenu & "\" & FolderName
End SUb
 
Private Sub ClearStartMenu
  Dim FSO, WshShell, Files, Folders, File, Folder, StartMenu
  Set FSO = CreateObject("Scripting.FileSystemObject")
  Set WshShell = CreateObject("WScript.Shell")
  Set StartMenu = Fso.GetFolder(WshShell.SpecialFolders("Programs"))
  Set Files = StartMenu.Files
  Set Folders = StartMenu.SubFolders
  For Each Folder In Folders
    If Ucase(Folder.Name) <> "STARTUP" Then FSO.DeleteFolder Folder, True
  Next
  For Each File In Files
    FSO.DeleteFile File, True
  Next
End Sub

Open in new window

0
 
Chris DentPowerShell DeveloperCommented:

It's absolutely fine if it's working for you. You only loop through the membership once so it's quite nice and fast :)

Chris
0
 
cosalt123Author Commented:
thanks Chris,
and thanks for some of that code you posted, i will probably use bits of it for some else. ; )

nath/Cosalt123
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now