Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add folder to start->programs menu

Status
Not open for further replies.

Briandr

MIS
Jul 11, 2003
177
US
Hi All,

What I'd like to is modify the following script to do the following:

Check for a particual folder off the Start->All Programs.
If the folder exists create a shortcut inside of it. This folder may not have the shortcut I want so I want it to overwrite one that may be there. The name of the shortcut if it is present will be the same one I am trying to create. Nothing different. If the folder does not exist create the folder and then create the shortcut within the folder. Here is what I have so far

Option Explicit
Dim objShell, objShortcut, strFolder
Set objShell = WScript.CreateObject("WScript.Shell")
strFolder = objShell.SpecialFolders("AllUsersStartMenu")
Set objShortcut = objShell.CreateShortcut(strFolder & "\Software Portal.lnk")
objShortcut.TargetPath = "C:\Program Files\Altiris\Altiris Agent\Agents\SoftwareManagementSolution\SWRAgentUtils.exe /ShowSoftwarePortal"
objShortcut.WorkingDirectory = "C:\Program Files\Altiris\Altiris Agent\Agents\SoftwareManagementSolution"
objShortcut.WindowStyle = 1
objShortcut.Save
Set objShortcut = Nothing
Set objShell = Nothing
 
All can be accomplished easily with the File System Object.

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
I know it is possible. What I don't know how to do is code it.
 
That's why I provided the link

Code:
'create FSO
set objFSO = CreateObject("Wscript.FileSystemObject")

strFolder = "c:\temp"
strShortcutName = "MyShortcut"

'check if folder exists. if not, create it.
if NOT(objFSO.FolderExists(strFolder)) then
    objFSO.CreateFolder(strFolder)
end if

'get files in folder
set objFiles = objFSO.GetFolder(strFolder).Files

'iterate files
for each objFile in objFiles
    if (objFile.Name = strShortcutName) then
        'create shortcut
    end if
next

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
set objFSO = CreateObject("Wscript.FileSystemObject")

should be

Set objFSO = CreateObject("Scripting.FileSystemObject")

Code:
Dim objfso, folder, files, sFolder
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
sFolder = objShell.SpecialFolders("AllUsersStartMenu")

strFolder = sFolder & "\Software Portal"
strCut = strFolder & "\Software Portal.lnk"

'check if shortcut exists. Delete it.
if (objFSO.FileExists(strCut)) then
    objFSO.DeleteFile(strCut)
end if

'check if folder exists. if not, create it.
if NOT(objFSO.FolderExists(strFolder)) then
    objFSO.CreateFolder(strFolder)
end if

'Now create the shortcut
Set objShortcut = objShell.CreateShortcut(strFolder & "\Software Portal.lnk")
objShortcut.TargetPath = "C:\Program Files\Altiris\Altiris Agent\Agents\SoftwareManagementSolution\SWRAgentUtils.exe /ShowSoftwarePortal"
objShortcut.WorkingDirectory = "C:\Program Files\Altiris\Altiris Agent\Agents\SoftwareManagementSolution"
objShortcut.WindowStyle = 1
objShortcut.Save
Set objShortcut = Nothing
Set objShell = Nothing
[\code]

MCITP:EA/SA, MCSE, MCSA, MCDBA, MCTS, MCP+I, MCP
 
Hi GrimR,

Thank you for responding. Much appreciated. When I ran the code it installed it on the 'Start' menu. I need it installed in the 'Programs' menu. My apologies if I was not clear. I think this line is invalid:

objShortcut.TargetPath = "C:\Program Files\Altiris\Altiris Agent\Agents\SoftwareManagementSolution\SWRAgentUtils.exe /ShowSoftwarePortal"

I think it has to do with the /ShowSoftwarePortal at the end. I am not sure if " " are wrapping it correctly.

 
remove it from the TargetPath and pass it to the Arguments property

Code:
objShortcut.TargetPath = "C:\Program Files\Altiris\Altiris Agent\Agents\SoftwareManagementSolution\SWRAgentUtils.exe"
objShortcut.Arguments = "/ShowSoftwarePortal"

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Hi Geates / GrimR,

I need to change this:

sFolder = objShell.SpecialFolders("AllUsersStartMenu")

to:

sFolder = objShell.SpecialFolders("AllUsersProgramsMenu")

The script executes with no errors, but the folder does not get created. It works with 'AllUsersStartMenu', but not 'AllUsersProgramsMenu'

Ideas?

Thanks.
 
Use "AllUsersPrograms"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi,

Thanks to one all. Its working nice. One final thing. Is there a command I can throw in the script to force the 'All Programs' menu to re-alphabetize itself. Not a huge deal if its more headache than its worth. Just would like to add it in if possible.
 
it's a reg key

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start Menu\Order

delete the Order key and the startmenu will alphabetize itself.

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Actually, the Order value is just for the start menu. Drill down further and you'll find ..\Start Menu\Programs\Order

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Code:
CONST HKEY_CURRENT_USER  = &H80000001
strKey = "Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start Menu\Programs\Order"

set objReg = GetObject("winmgmts:{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\.\root\default:StdRegProv")
objReg.DeleteKey HKEY_CURRENT_USER, strKey

NOTE: This is a PER USER setting.

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
I used this:

objShell.RegDelete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start Menu\Order"

Appears not to have worked. Wrong command? Is a re-boot necessary and then it will re-alphabetize?

I am running this command between these lines:

Set objShortcut = Nothing
objShell.RegDelete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start Menu\Order"
Set objShell = Nothing

Thanks.

 
Code:
objShell.RegDelete "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MenuOrder\Start Menu\[red]Programs[/red]\Order"

Yes and No. Windows needs to reload the registry before the changes take effect. Restarting the computer will reload the registry. So will logging off and logging on. But even faster would be to kill explorer.exe and relaunch it.

Code:
'kill process
set colProcesses = objShell.ExecQuery("Select * from Win32_Process Where Name='explorer.exe'")
for each objProcess in colProcesses
	objProcess.Terminate()
next

'Wait for it to end.  There's pro
do
   wscript.sleep 500
   set colProcesses = objShell.ExecQuery("Select * from Win32_Process Where Name='explorer.exe'")
loop until (colProcesses.count = 0)

'relaunch
objShell.Run "explorer.exe"

-Geates


"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top