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

VB Script Login Help, Creating Folder to UNC Path

A buddy of mine sent over this VB Script which essentially looks at an XML file, checks your group membership and creates the appropriate shortcuts to each directory onto the users desktop.

However, I would like the script to create a folder to the User's profile path \\server\shares\user\desktop

And then copy all the shortcuts to this folder.

Any help would be great.
Option Explicit
 
Dim oUsrGroups, oCompGroups
Dim oXmlConfig, oNet, oShell, oFSO
Set oXmlConfig = CreateObject("Msxml2.DOMDocument")
Set oNet = CreateObject("Wscript.Network")
Set oShell = WScript.CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
 
If Not oXmlConfig.Load("c:\cabs\config_shortcuts.xml") Then
    WScript.Quit(1)
End If
 
CreateShortCuts
 
' ----------------------------------------
' Use XML data to add short cuts to the users enviroment
Sub CreateShortCuts
    'On Error Resume Next
    Dim oShortcut,oAllShortcuts,oConditions,oCondition,oShtCut
    set oAllShortcuts = oXmlConfig.documentElement.selectNodes("//allshortcuts/shortcut")
    for Each oShortcut in oAllShortcuts
        Set oConditions=oShortcut.selectNodes("condition")
        If CheckConditions(oConditions,oShortcut.selectSingleNode("conditionjoinmethod").text) Then	
            'Create Shortcut
            Set oShtCut = oShell.CreateShortcut(oShell.ExpandEnvironmentStrings(oShortcut.selectSingleNode("filename").text))
            oShtCut.Description=oShortcut.selectSingleNode("description").text
            oShtCut.TargetPath=oShell.ExpandEnvironmentStrings(oShortcut.selectSingleNode("targetpath").text)
            oShtCut.Arguments=oShortcut.selectSingleNode("arguments").text
            oShtCut.IconLocation=oShell.ExpandEnvironmentStrings(oShortcut.selectSingleNode("iconpath").text) & "," & oShortcut.selectSingleNode("iconindex").text
            oShtCut.WorkingDirectory=oShell.ExpandEnvironmentStrings(oShortcut.selectSingleNode("workingdir").text)
            oShtCut.Save() 
'            Wscript.Echo " Shortcut:" & oShell.ExpandEnvironmentStrings(oShortcut.selectSingleNode("filename").text)
        End If
    Next
End Sub
 
' ----------------------------------------
' Check the conditions and return true or false based 
Function CheckConditions(oConditions,sConditionJoinMethod)
    Dim oCondition
    'If sConditionJoinMethod set to ANY, a single condition resulting in a true will mean we return true
    'If sConditionJoinMethod set to ALL, a single condition resulting in a true will mean we return false
    If Ucase(sConditionJoinMethod)="ANY" Then CheckConditions=False
    If Ucase(sConditionJoinMethod)="ALL" Then CheckConditions=True
    For Each oCondition in oConditions
        'If User in the group
        If (Ucase(oCondition.getAttribute("type"))="USERINGROUP" or Ucase(oCondition.getAttribute("type"))="GROUP") Then
            If (IsUserMember(oCondition.text)) Then
                CheckConditions=True
            Else
                CheckConditions=False
            End If
        End If
        'Computer in Group
        If (Ucase(oCondition.getAttribute("type"))="COMPUTERINGROUP") Then 
            If (IsComputerMember(oCondition.text)) Then
                CheckConditions=True
            Else
                CheckConditions=False
            End If
        End If
        'Computer Not in Group
        If (Ucase(oCondition.getAttribute("type"))="COMPUTERNOTINGROUP") Then 
            If not (IsComputerMember(oCondition.text)) Then
                CheckConditions=True
            Else
                CheckConditions=False
            End If
        End If
        'File Exists
        If (Ucase(oCondition.getAttribute("type"))="FILEEXISTS" or Ucase(oCondition.getAttribute("type"))="FILEEXIST") Then 
            If (oFSO.FileExists(oShell.ExpandEnvironmentStrings(oCondition.text))) Then
                CheckConditions=True
            Else
                CheckConditions=False
            End If
        End If
        'File Does Not Exist
        If (Ucase(oCondition.getAttribute("type"))="FILENOTEXISTS" or Ucase(oCondition.getAttribute("type"))="FILENOTEXIST") Then 
            If not (oFSO.FileExists(oShell.ExpandEnvironmentStrings(oCondition.text))) Then
                CheckConditions=True
            Else
                CheckConditions=False
            End If
        End If
        ' Exit if we have mae our decision
        If (Ucase(sConditionJoinMethod)="ANY" and CheckConditions = True) Then Exit For
        If (Ucase(sConditionJoinMethod)="ALL" and CheckConditions = False) Then Exit For
    next
End Function
 
' ----------------------------------------
' Test to see If a user is a member of a group
Function IsUserMember(sGroup)
    ' Globals oUsrGroups, oNet
    Dim sAdsPath, oUser, oGroup
    If IsEmpty(oUsrGroups) Then
        Set oUsrGroups = CreateObject("Scripting.Dictionary")
        oUsrGroups.CompareMode=vbTextCompare
        sAdsPath = oNet.UserDomain & "/" & oNet.UserName
        Set oUser = GetObject("WinNT://" & sAdsPath & ",user")
        For Each oGroup In oUser.Groups
            oUsrGroups.Add oGroup.Name, "-"
        Next
        Set oUser = Nothing
        Set oGroup = Nothing
    End If
    IsUserMember = CBool(oUsrGroups.Exists(sGroup))
End Function
 
' ----------------------------------------
' Test to see if a user is a member of a group
Function IsComputerMember(sGroup)
    ' Globals oCompGroups, oNet
    Dim DomainObj,GroupObj,UserObj
    IsComputerMember=False 'Default to returning False
    ' If this function has never been called we need to get a list of all the groups on the domain
    If IsEmpty (oCompGroups) Then
        Set oCompGroups = CreateObject("Scripting.Dictionary")
        oCompGroups.CompareMode=vbTextCompare
        Set DomainObj = GetObject("WinNT://" & oNet.UserDomain)
        DomainObj.Filter = Array("group")
        For Each GroupObj In DomainObj
            If GroupObj.Class = "Group" and not oCompGroups.Exists(GroupObj.Name) Then
               oCompGroups.Add GroupObj.Name,"-"
            End If
        Next
        Set GroupObj = Nothing
        Set DomainObj = Nothing
    End If
    ' Check if the group exists in the domain and see if we have aquired the member list yet.
    If not oCompGroups.Exists(sGroup) Then Exit Function
    If oCompGroups.Exists(sGroup) and not IsObject(oCompGroups.Item(sGroup))Then
        Set oCompGroups.Item(sGroup) = CreateObject("Scripting.Dictionary")
        Set GroupObj = GetObject("WinNT://ESD189/" & sGroup)
        For Each UserObj in GroupObj.Members
            oCompGroups.Item(sGroup).Add UserObj.Name,"="
        Next
        Set UserObj = Nothing
        Set GroupObj = Nothing
    End If
    IsComputerMember = CBool(oCompGroups.Item(sGroup).Exists(oNet.ComputerName & "$"))
End Function

Open in new window

0
armgtit
Asked:
armgtit
  • 6
  • 4
1 Solution
 
armgtitAuthor Commented:
Here is the XML file...
<?xml version="1.0"?>
<allshortcuts>
    <shortcut>
        <filename>\\esd189.org\dfs\agency_users\%USERNAME%\RedirFolders\Desktop\WESPaC.lnk</filename>
        <description>WESPaC Shortcut</description>
        <targetpath>C:\Program Files\Mozilla Firefox\firefox.exe</targetpath>
        <arguments>-url "http://portal.esd189.wa-k12.net/"</arguments>
        <workingdir>C:\Program Files\Mozilla Firefox</workingdir>
        <iconpath>C:\Program Files\Mozilla Firefox\firefox.exe</iconpath>
        <iconindex>0</iconindex>
        <conditionjoinmethod>all</conditionjoinmethod>
        <condition type="UserInGroup">_GRP_WESPaC</condition>
        <condition type="FileExists">C:\Program Files\Mozilla Firefox\firefox.exe</condition>
    </shortcut>
    <shortcut>
        <filename>\\esd189.org\dfs\agency_users\%USERNAME%\RedirFolders\Desktop\Sites_Data.lnk</filename>
        <description>SitesData</description>
        <targetpath>\\esd189.org\dfs\agency_staff\_AllSites</targetpath>
        <arguments></arguments>
        <workingdir></workingdir>
        <iconpath></iconpath>
        <iconindex></iconindex>
        <conditionjoinmethod>any</conditionjoinmethod>
        <condition type="UserInGroup">_GRP_Site_Admin_Assistants</condition>
        <condition type="UserInGroup">_GRP_Site_Administrators</condition>
        <condition type="UserInGroup">_GRP_Site_SPCL_Admins</condition>
    </shortcut>
    <shortcut> 
        <filename>\\esd189.org\dfs\agency_users\%USERNAME%\RedirFolders\Desktop\SCAN.lnk</filename>
        <description>SCAN</description>
        <targetpath>\\esd189.org\dfs\agency_staff\_Common\Databases\SCAN.mdb</targetpath>
        <arguments></arguments>
        <workingdir></workingdir>
        <iconpath></iconpath>
        <iconindex></iconindex>
        <conditionjoinmethod>all</conditionjoinmethod>
        <condition type="UserInGroup">_GRP_Fiscal_SCAN</condition>
        <condition type="FileExists">\\esd189.org\dfs\agency_staff\_Common\Databases\SCAN.mdb</condition>
    </shortcut>
    <shortcut> 
        <filename>\\esd189.org\dfs\agency_users\%USERNAME%\RedirFolders\Desktop\test.lnk</filename>
        <description>test</description>
        <targetpath>\\esd189.org\dfs\agency_staff\_Common\_Departments\ISSC\Co-Op List for Eric Chambers.xls</targetpath>
        <arguments></arguments>
        <workingdir></workingdir>
        <iconpath></iconpath>
        <iconindex></iconindex>
        <conditionjoinmethod>all</conditionjoinmethod>
        <condition type="UserInGroup">_GRP_DO_Staff</condition>
        <condition type="FileExists">\\esd189.org\dfs\agency_staff\_Common\_Departments\ISSC\Co-Op List for Eric Chambers.xls</condition>
    </shortcut>
    <!--  <shortcut> 
        <filename>asdf</filename>
        <description>Descr 2</description>
        <targetpath>c:\test.exe</targetpath>
        <arguments>321</arguments>
        <workingdir>U:\</workingdir>
        <iconpath>c:\test.exe</iconpath>
        <iconindex>27</iconindex>
        <conditionjoinmethod>all</conditionjoinmethod>
        <condition type="User">a</condition>
        <condition type="Computer">b</condition>
        <condition type="UserInGroup">c</condition>
        <condition type="ComputerInSite">g</condition>
        <condition type="ComputerInGroup">d</condition>
        <condition type="FileExists">d</condition>
        <condition type="FileNotExist">f</condition>
      </shortcut> -->
</allshortcuts>

Open in new window

0
 
Robberbaron (robr)Commented:
the location for the shortcut is defined by
oShortcut.selectSingleNode("filename").text) and expanding environment variables like username.

       <filename>\\esd189.org\dfs\agency_users\%USERNAME%\RedirFolders\Desktop\SCAN.lnk</filename>

so currently the shortcut is going to the users redirected deskyop folder.

\\server\shares\user\desktop.....  what portion of the current system need to change ?


0
 
armgtitAuthor Commented:
<filename>\\esd189.org\dfs\agency_users\%USERNAME%\RedirFolders\Desktop\Site Data\SCAN.lnk</filename>

On the Desktop I would like for it to create a folder called Site Data, if it already exists than it wouldn't need to create it again.  I tried inserting desktop\site data\scan.ink and it didn't work.
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
armgtitAuthor Commented:
Anyone?
0
 
Robberbaron (robr)Commented:
are you able to edit the XML easily ? ie change the way  is put together.

create the SiteData folder on desktop first.

then run with the attached test XML file

if that works, we can get into the creation of the folder on redirected desktop.

<?xml version="1.0"?>
<allshortcuts>
    <shortcut>
        <filename>\\esd189.org\dfs\agency_users\%USERNAME%\RedirFolders\Desktop\SiteData\WESPaC.lnk</filename>
        <description>WESPaC Shortcut</description>
        <targetpath>C:\Program Files\Mozilla Firefox\firefox.exe</targetpath>
        <arguments>-url "http://portal.esd189.wa-k12.net/"</arguments>
        <workingdir>C:\Program Files\Mozilla Firefox</workingdir>
        <iconpath>C:\Program Files\Mozilla Firefox\firefox.exe</iconpath>
        <iconindex>0</iconindex>
        <conditionjoinmethod>all</conditionjoinmethod>
        <condition type="UserInGroup">_GRP_WESPaC</condition>
        <condition type="FileExists">C:\Program Files\Mozilla Firefox\firefox.exe</condition>
    </shortcut>
</allshortcuts>

Open in new window

0
 
armgtitAuthor Commented:
Yes editing the XML file is not a problem as I've manually added a folder on my desktop...

\desktop\Company Information\Client Information as well as
\desktop\Company Information\Other Resources

Once I edit the XML it works fine.  

I just don't would hate to manually create folders.
0
 
Robberbaron (robr)Commented:
sFldr = oShell.ExpandEnvironmentStrings("\\esd189.org\dfs\agency_users\%USERNAME%\RedirFolders\Desktop\SiteData"

Set f = fso.CreateFolder(sFldr )
   
works for local folders. Cant test right now if works on a redirected desktop

0
 
armgtitAuthor Commented:
Where would I add this code?  And if I wanted to structure the folder on the desktop to something like this....

Arm Information (Main Folder)
    - Client Information (Sub-Folder)
    - Company Resouces (Sub-Folder)

Can I use this same code just add a couple more lines?
0
 
Robberbaron (robr)Commented:
1/ add to the top of the CreateShortCut routine

2/yes. Should work.

But I NEVER use spaces in folder names if I can help it at all.
0
 
armgtitAuthor Commented:
Ok I will give it a try and see what happens.
0

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

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