views:

21

answers:

2

I have a VB script that adds a program shortcut to the Windows Startup folder. In my script, I'm able to retrieve the Startup folder location in 32-bit Windows with this:

  Set objShell = CreateObject("WScript.Shell")
  startupFolder = objShell.SpecialFolders("Startup")

but it returns nothing when I try this on 64-bit Windows. Specifically, I'm testing on 64-bit Vista. I can't seem to find the appropriate environment variable or syntax for this. Thanks.

+1  A: 

See if this works. This actually reads the registry value where the folder is stored. I can' imagine why the other method doesn't work in 64-bit.

Dim startupFolder As String
startupFolder = My.Computer.Registry.GetValue _
("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "Startup", Nothing)
Serplat
I just realized I had my question tagged as vb and not vbscript. Your code doesn't work in vbscript...thanks though. For now, I'll just hardcode the startup location (!!) for 64-bit.
Banjer
+1  A: 

Try an alternative variant using the Shell.Application object:

Const ssfSTARTUP = &H7

Set oShell = CreateObject("Shell.Application")
Set startupFolder = oShell.NameSpace(ssfSTARTUP)

If Not startupFolder Is Nothing Then
  WScript.Echo startupFolder.Self.Path
End If

Does it work for you?

Helen
Yeah! Works on 32 and 64-bit. Thanks Helen.
Banjer