otrdiena, 2012. gada 14. februāris

Startup vbs script to place an icon on users desktop in computer GPO section

Yesterday I had to write script which installs shotcut on all desktops on specified computers. As known Logon scripts executes on profiles but Startup scripts executes befor profile is loaded. First I thought it is impossible but then I found some scripts related to subject. I don't know usernames so I made script combined from 2 other scripts.


Dim fs 
Dim objFolder, oFolder
Dim path
Dim oWS
Dim colFolders
Dim sDocsAndSettings 
Dim strComputer
strComputer = "."
Set oWS = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
sDocsAndSettings = "C:\Documents and Settings\"   
Set colFolders = fs.GetFolder(sDocsAndSettings) 
For Each oFolder In colFolders.SubFolders
    Select Case LCase(oFolder.Name)
        Case "admin", "administrator", "all users", "default user.original", "localservice", "networkservice"
            'LEAVE THE DEFAULT PROFILES ON THE MACHINE
        Case Else
            ' Check for the path
            If fs.FolderExists(sDocsAndSettings & oFolder.Name & "\Desktop") Then
    sLinkFile = sDocsAndSettings & oFolder.Name & "\Desktop\NameofLink.lnk"
    Set oLink = oWS.CreateShortcut(sLinkFile)
'       oLink.Description = "DescriptionofLink"
    oLink.IconLocation = "\\Servername\Share\Icon.ico"
    oLink.WindowStyle = "1"
    oLink.TargetPath = "https://pathtothesite.com/;jsessionid=somevalue"
'    oLink.WorkingDirectory = "c:\Program files\InCaseLinkExecutingSomething"
    oLink.Save
            End If
    End Select 
Next

Set fs = Nothing
Set oWS = Nothing

Script is adding icon to all Desktops. As profile are taken from somewhere else I cant copy it just to all users Desktop. You can place this in Computers Startup part of GPO and apply it to some group.
As you can see, you can assign GPO to computers and it will be executed before user actually logs on.  In case of huge network there should be politics- Always wait for network and Slow link detections prior thic one.

Nav komentāru:

Ierakstīt komentāru