Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Connecting to All Users Desktop

Reply
 
Old 03-12-2009   #1 (permalink)
John


 
 

Connecting to All Users Desktop

Hi

I have below code to change the icons of all shortcuts on All User Desktop.
Problem is I am connecting to All Users' Desktop twice, once using Namespace
and second using SpecialFolders. Is there a way to simplify code to connect
to All Users Desktop only once?

Sorry if it is dumb. I am very new to vbscript.

Many Thanks

Regards


Set oFS = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")

Const ALL_USERS_DESKTOP = &H19&
Set objShellApp = CreateObject("Shell.Application")
Set objFolder = objShellApp.Namespace(ALL_USERS_DESKTOP)

strFolder = objShell.SpecialFolders("AllUsersDesktop")
For Each objFile In oFS.GetFolder(strFolder).Files
If Right(LCase(objFile.Name), 4) = LCase(".lnk") Or
Right(LCase(objFile.Name), 4) = LCase(".url") Then
Set objFolderItem = objFolder.ParseName(objFile.Name)
Set oLink = objFolderItem.GetLink
oLink.SetIconLocation "C:\Windows\System32\SHELL32.dll", 109

oLink.Save
End If
Next



My System SpecsSystem Spec
Old 03-12-2009   #2 (permalink)
Alex K. Angelopoulos


 
 

Re: Connecting to All Users Desktop

John,

Actually, you're not really doing extra work per se, but if I understand you
correctly, you want to make the code look cleaner somehow. It's still
easiest to find the items by iterating through with the filesystemobject I
believe, but you can get the path directly from the shell.application
object, like this:

strFolder = objFolder.Self.path

As for dumb - you should see some of the things _I_ asked when I was first
starting out. You know the drill - the only dumb question is the one you
didn't ask. : )


"John" <info@xxxxxx> wrote in message
news:O7JvH9xoJHA.3840@xxxxxx
Quote:

> Hi
>
> I have below code to change the icons of all shortcuts on All User
> Desktop. Problem is I am connecting to All Users' Desktop twice, once
> using Namespace and second using SpecialFolders. Is there a way to
> simplify code to connect to All Users Desktop only once?
>
> Sorry if it is dumb. I am very new to vbscript.
>
> Many Thanks
>
> Regards
>
>
> Set oFS = CreateObject("Scripting.FileSystemObject")
> Set objShell = CreateObject("WScript.Shell")
>
> Const ALL_USERS_DESKTOP = &H19&
> Set objShellApp = CreateObject("Shell.Application")
> Set objFolder = objShellApp.Namespace(ALL_USERS_DESKTOP)
>
> strFolder = objShell.SpecialFolders("AllUsersDesktop")
> For Each objFile In oFS.GetFolder(strFolder).Files
> If Right(LCase(objFile.Name), 4) = LCase(".lnk") Or
> Right(LCase(objFile.Name), 4) = LCase(".url") Then
> Set objFolderItem = objFolder.ParseName(objFile.Name)
> Set oLink = objFolderItem.GetLink
> oLink.SetIconLocation "C:\Windows\System32\SHELL32.dll", 109
>
> oLink.Save
> End If
> Next
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Connecting Laptop using XP to Desktop using Vista 64 Premium Vista networking & sharing
Connecting laptop to desktop Vista hardware & devices
Connecting Desktop to Laptop Vista General
Connecting to Vista with RDP causes old desktop icons to appear Vista General
remote desktop connecting???? Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46